Skip to content

Commit

Permalink
Change Primitive to Polygon
Browse files Browse the repository at this point in the history
  • Loading branch information
tidwall committed Nov 21, 2022
1 parent 675497e commit ad814f6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
12 changes: 9 additions & 3 deletions circle.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ func (g *Circle) Spatial() Spatial {
return g.getObject().Spatial()
}

// Primative returns a primative GeoJSON object. Either a Polygon or Point.
func (g *Circle) Primative() Object {
// Polygon returns the circle as a GeoJSON Polygon.
func (g *Circle) Polygon() Object {
return g.getObject()
}

Expand All @@ -173,7 +173,13 @@ func (g *Circle) getObject() Object {

func makeCircleObject(center geometry.Point, meters float64, steps int) Object {
if meters <= 0 {
return NewPoint(center)
// Use a zero area rectangle
gPoly := new(Polygon)
gPoly.base.Exterior = geometry.Rect{
Min: center,
Max: center,
}
return gPoly
}
meters = geo.NormalizeDistance(meters)
points := make([]geometry.Point, 0, steps+1)
Expand Down
11 changes: 3 additions & 8 deletions rect.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,15 @@ func (g *Rect) Center() geometry.Point {
return g.base.Center()
}

// Primative returns a primative GeoJSON object. Either a Polygon or Point.
func (g *Rect) Primative() Object {
if g.base.Min == g.base.Max {
gPoint := new(Point)
gPoint.base = g.base.Min
return gPoint
}
// Polygon returns the Rect as a GeoJSON Polygon.
func (g *Rect) Polygon() Object {
gPoly := new(Polygon)
gPoly.base.Exterior = g.base
return gPoly
}

func (g *Rect) AppendJSON(dst []byte) []byte {
return g.Primative().AppendJSON(dst)
return g.Polygon().AppendJSON(dst)
}

func (g *Rect) JSON() string {
Expand Down

0 comments on commit ad814f6

Please sign in to comment.