diff --git a/s2/edge_vector_shape_test.go b/s2/edge_vector_shape_test.go index 5271136..559d5d6 100644 --- a/s2/edge_vector_shape_test.go +++ b/s2/edge_vector_shape_test.go @@ -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() {} diff --git a/s2/lax_loop_test.go b/s2/lax_loop_test.go index cdc73e1..9e3e5be 100644 --- a/s2/lax_loop_test.go +++ b/s2/lax_loop_test.go @@ -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() {} diff --git a/s2/lax_polygon_test.go b/s2/lax_polygon_test.go index 6046955..516ddf1 100644 --- a/s2/lax_polygon_test.go +++ b/s2/lax_polygon_test.go @@ -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) } diff --git a/s2/lax_polyline_test.go b/s2/lax_polyline_test.go index 580ab9a..90d8a77 100644 --- a/s2/lax_polyline_test.go +++ b/s2/lax_polyline_test.go @@ -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() {} diff --git a/s2/loop.go b/s2/loop.go index 0102db8..ae2ad4f 100644 --- a/s2/loop.go +++ b/s2/loop.go @@ -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. diff --git a/s2/point_vector.go b/s2/point_vector.go index 20c3626..b1613f6 100644 --- a/s2/point_vector.go +++ b/s2/point_vector.go @@ -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() {} diff --git a/s2/polygon.go b/s2/polygon.go index 3b25df8..57c43fb 100644 --- a/s2/polygon.go +++ b/s2/polygon.go @@ -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. diff --git a/s2/polyline.go b/s2/polyline.go index 75c32c1..2ac9bd4 100644 --- a/s2/polyline.go +++ b/s2/polyline.go @@ -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 diff --git a/s2/shape.go b/s2/shape.go index 4731fa4..2cbf170 100644 --- a/s2/shape.go +++ b/s2/shape.go @@ -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 @@ -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() } diff --git a/s2/shapeindex.go b/s2/shapeindex.go index f3e9a42..5374bbf 100644 --- a/s2/shapeindex.go +++ b/s2/shapeindex.go @@ -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