/// <summary> /// Searches the nearest StatusHelperElement from the given Point /// </summary> /// <param name="point">The Point to search a StatusHelperElement for</param> /// <returns>The nearest StatusHelperElement that is positioned left of the Poin</returns> internal StatusHelperElement SearchLeft(PolygonPoint point) { // The found StatusHelperElement and the Distance Variables StatusHelperElement result = null; var dist = Double.PositiveInfinity; // Search for the right StatusHelperElement foreach (var she in this.EdgesHelpers) { // Calculate the x-Coordinate of the Intersection between // a horizontal Line from the Point to the Left and the Edge of the StatusHelperElement Double xValue = Double.NaN; if (point.Y == she.Edge.PointOne.Y) { xValue = she.Edge.PointOne.X; } else if (point.Y == she.Edge.PointTwo.Y) { xValue = she.Edge.PointTwo.X; } else { xValue = she.Edge.PointOne.X + ((point.Y - she.Edge.PointOne.Y) / (she.Edge.PointTwo.Y - she.Edge.PointOne.Y)) * (she.Edge.PointTwo.X - she.Edge.PointOne.X); } // If the xValue is smaller than or equal to the Point's x-Coordinate // (i.e. it lies on the left Side of it - allows a small Error) if (xValue <= (point.X + SweepLinePolygonTriangulator.Epsilon)) { // Calculate the Distance var sheDist = point.X - xValue; // Update, if the Distance is smaller than a previously found Result if (sheDist < dist) { dist = sheDist; result = she; } } } // Return the nearest found StatusHelperElement return(result); }
/// <summary> /// Constructor that takes both Points of the Edge /// </summary> /// <param name="one">The Startpoint</param> /// <param name="two">The Endpoint</param> internal PolygonEdge(PolygonPoint one, PolygonPoint two) { this.mPointOne = one; this.mPointTwo = two; }
/// <summary> /// Constructor taking an Edge and a Helper /// </summary> /// <param name="edge">The Edge of the StatusHelperElement</param> /// <param name="point">The Helper for the Edge of the StatusHelperElement</param> internal StatusHelperElement(PolygonEdge edge, PolygonPoint point) { this.Edge = edge; this.Helper = point; }