/// <exception cref="java.io.ObjectStreamException"/> public virtual void SetGeometryByValue(com.epl.geometry.Point point) { try { attribs = null; if (point == null) { descriptionBitMask = 1; } com.epl.geometry.VertexDescription vd = point.GetDescription(); descriptionBitMask = vd.m_semanticsBitArray; if (point.IsEmpty()) { return; } attribs = new double[vd.GetTotalComponentCount()]; attribs[0] = point.GetX(); attribs[1] = point.GetY(); int index = 2; for (int i = 1, n = vd.GetAttributeCount(); i < n; i++) { int semantics = vd.GetSemantics(i); int comps = com.epl.geometry.VertexDescription.GetComponentCount(semantics); for (int ord = 0; ord < comps; ord++) { attribs[index++] = point.GetAttributeAsDbl(semantics, ord); } } } catch (System.Exception) { throw new System.IO.InvalidDataException("Cannot serialize this geometry"); } }
//This is a writeReplace class for Lin /// <exception cref="java.io.ObjectStreamException"/> public virtual object ReadResolve() { com.epl.geometry.Line ln = null; if (descriptionBitMask == -1) { return(null); } try { com.epl.geometry.VertexDescription vd = com.epl.geometry.VertexDescriptionDesignerImpl.GetVertexDescription(descriptionBitMask); ln = new com.epl.geometry.Line(vd); if (attribs != null) { ln.SetStartXY(attribs[0], attribs[1]); ln.SetEndXY(attribs[2], attribs[3]); int index = 4; for (int i = 1, n = vd.GetAttributeCount(); i < n; i++) { int semantics = vd.GetSemantics(i); int comps = com.epl.geometry.VertexDescription.GetComponentCount(semantics); for (int ord = 0; ord < comps; ord++) { ln.SetStartAttribute(semantics, ord, attribs[index++]); ln.SetEndAttribute(semantics, ord, attribs[index++]); } } } } catch (System.Exception) { throw new System.IO.InvalidDataException("Cannot read geometry from stream"); } return(ln); }
/// <summary>Merges this envelope with the extent of the given envelope.</summary> /// <remarks> /// Merges this envelope with the extent of the given envelope. If this /// envelope is empty, the coordinates of the given envelope /// are assigned. If the given envelope is empty, this envelope is unchanged. /// </remarks> /// <param name="other">The envelope to merge.</param> public virtual void Merge(com.epl.geometry.Envelope other) { _touch(); if (other.IsEmpty()) { return; } com.epl.geometry.VertexDescription otherVD = other.m_description; if (otherVD != m_description) { MergeVertexDescription(otherVD); } m_envelope.Merge(other.m_envelope); for (int iattrib = 1, nattrib = otherVD.GetAttributeCount(); iattrib < nattrib; iattrib++) { int semantics = otherVD.GetSemantics(iattrib); int ncomps = com.epl.geometry.VertexDescription.GetComponentCount(semantics); for (int iord = 0; iord < ncomps; iord++) { com.epl.geometry.Envelope1D intervalOther = other.QueryInterval(semantics, iord); com.epl.geometry.Envelope1D interval = QueryInterval(semantics, iord); interval.Merge(intervalOther); SetInterval(semantics, iord, interval); } } }
/// <exception cref="java.io.ObjectStreamException"/> public virtual void SetGeometryByValue(com.epl.geometry.Line ln) { try { attribs = null; if (ln == null) { descriptionBitMask = -1; } com.epl.geometry.VertexDescription vd = ln.GetDescription(); descriptionBitMask = vd.m_semanticsBitArray; attribs = new double[vd.GetTotalComponentCount() * 2]; attribs[0] = ln.GetStartX(); attribs[1] = ln.GetStartY(); attribs[2] = ln.GetEndX(); attribs[3] = ln.GetEndY(); int index = 4; for (int i = 1, n = vd.GetAttributeCount(); i < n; i++) { int semantics = vd.GetSemantics(i); int comps = com.epl.geometry.VertexDescription.GetComponentCount(semantics); for (int ord = 0; ord < comps; ord++) { attribs[index++] = ln.GetStartAttributeAsDbl(semantics, ord); attribs[index++] = ln.GetEndAttributeAsDbl(semantics, ord); } } } catch (System.Exception) { throw new System.IO.InvalidDataException("Cannot serialize this geometry"); } }
/// <summary>Merges this envelope with the point.</summary> /// <remarks> /// Merges this envelope with the point. The boundary of the envelope is /// increased to include the point. If the envelope is empty, the coordinates /// of the point to merge are assigned. If the point is empty, the original /// envelope is unchanged. /// </remarks> /// <param name="point">The point to be merged.</param> public virtual void Merge(com.epl.geometry.Point point) { _touch(); if (point.IsEmptyImpl()) { return; } com.epl.geometry.VertexDescription pointVD = point.m_description; if (m_description != pointVD) { MergeVertexDescription(pointVD); } if (IsEmpty()) { _setFromPoint(point); return; } m_envelope.Merge(point.GetXY()); for (int iattrib = 1, nattrib = pointVD.GetAttributeCount(); iattrib < nattrib; iattrib++) { int semantics = pointVD._getSemanticsImpl(iattrib); int ncomps = com.epl.geometry.VertexDescription.GetComponentCount(semantics); for (int iord = 0; iord < ncomps; iord++) { double v = point.GetAttributeAsDbl(semantics, iord); com.epl.geometry.Envelope1D interval = QueryInterval(semantics, iord); interval.Merge(v); SetInterval(semantics, iord, interval); } } }
public override void SetPointByVal(int index, com.epl.geometry.Point src) { if (index < 0 || index >= m_pointCount) { throw new com.epl.geometry.GeometryException("index out of bounds"); } com.epl.geometry.Point point = src; if (src.IsEmpty()) { // can not assign an empty point to a multipoint // vertex throw new System.ArgumentException(); } _verifyAllStreams(); // verify all allocated streams are of necessary // size. com.epl.geometry.VertexDescription vdin = point.GetDescription(); for (int attributeIndex = 0; attributeIndex < vdin.GetAttributeCount(); attributeIndex++) { int semantics = vdin._getSemanticsImpl(attributeIndex); int ncomp = com.epl.geometry.VertexDescription.GetComponentCount(semantics); for (int icomp = 0; icomp < ncomp; icomp++) { double v = point.GetAttributeAsDbl(semantics, icomp); SetAttribute(semantics, index, icomp, v); } } }
public Point(com.epl.geometry.VertexDescription vd) { if (vd == null) { throw new System.ArgumentException(); } m_description = vd; }
public Envelope(com.epl.geometry.VertexDescription vd) { if (vd == null) { throw new System.ArgumentException(); } m_description = vd; m_envelope.SetEmpty(); }
/// <summary>Assigns the new VertexDescription by adding or dropping attributes.</summary> /// <remarks> /// Assigns the new VertexDescription by adding or dropping attributes. The /// Geometry will have the src description as a result. /// </remarks> public virtual void AssignVertexDescription(com.epl.geometry.VertexDescription src) { _touch(); if (src == m_description) { return; } _assignVertexDescriptionImpl(src); }
public Envelope(com.epl.geometry.VertexDescription vd, com.epl.geometry.Envelope2D env2D) { if (vd == null) { throw new System.ArgumentException(); } m_description = vd; m_envelope.SetCoords(env2D); m_envelope.Normalize(); }
internal static int[] MapAttributes(com.epl.geometry.VertexDescription src, com.epl.geometry.VertexDescription dest) { int[] srcToDst = new int[src.GetAttributeCount()]; java.util.Arrays.Fill(srcToDst, -1); for (int i = 0, nsrc = src.GetAttributeCount(); i < nsrc; i++) { srcToDst[i] = dest.GetAttributeIndex(src.GetSemantics(i)); } return(srcToDst); }
public MultiPointImpl(com.epl.geometry.VertexDescription description) : base() { if (description == null) { throw new System.ArgumentException(); } m_description = description; m_pointCount = 0; }
/// <summary>Drops an attribute from the Geometry.</summary> /// <remarks> /// Drops an attribute from the Geometry. Dropping the attribute is /// equivalent to setting the attribute to the default value for each vertex, /// However, it is faster and the result Geometry has smaller memory /// footprint and smaller size when persisted. /// </remarks> public virtual void DropAttribute(int semantics) { _touch(); if (!m_description.HasAttribute(semantics)) { return; } com.epl.geometry.VertexDescription newvd = com.epl.geometry.VertexDescriptionDesignerImpl.RemoveSemanticsFromVertexDescription(m_description, semantics); _assignVertexDescriptionImpl(newvd); }
/// <summary>Adds a new attribute to the Geometry.</summary> /// <param name="semantics"/> public virtual void AddAttribute(int semantics) { _touch(); if (m_description.HasAttribute(semantics)) { return; } com.epl.geometry.VertexDescription newvd = com.epl.geometry.VertexDescriptionDesignerImpl.GetMergedVertexDescription(m_description, semantics); _assignVertexDescriptionImpl(newvd); }
protected internal override void _assignVertexDescriptionImpl(com.epl.geometry.VertexDescription newDescription) { if (m_attributes == null) { m_description = newDescription; return; } if (newDescription.GetTotalComponentCount() > 2) { int[] mapping = com.epl.geometry.VertexDescriptionDesignerImpl.MapAttributes(newDescription, m_description); double[] newAttributes = new double[(newDescription.GetTotalComponentCount() - 2) * 2]; int old_offset0 = _getEndPointOffset(m_description, 0); int old_offset1 = _getEndPointOffset(m_description, 1); int new_offset0 = _getEndPointOffset(newDescription, 0); int new_offset1 = _getEndPointOffset(newDescription, 1); int j = 0; for (int i = 1, n = newDescription.GetAttributeCount(); i < n; i++) { int semantics = newDescription.GetSemantics(i); int nords = com.epl.geometry.VertexDescription.GetComponentCount(semantics); if (mapping[i] == -1) { double d = com.epl.geometry.VertexDescription.GetDefaultValue(semantics); for (int ord = 0; ord < nords; ord++) { newAttributes[new_offset0 + j] = d; newAttributes[new_offset1 + j] = d; j++; } } else { int m = mapping[i]; int offset = m_description._getPointAttributeOffset(m) - 2; for (int ord = 0; ord < nords; ord++) { newAttributes[new_offset0 + j] = m_attributes[old_offset0 + offset]; newAttributes[new_offset1 + j] = m_attributes[old_offset1 + offset]; j++; offset++; } } } m_attributes = newAttributes; } else { m_attributes = null; } m_description = newDescription; }
public static com.epl.geometry.Geometry CreateGeometry(int gt, com.epl.geometry.VertexDescription vdIn) { com.epl.geometry.VertexDescription vd = vdIn; if (vd == null) { vd = com.epl.geometry.VertexDescriptionDesignerImpl.GetDefaultDescriptor2D(); } switch (gt) { case com.epl.geometry.Geometry.GeometryType.Point: { return(new com.epl.geometry.Point(vd)); } case com.epl.geometry.Geometry.GeometryType.Line: { return(new com.epl.geometry.Line(vd)); } case com.epl.geometry.Geometry.GeometryType.Envelope: { // case enum_value2(Geometry, GeometryType, enumBezier): // break; // case enum_value2(Geometry, GeometryType, enumEllipticArc): // break; return(new com.epl.geometry.Envelope(vd)); } case com.epl.geometry.Geometry.GeometryType.MultiPoint: { return(new com.epl.geometry.MultiPoint(vd)); } case com.epl.geometry.Geometry.GeometryType.Polyline: { return(new com.epl.geometry.Polyline(vd)); } case com.epl.geometry.Geometry.GeometryType.Polygon: { return(new com.epl.geometry.Polygon(vd)); } default: { throw new com.epl.geometry.GeometryException("invalid argument."); } } }
internal virtual void _setFromPoint(com.epl.geometry.Point centerPoint) { m_envelope.SetCoords(centerPoint.m_attributes[0], centerPoint.m_attributes[1]); com.epl.geometry.VertexDescription pointVD = centerPoint.m_description; for (int iattrib = 1, nattrib = pointVD.GetAttributeCount(); iattrib < nattrib; iattrib++) { int semantics = pointVD._getSemanticsImpl(iattrib); int ncomps = com.epl.geometry.VertexDescription.GetComponentCount(semantics); for (int iord = 0; iord < ncomps; iord++) { double v = centerPoint.GetAttributeAsDbl(semantics, iord); SetInterval(semantics, iord, v, v); } } }
/// <summary> /// Merges the new VertexDescription by adding missing attributes from the /// src. /// </summary> /// <remarks> /// Merges the new VertexDescription by adding missing attributes from the /// src. The Geometry will have a union of the current and the src /// descriptions. /// </remarks> public virtual void MergeVertexDescription(com.epl.geometry.VertexDescription src) { _touch(); if (src == m_description) { return; } // check if we need to do anything (if the src has same attributes) com.epl.geometry.VertexDescription newdescription = com.epl.geometry.VertexDescriptionDesignerImpl.GetMergedVertexDescription(m_description, src); if (newdescription == m_description) { return; } _assignVertexDescriptionImpl(newdescription); }
private void _set(int endPoint, com.epl.geometry.Point src) { _touch(); com.epl.geometry.Point point = src; if (src.IsEmptyImpl()) { // can not assign an empty point throw new com.epl.geometry.GeometryException("empty_Geometry"); } com.epl.geometry.VertexDescription vdin = point.GetDescription(); for (int attributeIndex = 0, nattrib = vdin.GetAttributeCount(); attributeIndex < nattrib; attributeIndex++) { int semantics = vdin._getSemanticsImpl(attributeIndex); int ncomp = com.epl.geometry.VertexDescription.GetComponentCount(semantics); for (int icomp = 0; icomp < ncomp; icomp++) { double v = point.GetAttributeAsDbl(semantics, icomp); _setAttribute(endPoint, semantics, icomp, v); } } }
public com.epl.geometry.VertexDescription FindOrAdd(int bitSet) { if (bitSet == 1) { return(m_vd2D); } if (bitSet == 3) { return(m_vd3D); } lock (this) { com.epl.geometry.VertexDescription vd = null; if (!m_map.TryGetValue(bitSet, out vd)) { vd = new com.epl.geometry.VertexDescription(bitSet); m_map[bitSet] = vd; } return(vd); } }
/// <exception cref="java.io.ObjectStreamException"/> public virtual void SetGeometryByValue(com.epl.geometry.Envelope env) { try { attribs = null; if (env == null) { descriptionBitMask = -1; } com.epl.geometry.VertexDescription vd = env.GetDescription(); descriptionBitMask = vd.m_semanticsBitArray; if (env.IsEmpty()) { return; } attribs = new double[vd.GetTotalComponentCount() * 2]; attribs[0] = env.GetXMin(); attribs[1] = env.GetYMin(); attribs[2] = env.GetXMax(); attribs[3] = env.GetYMax(); int index = 4; for (int i = 1, n = vd.GetAttributeCount(); i < n; i++) { int semantics = vd.GetSemantics(i); int comps = com.epl.geometry.VertexDescription.GetComponentCount(semantics); for (int ord = 0; ord < comps; ord++) { com.epl.geometry.Envelope1D e = env.QueryInterval(semantics, ord); attribs[index++] = e.vmin; attribs[index++] = e.vmax; } } } catch (System.Exception) { throw new System.IO.InvalidDataException("Cannot serialize this geometry"); } }
protected internal override void _assignVertexDescriptionImpl(com.epl.geometry.VertexDescription newDescription) { com.epl.geometry.AttributeStreamBase[] newAttributes = null; if (m_vertexAttributes != null) { int[] mapping = com.epl.geometry.VertexDescriptionDesignerImpl.MapAttributes(newDescription, m_description); newAttributes = new com.epl.geometry.AttributeStreamBase[newDescription.GetAttributeCount()]; for (int i = 0, n = newDescription.GetAttributeCount(); i < n; i++) { if (mapping[i] != -1) { int m = mapping[i]; newAttributes[i] = m_vertexAttributes[m]; } } } //if there are no streams we do not create them m_description = newDescription; m_vertexAttributes = newAttributes; // late assignment to try to stay m_reservedPointCount = -1; // we need to recreate the new attribute then NotifyModified(com.epl.geometry.MultiVertexGeometryImpl.DirtyFlags.DirtyAll); }
protected internal abstract void _assignVertexDescriptionImpl(com.epl.geometry.VertexDescription src);
internal static com.epl.geometry.VertexDescription GetMergedVertexDescription(com.epl.geometry.VertexDescription descr, int semantics) { int mask = descr.m_semanticsBitArray | (1 << semantics); if ((mask & descr.m_semanticsBitArray) == mask) { return(descr); } return(GetVertexDescription(mask)); }
internal static com.epl.geometry.VertexDescription RemoveSemanticsFromVertexDescription(com.epl.geometry.VertexDescription descr, int semanticsToRemove) { int mask = (descr.m_semanticsBitArray | (1 << (int)semanticsToRemove)) - (1 << (int)semanticsToRemove); if (mask == descr.m_semanticsBitArray) { return(descr); } return(GetVertexDescription(mask)); }
internal static com.epl.geometry.VertexDescription GetMergedVertexDescription(com.epl.geometry.VertexDescription descr1, com.epl.geometry.VertexDescription descr2) { int mask = descr1.m_semanticsBitArray | descr2.m_semanticsBitArray; if ((mask & descr1.m_semanticsBitArray) == mask) { return(descr1); } else { if ((mask & descr2.m_semanticsBitArray) == mask) { return(descr2); } } return(GetVertexDescription(mask)); }
internal Geometry() { m_description = null; m_touchFlag = 0; }
/// <summary>Static method to construct the convex hull of a Multi_vertex_geometry.</summary> /// <remarks> /// Static method to construct the convex hull of a Multi_vertex_geometry. /// Returns a Geometry. /// \param mvg The geometry used to create the convex hull. /// </remarks> internal static com.epl.geometry.Geometry Construct(com.epl.geometry.MultiVertexGeometry mvg) { if (mvg.IsEmpty()) { return(new com.epl.geometry.Polygon(mvg.GetDescription())); } com.epl.geometry.MultiVertexGeometryImpl mvg_impl = (com.epl.geometry.MultiVertexGeometryImpl)mvg._getImpl(); int N = mvg_impl.GetPointCount(); if (N <= 2) { if (N == 1 || mvg_impl.GetXY(0).Equals(mvg_impl.GetXY(1))) { com.epl.geometry.Point point = new com.epl.geometry.Point(mvg_impl.GetDescription()); mvg_impl.GetPointByVal(0, point); return(point); } else { com.epl.geometry.Point pt = new com.epl.geometry.Point(); com.epl.geometry.Polyline polyline = new com.epl.geometry.Polyline(mvg_impl.GetDescription()); mvg_impl.GetPointByVal(0, pt); polyline.StartPath(pt); mvg_impl.GetPointByVal(1, pt); polyline.LineTo(pt); return(polyline); } } com.epl.geometry.AttributeStreamOfDbl stream = (com.epl.geometry.AttributeStreamOfDbl)mvg_impl.GetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.POSITION); com.epl.geometry.ConvexHull convex_hull = new com.epl.geometry.ConvexHull(stream, N); int t0 = 0; int tm = 1; com.epl.geometry.Point2D pt_0 = new com.epl.geometry.Point2D(); com.epl.geometry.Point2D pt_m = new com.epl.geometry.Point2D(); com.epl.geometry.Point2D pt_p = new com.epl.geometry.Point2D(); stream.Read(t0 << 1, pt_0); while (true) { if (tm >= N) { break; } stream.Read(tm << 1, pt_m); if (!pt_m.IsEqual(pt_0, com.epl.geometry.NumberUtils.DoubleEps())) { break; } tm++; } // We don't want to close the gap between t0 and tm. convex_hull.m_tree_hull.AddElement(t0, -1); if (tm < N) { convex_hull.m_tree_hull.AddBiggestElement(tm, -1); for (int tp = tm + 1; tp < mvg_impl.GetPointCount(); tp++) { // Dynamically insert into the current convex hull stream.Read(tp << 1, pt_p); int p = convex_hull.TreeHull_(pt_p); if (p != -1) { convex_hull.m_tree_hull.SetElement(p, tp); } } } // reset the place holder to the point index. // Extracts the convex hull from the tree. Reading the tree in order from first to last is the resulting convex hull. com.epl.geometry.VertexDescription description = mvg_impl.GetDescription(); bool b_has_attributes = (description.GetAttributeCount() > 1); int point_count = convex_hull.m_tree_hull.Size(-1); com.epl.geometry.Geometry hull; if (point_count >= 2) { if (point_count >= 3) { hull = new com.epl.geometry.Polygon(description); } else { hull = new com.epl.geometry.Polyline(description); } com.epl.geometry.MultiPathImpl hull_impl = (com.epl.geometry.MultiPathImpl)hull._getImpl(); hull_impl.AddPath((com.epl.geometry.Point2D[])null, 0, true); com.epl.geometry.Point point = null; if (b_has_attributes) { point = new com.epl.geometry.Point(); } for (int i = convex_hull.m_tree_hull.GetFirst(-1); i != -1; i = convex_hull.m_tree_hull.GetNext(i)) { if (b_has_attributes) { mvg_impl.GetPointByVal(convex_hull.m_tree_hull.GetElement(i), point); hull_impl.InsertPoint(0, -1, point); } else { stream.Read(convex_hull.m_tree_hull.GetElement(i) << 1, pt_p); hull_impl.InsertPoint(0, -1, pt_p); } } } else { System.Diagnostics.Debug.Assert((point_count == 1)); if (b_has_attributes) { com.epl.geometry.Point point = new com.epl.geometry.Point(description); mvg_impl.GetPointByVal(convex_hull.m_tree_hull.GetElement(convex_hull.m_tree_hull.GetFirst(-1)), point); hull = point; } else { stream.Read(convex_hull.m_tree_hull.GetElement(convex_hull.m_tree_hull.GetFirst(-1)) << 1, pt_p); hull = new com.epl.geometry.Point(pt_p); } } return(hull); }
public override void AssignVertexDescription(com.epl.geometry.VertexDescription src) { m_impl.AssignVertexDescription(src); }
public override void MergeVertexDescription(com.epl.geometry.VertexDescription src) { m_impl.MergeVertexDescription(src); }