Skip to content

Commit

Permalink
s2: Fix two mistakes in the error bound calculations for s1.ChordAngl…
Browse files Browse the repository at this point in the history
…e distances.

Signed-off-by: David Symonds <[email protected]>
  • Loading branch information
rsned authored and dsymonds committed Aug 24, 2018
1 parent 7ebb027 commit 44f0b35
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion s2/edge_distances.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ func minUpdateInteriorDistanceMaxError(dist s1.ChordAngle) float64 {
// This bound includes all source of error, assuming that the input points
// are normalized. a and b are components of chord length that are
// perpendicular and parallel to a plane containing the edge respectively.
b := math.Min(1.0, 0.5*float64(dist)*float64(dist))
b := math.Min(1.0, 0.5*float64(dist))
a := math.Sqrt(b * (2 - b))
return ((2.5+2*math.Sqrt(3)+8.5*a)*a +
(2+2*math.Sqrt(3)/3+6.5*(1-b))*b +
Expand Down
3 changes: 3 additions & 0 deletions s2/edge_distances_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,9 @@ func TestEdgeDistanceMinUpdateDistanceMaxError(t *testing.T) {
}
}

// TODO(roberts): TestEdgeDistanceUpdateMinInteriorDistanceMaxError once s2predicates
// CompareEdgeDistance

func TestEdgeDistancesEdgePairMinDistance(t *testing.T) {
var zero Point
tests := []struct {
Expand Down
39 changes: 39 additions & 0 deletions s2/s2_test_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,42 @@ func TestTestingFractal(t *testing.T) {
}
}
}

// TestChordAngleMaxPointError is located in here to work around circular
// import issues. This s1 test needs s2.Points which wont work with our
// packages. The test is in this file since while it uses Points, it's not
// part of Points methods so it shouldn't be in s2point_test.
func TestChordAngleMaxPointError(t *testing.T) {
// Check that the error bound returned by s1.MaxPointError() is
// large enough.
const iters = 100000
for iter := 0; iter < iters; iter++ {
x := randomPoint()
y := randomPoint()
if oneIn(10) {
// Occasionally test a point pair that is nearly identical or antipodal.
r := s1.Angle(1e-15 * randomFloat64())
y = InterpolateAtDistance(r, x, y)
if oneIn(2) {
y = Point{y.Mul(-1)}
}
}
dist := ChordAngleBetweenPoints(x, y)
err := dist.MaxPointError()
if got, want := CompareDistance(x, y, dist.Expanded(err)), 0; got > 0 {
t.Errorf("CompareDistance(%v, %v, %v.Expanded(%v)) = %v, want <= %v", x, y, dist, err, got, want)
}
if got, want := CompareDistance(x, y, dist.Expanded(-err)), 0; got < 0 {
t.Errorf("CompareDistance(%v, %v, %v.Expanded(-%v)) = %v, want >= %v", x, y, dist, err, got, want)
}
}
}

// TODO(roberts): Remaining tests
// TriangleFractal
// TriangleMultiFractal
// SpaceFillingFractal
// KochCurveFractal
// KochCurveMultiFractal
// CesaroFractal
// CesaroMultiFractal

0 comments on commit 44f0b35

Please sign in to comment.