public PolygonLink(ConvexPolygon startPoly, IndexedEdge startEdge, ConvexPolygon endPoly, IndexedEdge endEdge)
 {
     StartPoly      = startPoly;
     StartEdgeIndex = startEdge;
     EndPoly        = endPoly;
     EndEdgeIndex   = endEdge;
 }
Пример #2
0
 public PolygonLink(ConvexPolygon startPoly, IndexedEdge startEdge, ConvexPolygon endPoly, IndexedEdge endEdge)
 {
     StartPoly = startPoly;
     StartEdgeIndex = startEdge;
     EndPoly = endPoly;
     EndEdgeIndex = endEdge;
 }
        /// <summary>
        /// Attmept to add a vertex to the polygon.
        /// If the vertex would form a concave polygon then it is not added.
        /// </summary>
        /// <param name="vertexPosition">The vertex to try to add.</param>
        public void TryToAddVertex(Point vertexPosition)
        {
            IndexedEdge edgeIndex = GetClosestEdge(vertexPosition);

            _vertices.Insert(edgeIndex.End, vertexPosition);

            if (IsConcave())
            {
                _vertices.RemoveAt(edgeIndex.End);
                return;
            }

            GenerateEdges();
        }
        /// <summary>
        /// Given a 2d point in the world return the polygon's indexed edge that is closest to that point.
        /// </summary>
        /// <param name="vertexPosition">Position to compare.</param>
        /// <param name="minDistance">The distance the point is from the closest edge.</param>
        /// <returns>The closest edge</returns>
        public IndexedEdge GetClosestEdge(Point vertexPosition, out float minDistance)
        {
            minDistance = float.MaxValue;
            IndexedEdge current = new IndexedEdge();

            foreach (IndexedEdge edge in _indexedEdges)
            {
                Point start    = _vertices[edge.Start];
                Point end      = _vertices[edge.End];
                float distance = (float)LineSegment.GetDistance(start, end, vertexPosition);
                if (distance < minDistance)
                {
                    current     = edge;
                    minDistance = distance;
                }
            }
            return(current);
        }
Пример #5
0
 public PolygonEdgePair(ConvexPolygon polygon, IndexedEdge edge)
 {
     Polygon = polygon;
     Edge = edge;
 }
Пример #6
0
 /// <summary>
 /// Given a 2d point in the world return the polygon's indexed edge that is closest to that point.
 /// </summary>
 /// <param name="vertexPosition">Position to compare.</param>
 /// <param name="minDistance">The distance the point is from the closest edge.</param>
 /// <returns>The closest edge</returns>
 public IndexedEdge GetClosestEdge(Point vertexPosition, out float minDistance)
 {
     minDistance = float.MaxValue;
     IndexedEdge current = new IndexedEdge();
     foreach (IndexedEdge edge in _indexedEdges)
     {
         Point start = _vertices[edge.Start];
         Point end = _vertices[edge.End];
         float distance = (float)LineSegment.GetDistance(start, end, vertexPosition);
         if (distance < minDistance)
         {
             current = edge;
             minDistance = distance;
         }
     }
     return current;
 }