Beispiel #1
0
        //=====================================================================
        // XYPolyline(XYPolyline xyPolyline): void
        //=====================================================================
        /// <summary>
        /// Constructor. Copies the contents of the xyPolyline parameter.
        /// </summary>
        /// <param name="xyPolyline">Polyline to copy.</param>
        /// <returns>None</returns>
        public XYPolyline(XYPolyline xyPolyline)
        {
            _points = new ArrayList();

            foreach (XYPoint xypoint in xyPolyline.Points)
            {
                _points.Add(new XYPoint(xypoint.X, xypoint.Y));
            }
        }
Beispiel #2
0
        //=========================================================================================
        //CalculateLengthOfPolylineInsidePolygon(XYPolyline polyline, XYPolygon polygon) : double
        //=========================================================================================
        /// <summary>
        /// Calculates the length of polyline inside polygon. Lines segments on the edges of
        /// polygons are included with half their length.
        /// </summary>
        /// <param name="polyline">Polyline</param>
        /// <param name="polygon">Polygon</param>
        /// <returns>
        /// Length of polyline inside polygon.
        /// </returns>
        public static double CalculateLengthOfPolylineInsidePolygon(XYPolyline polyline, XYPolygon polygon)
        {
            double lengthInside         = 0;
            int    numberOfLineSegments = polyline.Points.Count - 1;

            for (int i = 0; i < numberOfLineSegments; i++)
            {
                XYLine line = new XYLine(polyline.GetLine(i));
                lengthInside += CalculateLengthOfLineInsidePolygon(line, polygon);
            }
            return(lengthInside);
        }
Beispiel #3
0
        //=====================================================================
        // CalculatePolylineToPointDistance (XYPolyline polyLine, XYPoint point) : double
        //=====================================================================
        /// <summary>
        /// Finds the shortest distance between any line segment of the polyline
        /// and the point.
        /// </summary>
        /// <param name="polyLine">PolyLine.</param>
        /// <param name="point">Point</param>
        /// <returns>
        ///	<p>Length of the shortest path between the polyline and the point.</p>
        /// </returns>
        public static double CalculatePolylineToPointDistance(XYPolyline polyLine, XYPoint point)
        {
            double dist = 0;
            int    i    = 0;

            while (i < polyLine.Points.Count - 1)
            {
                if (i == 0)
                {
                    dist = CalculateLineToPointDistance(polyLine.GetLine(0), point);
                }
                else
                {
                    dist = Math.Min(dist, CalculateLineToPointDistance(polyLine.GetLine(i), point));
                }
                i++;
            }
            return(dist);
        }
Beispiel #4
0
        //=====================================================================
        // Equals(Object obj) : Bool
        //=====================================================================
        /// <summary>
        /// Compares the object type and the coordinates of the object and the
        /// object passed as parameter.
        /// </summary>
        /// <returns>True if object type is XYPolygon and the coordinates are
        /// equal to to the coordinates of the current object. False otherwise.</returns>
        public override bool Equals(Object obj)
        {
            if (obj == null || GetType() != obj.GetType())
            {
                return(false);
            }
            XYPolyline e = (XYPolygon)obj;

            if (Points.Count != e.Points.Count)
            {
                return(false);
            }
            for (int i = 0; i < Points.Count; i++)
            {
                if (!Points[i].Equals(e.Points[i]))
                {
                    return(false);
                }
            }
            return(true);
        }
Beispiel #5
0
 //===============================================================================================
 //CheckElementSet(IElementSet elementSet): void static
 //===============================================================================================
 /// <summary>
 /// Static method that validates an object with an IElementSet interface. The method
 /// raises an Exception in case IElementSet does not describe a valid ElementSet.
 /// The checks made are:
 ///   <p>ElementType: Check</p>
 ///   <p>XYPoint:     Only one vertex in each element.</p>
 ///   <p>XYPolyline:  At least two vertices in each element.</p>
 ///   <p>             All line segments in each element has length > 0</p>
 ///   <p>XYPolygon:   At least three vertices in each element.</p>
 ///   <p>             Area of each element is larger than 0</p>
 ///   <p>             All line segments in each element has length > 0</p>
 ///   <p>             No line segments within an element crosses.</p>
 /// </summary>
 ///
 /// <param name="elementSet">Object that implement the IElementSet interface</param>
 ///
 /// <returns>
 /// The method has no return value.
 /// </returns>
 public static void CheckElementSet(IElementSet elementSet)
 {
     try
     {
         if (elementSet.ElementType == ElementType.Point)
         {
             for (int i = 0; i < elementSet.ElementCount; i++)
             {
                 try
                 {
                     if (elementSet.GetVertexCount(i) != 1)
                     {
                         throw new System.Exception("Number of vertices in point element is different from 1.");
                     }
                 }
                 catch (System.Exception e)
                 {
                     throw new System.Exception("ElementID = " + elementSet.GetElementId(i), e);
                 }
             }
         }
         else if (elementSet.ElementType == ElementType.PolyLine)
         {
             for (int i = 0; i < elementSet.ElementCount; i++)
             {
                 try
                 {
                     XYPolyline xypolyline = new XYPolyline();
                     for (int j = 0; j < elementSet.GetVertexCount(i); j++)
                     {
                         XYPoint xypoint = new XYPoint(elementSet.GetVertexXCoordinate(i, j), elementSet.GetVertexYCoordinate(i, j));
                         xypolyline.Points.Add(xypoint);
                     }
                     xypolyline.Validate();
                 }
                 catch (System.Exception e)
                 {
                     throw new System.Exception("ElementID = " + elementSet.GetElementId(i), e);
                 }
             }
         }
         else if (elementSet.ElementType == ElementType.Polygon)
         {
             for (int i = 0; i < elementSet.ElementCount; i++)
             {
                 try
                 {
                     XYPolygon xypolygon = new XYPolygon();
                     for (int j = 0; j < elementSet.GetVertexCount(i); j++)
                     {
                         XYPoint xypoint = new XYPoint(elementSet.GetVertexXCoordinate(i, j), elementSet.GetVertexYCoordinate(i, j));
                         xypolygon.Points.Add(xypoint);
                     }
                     xypolygon.Validate();
                 }
                 catch (System.Exception e)
                 {
                     throw new System.Exception("ElementID = " + elementSet.GetElementId(i), e);
                 }
             }
         }
     }
     catch (System.Exception e)
     {
         throw new System.Exception("ElementSet with ID = " + elementSet.Caption + " is invalid", e);
     }
 }