tile38/vendor/github.com/tidwall/geojson/simplepoint.go

160 lines
3.4 KiB
Go
Raw Normal View History

package geojson
import "github.com/tidwall/geojson/geometry"
// SimplePoint ...
type SimplePoint struct {
2020-02-11 21:02:15 +03:00
geometry.Point
}
2020-02-11 21:02:15 +03:00
// NewSimplePoint returns a new SimplePoint object.
func NewSimplePoint(point geometry.Point) *SimplePoint {
2020-02-11 21:02:15 +03:00
return &SimplePoint{Point: point}
}
// ForEach ...
func (g *SimplePoint) ForEach(iter func(geom Object) bool) bool {
return iter(g)
}
// Empty ...
func (g *SimplePoint) Empty() bool {
2020-02-11 21:02:15 +03:00
return g.Point.Empty()
}
// Valid ...
func (g *SimplePoint) Valid() bool {
2020-02-11 21:02:15 +03:00
return g.Point.Valid()
}
// Rect ...
func (g *SimplePoint) Rect() geometry.Rect {
2020-02-11 21:02:15 +03:00
return g.Point.Rect()
}
// Spatial ...
func (g *SimplePoint) Spatial() Spatial {
return g
}
// Center ...
func (g *SimplePoint) Center() geometry.Point {
2020-02-11 21:02:15 +03:00
return g.Point
}
// Base ...
func (g *SimplePoint) Base() geometry.Point {
2020-02-11 21:02:15 +03:00
return g.Point
}
// AppendJSON ...
func (g *SimplePoint) AppendJSON(dst []byte) []byte {
dst = append(dst, `{"type":"Point","coordinates":`...)
2020-02-11 21:02:15 +03:00
dst = appendJSONPoint(dst, g.Point, nil, 0)
dst = append(dst, '}')
return dst
}
// JSON ...
func (g *SimplePoint) JSON() string {
return string(g.AppendJSON(nil))
}
// MarshalJSON ...
func (g *SimplePoint) MarshalJSON() ([]byte, error) {
return g.AppendJSON(nil), nil
}
// String ...
func (g *SimplePoint) String() string {
return string(g.AppendJSON(nil))
}
// Within ...
func (g *SimplePoint) Within(obj Object) bool {
return obj.Contains(g)
}
// Contains ...
func (g *SimplePoint) Contains(obj Object) bool {
2020-02-11 21:02:15 +03:00
return obj.Spatial().WithinPoint(g.Point)
}
// Intersects ...
func (g *SimplePoint) Intersects(obj Object) bool {
if obj, ok := obj.(*Circle); ok {
return obj.Contains(g)
}
2020-02-11 21:02:15 +03:00
return obj.Spatial().IntersectsPoint(g.Point)
}
// WithinRect ...
func (g *SimplePoint) WithinRect(rect geometry.Rect) bool {
2020-02-11 21:02:15 +03:00
return rect.ContainsPoint(g.Point)
}
// WithinPoint ...
func (g *SimplePoint) WithinPoint(point geometry.Point) bool {
2020-02-11 21:02:15 +03:00
return point.ContainsPoint(g.Point)
}
// WithinLine ...
func (g *SimplePoint) WithinLine(line *geometry.Line) bool {
2020-02-11 21:02:15 +03:00
return line.ContainsPoint(g.Point)
}
// WithinPoly ...
func (g *SimplePoint) WithinPoly(poly *geometry.Poly) bool {
2020-02-11 21:02:15 +03:00
return poly.ContainsPoint(g.Point)
}
// IntersectsPoint ...
func (g *SimplePoint) IntersectsPoint(point geometry.Point) bool {
2020-02-11 21:02:15 +03:00
return g.Point.IntersectsPoint(point)
}
// IntersectsRect ...
func (g *SimplePoint) IntersectsRect(rect geometry.Rect) bool {
2020-02-11 21:02:15 +03:00
return g.Point.IntersectsRect(rect)
}
// IntersectsLine ...
func (g *SimplePoint) IntersectsLine(line *geometry.Line) bool {
2020-02-11 21:02:15 +03:00
return g.Point.IntersectsLine(line)
}
// IntersectsPoly ...
func (g *SimplePoint) IntersectsPoly(poly *geometry.Poly) bool {
2020-02-11 21:02:15 +03:00
return g.Point.IntersectsPoly(poly)
}
// NumPoints ...
func (g *SimplePoint) NumPoints() int {
return 1
}
// Distance ...
func (g *SimplePoint) Distance(obj Object) float64 {
2020-02-11 21:02:15 +03:00
return obj.Spatial().DistancePoint(g.Point)
}
// DistancePoint ...
func (g *SimplePoint) DistancePoint(point geometry.Point) float64 {
return geoDistancePoints(g.Center(), point)
}
// DistanceRect ...
func (g *SimplePoint) DistanceRect(rect geometry.Rect) float64 {
return geoDistancePoints(g.Center(), rect.Center())
}
// DistanceLine ...
func (g *SimplePoint) DistanceLine(line *geometry.Line) float64 {
return geoDistancePoints(g.Center(), line.Rect().Center())
}
// DistancePoly ...
func (g *SimplePoint) DistancePoly(poly *geometry.Poly) float64 {
return geoDistancePoints(g.Center(), poly.Rect().Center())
}