tidwall cfc65a13f6 Refactor repository and build scripts
This commit includes updates that affects the build, testing, and
deployment of Tile38.

- The root level build.sh has been broken up into multiple scripts
  and placed in the "scripts" directory.

- The vendor directory has been updated to follow the Go modules
  rules, thus `make` should work on isolated environments. Also
  some vendored packages may have been updated to a later
  version, if needed.

- The Makefile has been updated to allow for making single
  binaries such as `make tile38-server`. There is some scaffolding
  during the build process, so from now on all binaries should be
  made using make. For example, to run a development version of
  the tile38-cli binary, do this:
     make tile38-cli && ./tile38-cli
  not this:
     go run cmd/tile38-cli/main.go

- Travis.CI docker push script has been updated to address a
  change to Docker's JSON repo meta output, which in turn fixes
  a bug where new Tile38 versions were not being properly pushed
  to Docker
2019-11-18 10:33:15 -07:00

160 lines
3.3 KiB
Go

package geojson
import "github.com/tidwall/geojson/geometry"
// SimplePoint ...
type SimplePoint struct {
base geometry.Point
}
// NewSimplePoint ...
func NewSimplePoint(point geometry.Point) *SimplePoint {
return &SimplePoint{base: point}
}
// ForEach ...
func (g *SimplePoint) ForEach(iter func(geom Object) bool) bool {
return iter(g)
}
// Empty ...
func (g *SimplePoint) Empty() bool {
return g.base.Empty()
}
// Valid ...
func (g *SimplePoint) Valid() bool {
return g.base.Valid()
}
// Rect ...
func (g *SimplePoint) Rect() geometry.Rect {
return g.base.Rect()
}
// Spatial ...
func (g *SimplePoint) Spatial() Spatial {
return g
}
// Center ...
func (g *SimplePoint) Center() geometry.Point {
return g.base
}
// Base ...
func (g *SimplePoint) Base() geometry.Point {
return g.base
}
// AppendJSON ...
func (g *SimplePoint) AppendJSON(dst []byte) []byte {
dst = append(dst, `{"type":"Point","coordinates":`...)
dst = appendJSONPoint(dst, g.base, 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 {
return obj.Spatial().WithinPoint(g.base)
}
// Intersects ...
func (g *SimplePoint) Intersects(obj Object) bool {
if obj, ok := obj.(*Circle); ok {
return obj.Contains(g)
}
return obj.Spatial().IntersectsPoint(g.base)
}
// WithinRect ...
func (g *SimplePoint) WithinRect(rect geometry.Rect) bool {
return rect.ContainsPoint(g.base)
}
// WithinPoint ...
func (g *SimplePoint) WithinPoint(point geometry.Point) bool {
return point.ContainsPoint(g.base)
}
// WithinLine ...
func (g *SimplePoint) WithinLine(line *geometry.Line) bool {
return line.ContainsPoint(g.base)
}
// WithinPoly ...
func (g *SimplePoint) WithinPoly(poly *geometry.Poly) bool {
return poly.ContainsPoint(g.base)
}
// IntersectsPoint ...
func (g *SimplePoint) IntersectsPoint(point geometry.Point) bool {
return g.base.IntersectsPoint(point)
}
// IntersectsRect ...
func (g *SimplePoint) IntersectsRect(rect geometry.Rect) bool {
return g.base.IntersectsRect(rect)
}
// IntersectsLine ...
func (g *SimplePoint) IntersectsLine(line *geometry.Line) bool {
return g.base.IntersectsLine(line)
}
// IntersectsPoly ...
func (g *SimplePoint) IntersectsPoly(poly *geometry.Poly) bool {
return g.base.IntersectsPoly(poly)
}
// NumPoints ...
func (g *SimplePoint) NumPoints() int {
return 1
}
// Distance ...
func (g *SimplePoint) Distance(obj Object) float64 {
return obj.Spatial().DistancePoint(g.base)
}
// 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())
}