internal static int PolygonText(com.epl.geometry.AttributeStreamOfDbl zs, com.epl.geometry.AttributeStreamOfDbl ms, com.epl.geometry.AttributeStreamOfDbl position, com.epl.geometry.AttributeStreamOfInt32 paths, com.epl.geometry.AttributeStreamOfInt8 path_flags, int total_point_count , com.epl.geometry.WktParser wkt_parser) { // At start of PolygonText int current_token = wkt_parser.CurrentToken(); if (current_token == com.epl.geometry.WktParser.WktToken.empty) { return(total_point_count); } bool b_first_line_string = true; current_token = wkt_parser.NextToken(); while (current_token != com.epl.geometry.WktParser.WktToken.right_paren) { // At start of LineStringText int point_count = LineStringText(true, zs, ms, position, paths, path_flags, wkt_parser); if (point_count != 0) { if (b_first_line_string) { b_first_line_string = false; path_flags.SetBits(path_flags.Size() - 2, unchecked ((byte)com.epl.geometry.PathFlags.enumOGCStartPolygon)); } path_flags.SetBits(path_flags.Size() - 2, unchecked ((byte)com.epl.geometry.PathFlags.enumClosed)); total_point_count += point_count; } current_token = wkt_parser.NextToken(); } return(total_point_count); }
public override bool Equals(com.epl.geometry.AttributeStreamBase other, int start, int end) { if (other == null) { return(false); } if (!(other is com.epl.geometry.AttributeStreamOfInt8)) { return(false); } com.epl.geometry.AttributeStreamOfInt8 _other = (com.epl.geometry.AttributeStreamOfInt8)other; int size = Size(); int sizeOther = _other.Size(); if (end > size || end > sizeOther && (size != sizeOther)) { return(false); } if (end > size) { end = size; } for (int i = start; i < end; i++) { if (Read(i) != _other.Read(i)) { return(false); } } return(true); }
public AttributeStreamOfInt8(com.epl.geometry.AttributeStreamOfInt8 other, int maxSize) { m_size = other.Size(); if (m_size > maxSize) { m_size = maxSize; } int sz = m_size; if (sz < 2) { sz = 2; } m_buffer = new byte[sz]; System.Array.Copy(other.m_buffer, 0, m_buffer, 0, m_size); }
public static void TestIntervalTree_RandomConstruction() { int pointcount = 0; int passcount = 1000; int figureSize = 50; com.epl.geometry.Envelope env = new com.epl.geometry.Envelope(); env.SetCoords(-10000, -10000, 10000, 10000); com.epl.geometry.RandomCoordinateGenerator generator = new com.epl.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.epl.geometry.Envelope1D> intervals = new System.Collections.Generic.List <com.epl.geometry.Envelope1D>(); com.epl.geometry.AttributeStreamOfInt8 intervalsFound = new com.epl.geometry.AttributeStreamOfInt8(0); for (int i = 0; i < passcount; i++) { int r = figureSize; if (r < 3) { continue; } com.epl.geometry.Polygon poly = new com.epl.geometry.Polygon(); com.epl.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.epl.geometry.SegmentIterator seg_iter = poly.QuerySegmentIterator(); com.epl.geometry.Envelope1D interval; com.epl.geometry.Envelope1D range = poly.QueryInterval(com.epl.geometry.VertexDescription.Semantics.POSITION, 0); range.vmin -= 0.01; range.vmax += 0.01; while (seg_iter.NextPath()) { while (seg_iter.HasNextSegment()) { com.epl.geometry.Segment segment = seg_iter.NextSegment(); interval = segment.QueryInterval(com.epl.geometry.VertexDescription.Semantics.POSITION, 0); intervals.Add(interval); } } intervalsFound.Resize(intervals.Count, 0); // Just test construction for assertions com.epl.geometry.IntervalTreeImpl intervalTree = new com.epl.geometry.IntervalTreeImpl(true); Construct(intervalTree, intervals); for (int j_1 = 0; j_1 < intervals.Count; j_1++) { intervalTree.Insert(j_1); } com.epl.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); } } } }
internal static com.epl.geometry.Geometry PolygonTaggedText(bool b_multi_polygon, int import_flags, com.epl.geometry.WktParser wkt_parser) { com.epl.geometry.MultiPath multi_path; com.epl.geometry.MultiPathImpl multi_path_impl; com.epl.geometry.AttributeStreamOfDbl zs = null; com.epl.geometry.AttributeStreamOfDbl ms = null; com.epl.geometry.AttributeStreamOfDbl position; com.epl.geometry.AttributeStreamOfInt32 paths; com.epl.geometry.AttributeStreamOfInt8 path_flags; position = (com.epl.geometry.AttributeStreamOfDbl)com.epl.geometry.AttributeStreamBase.CreateDoubleStream(0); paths = (com.epl.geometry.AttributeStreamOfInt32)com.epl.geometry.AttributeStreamBase.CreateIndexStream(1, 0); path_flags = (com.epl.geometry.AttributeStreamOfInt8)com.epl.geometry.AttributeStreamBase.CreateByteStream(1, unchecked ((byte)0)); multi_path = new com.epl.geometry.Polygon(); multi_path_impl = (com.epl.geometry.MultiPathImpl)multi_path._getImpl(); int current_token = wkt_parser.NextToken(); if (current_token == com.epl.geometry.WktParser.WktToken.attribute_z) { zs = (com.epl.geometry.AttributeStreamOfDbl)com.epl.geometry.AttributeStreamBase.CreateDoubleStream(0, com.epl.geometry.NumberUtils.TheNaN); multi_path_impl.AddAttribute(com.epl.geometry.VertexDescription.Semantics.Z); wkt_parser.NextToken(); } else { if (current_token == com.epl.geometry.WktParser.WktToken.attribute_m) { ms = (com.epl.geometry.AttributeStreamOfDbl)com.epl.geometry.AttributeStreamBase.CreateDoubleStream(0, com.epl.geometry.NumberUtils.TheNaN); multi_path_impl.AddAttribute(com.epl.geometry.VertexDescription.Semantics.M); wkt_parser.NextToken(); } else { if (current_token == com.epl.geometry.WktParser.WktToken.attribute_zm) { zs = (com.epl.geometry.AttributeStreamOfDbl)com.epl.geometry.AttributeStreamBase.CreateDoubleStream(0, com.epl.geometry.NumberUtils.TheNaN); ms = (com.epl.geometry.AttributeStreamOfDbl)com.epl.geometry.AttributeStreamBase.CreateDoubleStream(0, com.epl.geometry.NumberUtils.TheNaN); multi_path_impl.AddAttribute(com.epl.geometry.VertexDescription.Semantics.Z); multi_path_impl.AddAttribute(com.epl.geometry.VertexDescription.Semantics.M); wkt_parser.NextToken(); } } } int point_count; if (b_multi_polygon) { point_count = MultiPolygonText(zs, ms, position, paths, path_flags, wkt_parser); } else { point_count = PolygonText(zs, ms, position, paths, path_flags, 0, wkt_parser); } if (point_count != 0) { System.Diagnostics.Debug.Assert((2 * point_count == position.Size())); multi_path_impl.SetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.POSITION, position); multi_path_impl.SetPathStreamRef(paths); multi_path_impl.SetPathFlagsStreamRef(path_flags); if (zs != null) { multi_path_impl.SetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.Z, zs); } if (ms != null) { multi_path_impl.SetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.M, ms); } multi_path_impl.NotifyModified(com.epl.geometry.MultiVertexGeometryImpl.DirtyFlags.DirtyAll); com.epl.geometry.AttributeStreamOfInt8 path_flags_clone = new com.epl.geometry.AttributeStreamOfInt8(path_flags); for (int i = 0; i < path_flags_clone.Size() - 1; i++) { if (((int)path_flags_clone.Read(i) & (int)com.epl.geometry.PathFlags.enumOGCStartPolygon) != 0) { // Should // be // clockwise if (!com.epl.geometry.InternalUtils.IsClockwiseRing(multi_path_impl, i)) { multi_path_impl.ReversePath(i); } } else { // make clockwise // Should be counter-clockwise if (com.epl.geometry.InternalUtils.IsClockwiseRing(multi_path_impl, i)) { multi_path_impl.ReversePath(i); } } } // make // counter-clockwise multi_path_impl.SetPathFlagsStreamRef(path_flags_clone); } if ((import_flags & (int)com.epl.geometry.WktImportFlags.wktImportNonTrusted) == 0) { multi_path_impl.SetIsSimple(com.epl.geometry.MultiVertexGeometryImpl.GeometryXSimple.Weak, 0.0, false); } multi_path_impl.SetDirtyOGCFlags(false); return(multi_path); }
public override void WriteRange(int startElement, int count, com.epl.geometry.AttributeStreamBase _src, int srcStart, bool bForward, int stride) { if (startElement < 0 || count < 0 || srcStart < 0) { throw new System.ArgumentException(); } if (!bForward && (stride <= 0 || (count % stride != 0))) { throw new System.ArgumentException(); } com.epl.geometry.AttributeStreamOfInt8 src = (com.epl.geometry.AttributeStreamOfInt8)_src; // the input // type must // match if (src.Size() < (int)(srcStart + count)) { throw new System.ArgumentException(); } if (count == 0) { return; } if (Size() < count + startElement) { Resize(count + startElement); } if (_src == (com.epl.geometry.AttributeStreamBase) this) { _selfWriteRangeImpl(startElement, count, srcStart, bForward, stride); return; } if (bForward) { int j = startElement; int offset = srcStart; for (int i = 0; i < count; i++) { m_buffer[j] = src.m_buffer[offset]; j++; offset++; } } else { int j = startElement; int offset = srcStart + count - stride; if (stride == 1) { for (int i = 0; i < count; i++) { m_buffer[j] = src.m_buffer[offset]; j++; offset--; } } else { for (int i = 0, n = count / stride; i < n; i++) { for (int k = 0; k < stride; k++) { m_buffer[j + k] = src.m_buffer[offset + k]; } j += stride; offset -= stride; } } } }