/// <summary> /// It is hard to create a situation where border segments change by /// enough to cause an invalid geometry to be returned. /// One way is to use a fixed precision model, /// which will cause segments to move enough to /// intersect with non-overlapping components. /// <para/> /// However, the current union algorithm /// emits topology failures for these situations, since /// it is not performing snap-rounding. /// These exceptions are irrelevant to the correctness /// of the OverlapUnion algorithm, so are prevented from being reported as a test failure. /// </summary> /// <param name="wktA"></param> /// <param name="wktB"></param> /// <param name="scaleFactor"></param> private static void CheckUnionWithTopologyFailure(string wktA, string wktB, double scaleFactor) { var rdr = new WKTReader(new NtsGeometryServices(new PrecisionModel(scaleFactor), 0)); var a = rdr.Read(wktA); var b = rdr.Read(wktB); var union = new OverlapUnion(a, b); Geometry result; try { result = union.Union(); } catch (TopologyException) { bool isOptimized = union.IsUnionOptimized; // if the optimized algorithm was used then this is a real error if (isOptimized) { throw; } // otherwise the error is probably due to the fixed precision // not being handled by the current union code return; } Assert.IsTrue(result.IsValid, "OverlapUnion result is invalid"); }
private static void CheckUnion(string wktA, string wktB, bool isCheckOptimized) { var rdr = new WKTReader(); var a = rdr.Read(wktA); var b = rdr.Read(wktB); var union = new OverlapUnion(a, b); var result = union.Union(); if (isCheckOptimized) { bool isOptimized = union.IsUnionOptimized; Assert.IsTrue(isOptimized, "Union was not performed using combine"); } Assert.IsTrue(result.IsValid, "OverlapUnion result is invalid"); }