private static Boolean CheckIntersects(IGeometry target, IGeometry test) { bool expectedResult = target.Intersects(test); PreparedGeometryFactory pgFact = new PreparedGeometryFactory(); IPreparedGeometry prepGeom = pgFact.Create(target); bool prepResult = prepGeom.Intersects(test); if (prepResult != expectedResult) { return false; } return true; }
/// <summary> /// Tests using PreparedGeometry, but creating a new /// PreparedGeometry object each time. /// This tests whether there is a penalty for using /// the PG algorithm as a complete replacement for /// the original algorithm. /// </summary> /// <param name="g">The polygonal test geometry</param> /// <param name="lines">The lines to test for intersection with <paramref name="g"/></param> /// <returns>The count</returns> private static int TestPrepGeomNotCached(IGeometry g, IEnumerable<IGeometry> lines) { Console.WriteLine("Using NON-CACHED Prepared Geometry"); var pgFact = new PreparedGeometryFactory(); // PreparedGeometry prepGeom = pgFact.create(g); int count = 0; foreach (var line in lines) { // test performance of creating the prepared geometry each time var prepGeom = pgFact.Create(g); if (prepGeom.Intersects(line)) count++; } return count; }
private static int TestPrepGeomCached(IGeometry g, IEnumerable<IGeometry> lines) { Console.WriteLine("Using cached Prepared Geometry"); var pgFact = new PreparedGeometryFactory(); var prepGeom = pgFact.Create(g); var count = 0; foreach (var line in lines) { if (prepGeom.Intersects(line)) count++; } return count; }
public void TestResultsEqual(IGeometry g, ILineString line) { bool slowIntersects = g.Intersects(line); PreparedGeometryFactory pgFact = new PreparedGeometryFactory(); IPreparedGeometry prepGeom = pgFact.Create(g); bool fastIntersects = prepGeom.Intersects(line); if (slowIntersects != fastIntersects) { Console.WriteLine(line); Console.WriteLine("Slow = " + slowIntersects + ", Fast = " + fastIntersects); throw new Exception("Different results found for intersects() !"); } }