Skip to content

Commit

Permalink
s2: Drop the deprecated SimpleCrossing.
Browse files Browse the repository at this point in the history
It was replaced by the more general CrossingSign in f13a53c.
  • Loading branch information
dsymonds committed Nov 28, 2017
1 parent 402d75f commit ec03579
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 55 deletions.
39 changes: 10 additions & 29 deletions s2/edge_crosser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ func TestEdgeCrosserCrossings(t *testing.T) {
a, b, c, d Point
robust Crossing
edgeOrVertex bool
simple bool
}{
{
msg: "two regular edges that cross",
Expand All @@ -43,7 +42,6 @@ func TestEdgeCrosserCrossings(t *testing.T) {
d: Point{r3.Vector{0.1, 0.5, 3}},
robust: Cross,
edgeOrVertex: true,
simple: true,
},
{
msg: "two regular edges that intersect antipodal points",
Expand All @@ -53,7 +51,6 @@ func TestEdgeCrosserCrossings(t *testing.T) {
d: Point{r3.Vector{-0.1, -0.5, -3}},
robust: DoNotCross,
edgeOrVertex: false,
simple: true,
},
{
msg: "two edges on the same great circle that start at antipodal points",
Expand All @@ -63,7 +60,6 @@ func TestEdgeCrosserCrossings(t *testing.T) {
d: Point{r3.Vector{0, 1, 1}},
robust: DoNotCross,
edgeOrVertex: false,
simple: true,
},
{
msg: "two edges that cross where one vertex is the OriginPoint",
Expand All @@ -73,7 +69,6 @@ func TestEdgeCrosserCrossings(t *testing.T) {
d: Point{r3.Vector{1, 1, -0.1}},
robust: Cross,
edgeOrVertex: true,
simple: true,
},
{
msg: "two edges that intersect antipodal points where one vertex is the OriginPoint",
Expand All @@ -83,7 +78,6 @@ func TestEdgeCrosserCrossings(t *testing.T) {
d: Point{r3.Vector{1, 1, -0.1}},
robust: DoNotCross,
edgeOrVertex: false,
simple: true,
},
{
msg: "two edges that cross antipodal points",
Expand All @@ -93,7 +87,6 @@ func TestEdgeCrosserCrossings(t *testing.T) {
d: Point{r3.Vector{-1, -1, 1}},
robust: DoNotCross,
edgeOrVertex: false,
simple: true,
},
{
// The Ortho() direction is (-4,0,2) and edge CD
Expand All @@ -105,7 +98,6 @@ func TestEdgeCrosserCrossings(t *testing.T) {
d: Point{r3.Vector{2, 3, 4}},
robust: MaybeCross,
edgeOrVertex: false,
simple: true,
},
{
// The edge AB is approximately in the x=y plane, while CD is approximately
Expand All @@ -117,7 +109,6 @@ func TestEdgeCrosserCrossings(t *testing.T) {
d: Point{r3.Vector{10, 10, 1}},
robust: Cross,
edgeOrVertex: true,
simple: false,
},
{
msg: "two edges that barely cross near the middle separated by a distance of about 1e-15",
Expand All @@ -127,7 +118,6 @@ func TestEdgeCrosserCrossings(t *testing.T) {
d: Point{r3.Vector{1, 1, 0}},
robust: DoNotCross,
edgeOrVertex: false,
simple: false,
},
{
// This example cannot be handled using regular double-precision
Expand All @@ -139,7 +129,6 @@ func TestEdgeCrosserCrossings(t *testing.T) {
d: Point{r3.Vector{1e-323, 0, 1}},
robust: Cross,
edgeOrVertex: true,
simple: false,
},
{
msg: "two edges that barely cross each other near the end separated by a distance of about 1e-640",
Expand All @@ -149,7 +138,6 @@ func TestEdgeCrosserCrossings(t *testing.T) {
d: Point{r3.Vector{1e-323, 0, 1}},
robust: DoNotCross,
edgeOrVertex: false,
simple: false,
},
{
msg: "two edges that barely cross each other near the middle of one edge",
Expand All @@ -161,7 +149,6 @@ func TestEdgeCrosserCrossings(t *testing.T) {
d: Point{r3.Vector{1, 1, 0}},
robust: Cross,
edgeOrVertex: true,
simple: false,
},
{
msg: "two edges that barely cross each other near the middle separated by a distance of about 1e-640",
Expand All @@ -171,7 +158,6 @@ func TestEdgeCrosserCrossings(t *testing.T) {
d: Point{r3.Vector{1, 1, 0}},
robust: DoNotCross,
edgeOrVertex: false,
simple: false,
},
}

Expand All @@ -181,33 +167,28 @@ func TestEdgeCrosserCrossings(t *testing.T) {
b := Point{test.b.Normalize()}
c := Point{test.c.Normalize()}
d := Point{test.d.Normalize()}
testCrossing(t, test.msg, a, b, c, d, test.robust, test.edgeOrVertex, test.simple)
testCrossing(t, test.msg, b, a, c, d, test.robust, test.edgeOrVertex, test.simple)
testCrossing(t, test.msg, a, b, d, c, test.robust, test.edgeOrVertex, test.simple)
testCrossing(t, test.msg, b, a, d, c, test.robust, test.edgeOrVertex, test.simple)
testCrossing(t, test.msg, a, b, c, d, test.robust, test.edgeOrVertex)
testCrossing(t, test.msg, b, a, c, d, test.robust, test.edgeOrVertex)
testCrossing(t, test.msg, a, b, d, c, test.robust, test.edgeOrVertex)
testCrossing(t, test.msg, b, a, d, c, test.robust, test.edgeOrVertex)

// test degenerate cases
testCrossing(t, test.msg, a, a, c, d, DoNotCross, false, false)
testCrossing(t, test.msg, a, b, c, c, DoNotCross, false, false)
testCrossing(t, test.msg, a, a, c, c, DoNotCross, false, false)
testCrossing(t, test.msg, a, a, c, d, DoNotCross, false)
testCrossing(t, test.msg, a, b, c, c, DoNotCross, false)
testCrossing(t, test.msg, a, a, c, c, DoNotCross, false)

testCrossing(t, test.msg, a, b, a, b, MaybeCross, true, false)
testCrossing(t, test.msg, c, d, a, b, test.robust, test.edgeOrVertex != (test.robust == MaybeCross), test.simple)
testCrossing(t, test.msg, a, b, a, b, MaybeCross, true)
testCrossing(t, test.msg, c, d, a, b, test.robust, test.edgeOrVertex != (test.robust == MaybeCross))
}
}

func testCrossing(t *testing.T, msg string, a, b, c, d Point, robust Crossing, edgeOrVertex, simple bool) {
func testCrossing(t *testing.T, msg string, a, b, c, d Point, robust Crossing, edgeOrVertex bool) {
// Modify the expected result if two vertices from different edges match.
if a == c || a == d || b == c || b == d {
robust = MaybeCross
}

input := fmt.Sprintf("%s: a: %v, b: %v, c: %v, d: %v", msg, a, b, c, d)
if simple {
if got, want := SimpleCrossing(a, b, c, d), robust == Cross; got != want {
t.Errorf("%v, SimpleCrossing(a, b, c, d) = %t, want %t", input, got, want)
}
}

crosser := NewChainEdgeCrosser(a, b, c)
if got, want := crosser.ChainCrossingSign(d), robust; got != want {
Expand Down
24 changes: 0 additions & 24 deletions s2/edge_crossings.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,30 +67,6 @@ func (c Crossing) String() string {
}
}

// SimpleCrossing reports whether edge AB crosses CD at a point that is interior
// to both edges. Properties:
//
// (1) SimpleCrossing(b,a,c,d) == SimpleCrossing(a,b,c,d)
// (2) SimpleCrossing(c,d,a,b) == SimpleCrossing(a,b,c,d)
//
// DEPRECATED: Use CrossingSign(a,b,c,d) == Cross instead.
func SimpleCrossing(a, b, c, d Point) bool {
// We compute the equivalent of Sign for triangles ACB, CBD, BDA,
// and DAC. All of these triangles need to have the same orientation
// (CW or CCW) for an intersection to exist.
ab := a.Vector.Cross(b.Vector)
acb := -(ab.Dot(c.Vector))
bda := ab.Dot(d.Vector)
if acb*bda <= 0 {
return false
}

cd := c.Vector.Cross(d.Vector)
cbd := -(cd.Dot(b.Vector))
dac := cd.Dot(a.Vector)
return (acb*cbd > 0) && (acb*dac > 0)
}

// CrossingSign reports whether the edge AB intersects the edge CD.
// If AB crosses CD at a point that is interior to both edges, Cross is returned.
// If any two vertices from different edges are the same it returns MaybeCross.
Expand Down
4 changes: 2 additions & 2 deletions s2/rect.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,8 @@ func intersectsLatEdge(a, b Point, lat s1.Angle, lng s1.Interval) bool {
func intersectsLngEdge(a, b Point, lat r1.Interval, lng s1.Angle) bool {
// The nice thing about edges of constant longitude is that
// they are straight lines on the sphere (geodesics).
return SimpleCrossing(a, b, PointFromLatLng(LatLng{s1.Angle(lat.Lo), lng}),
PointFromLatLng(LatLng{s1.Angle(lat.Hi), lng}))
return CrossingSign(a, b, PointFromLatLng(LatLng{s1.Angle(lat.Lo), lng}),
PointFromLatLng(LatLng{s1.Angle(lat.Hi), lng})) == Cross
}

// IntersectsCell reports whether this rectangle intersects the given cell. This is an
Expand Down

0 comments on commit ec03579

Please sign in to comment.