public static void TestIntervalTreeRandomConstruction() { int pointcount = 0; int passcount = 1000; int figureSize = 50; com.esri.core.geometry.Envelope env = new com.esri.core.geometry.Envelope(); env.SetCoords(-10000, -10000, 10000, 10000); com.esri.core.geometry.RandomCoordinateGenerator generator = new com.esri.core.geometry.RandomCoordinateGenerator(System.Math.Max(figureSize, 10000), env, 0.001); System.Random random = new System.Random(2013); int rand_max = 98765; System.Collections.Generic.List<com.esri.core.geometry.Envelope1D> intervals = new System.Collections.Generic.List<com.esri.core.geometry.Envelope1D>(); com.esri.core.geometry.AttributeStreamOfInt8 intervalsFound = new com.esri.core.geometry.AttributeStreamOfInt8(0); for (int i = 0; i < passcount; i++) { int r = figureSize; if (r < 3) { continue; } com.esri.core.geometry.Polygon poly = new com.esri.core.geometry.Polygon(); com.esri.core.geometry.Point pt; for (int j = 0; j < r; j++) { int rand = random.Next(rand_max); bool bRandomNew = (r > 10) && ((1.0 * rand) / rand_max > 0.95); pt = generator.GetRandomCoord(); if (j == 0 || bRandomNew) { poly.StartPath(pt); } else { poly.LineTo(pt); } } { intervals.Clear(); com.esri.core.geometry.SegmentIterator seg_iter = poly.QuerySegmentIterator(); com.esri.core.geometry.Envelope1D interval; com.esri.core.geometry.Envelope1D range = poly.QueryInterval(com.esri.core.geometry.VertexDescription.Semantics.POSITION, 0); range.vmin -= 0.01; range.vmax += 0.01; while (seg_iter.NextPath()) { while (seg_iter.HasNextSegment()) { com.esri.core.geometry.Segment segment = seg_iter.NextSegment(); interval = segment.QueryInterval(com.esri.core.geometry.VertexDescription.Semantics.POSITION, 0); intervals.Add(interval); } } intervalsFound.Resize(intervals.Count, 0); // Just test construction for assertions com.esri.core.geometry.IntervalTreeImpl intervalTree = new com.esri.core.geometry.IntervalTreeImpl(true); Construct(intervalTree, intervals); for (int j_1 = 0; j_1 < intervals.Count; j_1++) { intervalTree.Insert(j_1); } com.esri.core.geometry.IntervalTreeImpl.IntervalTreeIteratorImpl iterator = intervalTree.GetIterator(range, 0.0); int count = 0; int handle; while ((handle = iterator.Next()) != -1) { count++; intervalsFound.Write(handle, unchecked((byte)1)); } NUnit.Framework.Assert.IsTrue(count == intervals.Count); for (int j_2 = 0; j_2 < intervalsFound.Size(); j_2++) { interval = intervals[j_2]; NUnit.Framework.Assert.IsTrue(intervalsFound.Read(j_2) == 1); } for (int j_3 = 0; j_3 < intervals.Count >> 1; j_3++) { intervalTree.Remove(j_3); } iterator.ResetIterator(range, 0.0); count = 0; while ((handle = iterator.Next()) != -1) { count++; intervalsFound.Write(handle, unchecked((byte)1)); } NUnit.Framework.Assert.IsTrue(count == intervals.Count - (intervals.Count >> 1)); for (int j_4 = (intervals.Count >> 1); j_4 < intervals.Count; j_4++) { intervalTree.Remove(j_4); } } } }
public static void testIntervalTreeRandomConstruction() { int pointcount = 0; int passcount = 1000; int figureSize = 50; com.esri.core.geometry.Envelope env = new com.esri.core.geometry.Envelope(); env.setCoords(-10000, -10000, 10000, 10000); com.esri.core.geometry.RandomCoordinateGenerator generator = new com.esri.core.geometry.RandomCoordinateGenerator (System.Math.max(figureSize, 10000), env, 0.001); java.util.Random random = new java.util.Random(2013); int rand_max = 98765; System.Collections.Generic.List <com.esri.core.geometry.Envelope1D> intervals = new System.Collections.Generic.List <com.esri.core.geometry.Envelope1D>(); com.esri.core.geometry.AttributeStreamOfInt8 intervalsFound = new com.esri.core.geometry.AttributeStreamOfInt8 (0); for (int i = 0; i < passcount; i++) { int r = figureSize; if (r < 3) { continue; } com.esri.core.geometry.Polygon poly = new com.esri.core.geometry.Polygon(); com.esri.core.geometry.Point pt; for (int j = 0; j < r; j++) { int rand = random.nextInt(rand_max); bool bRandomNew = (r > 10) && ((1.0 * rand) / rand_max > 0.95); pt = generator.GetRandomCoord(); if (j == 0 || bRandomNew) { poly.startPath(pt); } else { poly.lineTo(pt); } } { intervals.clear(); com.esri.core.geometry.SegmentIterator seg_iter = poly.querySegmentIterator(); com.esri.core.geometry.Envelope1D interval; com.esri.core.geometry.Envelope1D range = poly.queryInterval(com.esri.core.geometry.VertexDescription.Semantics .POSITION, 0); range.vmin -= 0.01; range.vmax += 0.01; while (seg_iter.nextPath()) { while (seg_iter.hasNextSegment()) { com.esri.core.geometry.Segment segment = seg_iter.nextSegment(); interval = segment.queryInterval(com.esri.core.geometry.VertexDescription.Semantics .POSITION, 0); intervals.add(interval); } } intervalsFound.resize(intervals.Count, 0); // Just test construction for assertions com.esri.core.geometry.IntervalTreeImpl intervalTree = new com.esri.core.geometry.IntervalTreeImpl (true); construct(intervalTree, intervals); for (int j_1 = 0; j_1 < intervals.Count; j_1++) { intervalTree.insert(j_1); } com.esri.core.geometry.IntervalTreeImpl.IntervalTreeIteratorImpl iterator = intervalTree .getIterator(range, 0.0); int count = 0; int handle; while ((handle = iterator.next()) != -1) { count++; intervalsFound.write(handle, unchecked ((byte)1)); } NUnit.Framework.Assert.IsTrue(count == intervals.Count); for (int j_2 = 0; j_2 < intervalsFound.size(); j_2++) { interval = intervals[j_2]; NUnit.Framework.Assert.IsTrue(intervalsFound.read(j_2) == 1); } for (int j_3 = 0; j_3 < intervals.Count >> 1; j_3++) { intervalTree.remove(j_3); } iterator.resetIterator(range, 0.0); count = 0; while ((handle = iterator.next()) != -1) { count++; intervalsFound.write(handle, unchecked ((byte)1)); } NUnit.Framework.Assert.IsTrue(count == intervals.Count - (intervals.Count >> 1)); for (int j_4 = (intervals.Count >> 1); j_4 < intervals.Count; j_4++) { intervalTree.remove(j_4); } } } }