Skip to content

Commit 6580a94

Browse files
rsnedalan-strohm
authored andcommitted
Add missing methods on Edge (golang#166)
shape.go had fallen behind C++. Added the missing edge methods. Add comments on what's left to catch back up. (This is needed for src/s2/internal/s2incident_edge_tracker to get to LegacyValidationQuery) --------- Co-authored-by: Alan Strohm <[email protected]>
1 parent 0738b43 commit 6580a94

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

s2/shape.go

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ import (
1818
"sort"
1919
)
2020

21-
// Edge represents a geodesic edge consisting of two vertices. Zero-length edges are
22-
// allowed, and can be used to represent points.
21+
// Edge represents a geodesic edge consisting of two vertices. Zero-length
22+
// edges are allowed, and can be used to represent points.
2323
type Edge struct {
2424
V0, V1 Point
2525
}
@@ -38,6 +38,27 @@ func (e Edge) Cmp(other Edge) int {
3838
return e.V1.Cmp(other.V1.Vector)
3939
}
4040

41+
// TODO(rsned): Add helpers for <=, >=
42+
43+
// Reversed returns a new edge with the vertices reversed.
44+
func (e Edge) Reversed() Edge {
45+
return Edge{V0: e.V1, V1: e.V0}
46+
}
47+
48+
// IsDegenerate reports if the edge is degenerate.
49+
func (e Edge) IsDegenerate() bool { return e.V0 == e.V1 }
50+
51+
// Incoming reports if point equals v1, indicating this edge is arriving.
52+
func (e Edge) Incoming(point Point) bool { return e.V1 == point }
53+
54+
// Outgoing reports if point equals v0, indicating this edge is leaving.
55+
func (e Edge) Outgoing(point Point) bool { return e.V0 == point }
56+
57+
// IncidentOn reports if point is one of the vertices of this edge.
58+
func (e Edge) IncidentOn(point Point) bool {
59+
return e.Incoming(point) || e.Outgoing(point)
60+
}
61+
4162
// sortEdges sorts the slice of Edges in place.
4263
func sortEdges(e []Edge) {
4364
sort.Sort(edges(e))
@@ -50,6 +71,8 @@ func (e edges) Len() int { return len(e) }
5071
func (e edges) Swap(i, j int) { e[i], e[j] = e[j], e[i] }
5172
func (e edges) Less(i, j int) bool { return e[i].Cmp(e[j]) == -1 }
5273

74+
// TODO(rsned): Implement the slices.SortFunc interface.
75+
5376
// ShapeEdgeID is a unique identifier for an Edge within an ShapeIndex,
5477
// consisting of a (shapeID, edgeID) pair.
5578
type ShapeEdgeID struct {
@@ -261,3 +284,9 @@ var (
261284
_ Shape = &Polygon{}
262285
_ Shape = &Polyline{}
263286
)
287+
288+
// TODO(rsned): Remaining methods and types from C++
289+
// ChainVertexIterator
290+
// ChainVertexRange
291+
// ChainIterator
292+
// ChainRange

0 commit comments

Comments
 (0)