Permalink
Browse files

Fixed another numerical conditioning issue with circles on the very edge

  • Loading branch information...
1 parent b79771f commit 3da8e87523cc8e9ea21a3021c9c5482e52b532b0 @synhershko committed Sep 16, 2012
Showing with 6 additions and 2 deletions.
  1. +4 −2 Spatial4n.Core/Shapes/Impl/GeoCircle.cs
  2. +2 −0 Spatial4n.Tests/shape/TestShapesGeo.cs
@@ -53,10 +53,12 @@ private void Init()
if (backDistDEG > 0)
{
double backRadius = 180 - radiusDEG;
- //shrink inverseCircle as small as possible to avoid accidental overlap
- backRadius -= Ulp(backRadius);
double backX = DistanceUtils.NormLonDEG(GetCenter().GetX() + 180);
double backY = DistanceUtils.NormLatDEG(GetCenter().GetY() + 180);
+ //Shrink inverseCircle as small as possible to avoid accidental overlap.
+ // Note that this is tricky business to come up with a value small enough
+ // but not too small or else numerical conditioning issues become a problem.
+ backRadius -= Math.Max(Ulp(Math.Abs(backY) + backRadius), Ulp(Math.Abs(backX) + backRadius));
if (inverseCircle != null)
{
inverseCircle.Reset(backX, backY, backRadius);
@@ -117,6 +117,8 @@ public void TestGeoCircle(SpatialContext ctx)
// assertEquals("dist != xy space", INTERSECTS, c.relate(r, ctx));//once failed here
//}
+ assertEquals("edge rounding issue 2", SpatialRelation.INTERSECTS, ctx.MakeCircle(84, -40, 136).Relate(ctx.MakeRectangle(-150, -80, 34, 84)));
+
assertEquals("edge rounding issue", SpatialRelation.CONTAINS, ctx.MakeCircle(0, 66, 156).Relate(ctx.MakePoint(0, -90)));
assertEquals("nudge back circle", SpatialRelation.CONTAINS, ctx.MakeCircle(-150, -90, 122).Relate(ctx.MakeRectangle(0, -132, 32, 32)));

0 comments on commit 3da8e87

Please sign in to comment.