Skip to content

Commit

Permalink
s2: Add type tags to the Shape interface.
Browse files Browse the repository at this point in the history
This begins the support for different encoding mechanisms and options,
mirroring C++.

Signed-off-by: David Symonds <dsymonds@golang.org>
  • Loading branch information
rsned authored and dsymonds committed Aug 12, 2019
1 parent e29ec1b commit f4445d1
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 4 deletions.
1 change: 1 addition & 0 deletions s2/edge_vector_shape_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,5 @@ func (e *edgeVectorShape) ChainPosition(edgeID int) ChainPosition { return Chain
func (e *edgeVectorShape) IsEmpty() bool { return defaultShapeIsEmpty(e) }
func (e *edgeVectorShape) IsFull() bool { return defaultShapeIsFull(e) }
func (e *edgeVectorShape) Dimension() int { return 1 }
func (e *edgeVectorShape) typeTag() typeTag { return typeTagNone }
func (e *edgeVectorShape) privateInterface() {}
1 change: 1 addition & 0 deletions s2/lax_loop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,5 @@ func (l *laxLoop) ChainEdge(i, j int) Edge {
func (l *laxLoop) ChainPosition(e int) ChainPosition { return ChainPosition{0, e} }
func (l *laxLoop) IsEmpty() bool { return defaultShapeIsEmpty(l) }
func (l *laxLoop) IsFull() bool { return defaultShapeIsFull(l) }
func (l *laxLoop) typeTag() typeTag { return typeTagNone }
func (l *laxLoop) privateInterface() {}
1 change: 1 addition & 0 deletions s2/lax_polygon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ func (p *laxPolygon) Edge(e int) Edge {
}

func (p *laxPolygon) Dimension() int { return 2 }
func (p *laxPolygon) typeTag() typeTag { return typeTagLaxPolygon }
func (p *laxPolygon) privateInterface() {}
func (p *laxPolygon) IsEmpty() bool { return defaultShapeIsEmpty(p) }
func (p *laxPolygon) IsFull() bool { return defaultShapeIsFull(p) }
Expand Down
1 change: 1 addition & 0 deletions s2/lax_polyline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,5 @@ func (l *laxPolyline) ChainPosition(e int) ChainPosition { return ChainPosition{
func (l *laxPolyline) Dimension() int { return 1 }
func (l *laxPolyline) IsEmpty() bool { return defaultShapeIsEmpty(l) }
func (l *laxPolyline) IsFull() bool { return defaultShapeIsFull(l) }
func (l *laxPolyline) typeTag() typeTag { return typeTagLaxPolyline }
func (l *laxPolyline) privateInterface() {}
2 changes: 2 additions & 0 deletions s2/loop.go
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,8 @@ func (l *Loop) ChainPosition(edgeID int) ChainPosition {
// Dimension returns the dimension of the geometry represented by this Loop.
func (l *Loop) Dimension() int { return 2 }

func (l *Loop) typeTag() typeTag { return typeTagNone }

func (l *Loop) privateInterface() {}

// IsEmpty reports true if this is the special empty loop that contains no points.
Expand Down
1 change: 1 addition & 0 deletions s2/point_vector.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@ func (p *PointVector) ChainPosition(e int) ChainPosition { return ChainPosition{
func (p *PointVector) Dimension() int { return 0 }
func (p *PointVector) IsEmpty() bool { return defaultShapeIsEmpty(p) }
func (p *PointVector) IsFull() bool { return defaultShapeIsFull(p) }
func (p *PointVector) typeTag() typeTag { return typeTagPointVector }
func (p *PointVector) privateInterface() {}
2 changes: 2 additions & 0 deletions s2/polygon.go
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,8 @@ func (p *Polygon) ChainPosition(edgeID int) ChainPosition {
// Dimension returns the dimension of the geometry represented by this Polygon.
func (p *Polygon) Dimension() int { return 2 }

func (p *Polygon) typeTag() typeTag { return typeTagPolygon }

func (p *Polygon) privateInterface() {}

// Contains reports whether this polygon contains the other polygon.
Expand Down
2 changes: 2 additions & 0 deletions s2/polyline.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ func (p *Polyline) IsEmpty() bool { return defaultShapeIsEmpty(p) }
// IsFull reports whether this shape contains all points on the sphere.
func (p *Polyline) IsFull() bool { return defaultShapeIsFull(p) }

func (p *Polyline) typeTag() typeTag { return typeTagPolyline }

func (p *Polyline) privateInterface() {}

// findEndVertex reports the maximal end index such that the line segment between
Expand Down
21 changes: 21 additions & 0 deletions s2/shape.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,23 @@ func OriginReferencePoint(contained bool) ReferencePoint {
return ReferencePoint{Point: OriginPoint(), Contained: contained}
}

// typeTag is a 32-bit tag that can be used to identify the type of an encoded
// Shape. All encodable types have a non-zero type tag. The tag associated with
type typeTag uint32

const (
// Indicates that a given Shape type cannot be encoded.
typeTagNone typeTag = 0
typeTagPolygon typeTag = 1
typeTagPolyline typeTag = 2
typeTagPointVector typeTag = 3
typeTagLaxPolyline typeTag = 4
typeTagLaxPolygon typeTag = 5

// The minimum allowable tag for future user-defined Shape types.
typeTagMinUser typeTag = 8192
)

// Shape represents polygonal geometry in a flexible way. It is organized as a
// collection of edges that optionally defines an interior. All geometry
// represented by a given Shape must have the same dimension, which means that
Expand Down Expand Up @@ -220,6 +237,10 @@ type Shape interface {
// IsFull reports whether the Shape contains all points on the sphere.
IsFull() bool

// typeTag returns a value that can be used to identify the type of an
// encoded Shape.
typeTag() typeTag

// We do not support implementations of this interface outside this package.
privateInterface()
}
Expand Down
4 changes: 0 additions & 4 deletions s2/shapeindex.go
Original file line number Diff line number Diff line change
Expand Up @@ -1514,7 +1514,3 @@ func maxLevelForEdge(edge Edge) int {
func (s *ShapeIndex) removeShapeInternal(removed *removedShape, allEdges [][]faceEdge, t *tracker) {
// TODO(roberts): finish the implementation of this.
}

// TODO(roberts): Differences from C++.
// ShapeContainsPoint
// FindContainingShapes

0 comments on commit f4445d1

Please sign in to comment.