예제 #1
0
        private static List <SubsectorEdge> CreateSubsectorEdges(ConvexTraversal convexTraversal, Rotation rotation)
        {
            List <ConvexTraversalPoint> traversal = convexTraversal.Traversal;

            Debug.Assert(traversal.Count >= 3, "Traversal must yield at least a triangle in size");

            List <SubsectorEdge> subsectorEdges = new List <SubsectorEdge>();

            ConvexTraversalPoint firstTraversal = traversal.First();
            Vec2D startPoint = firstTraversal.Vertex;

            foreach (ConvexTraversalPoint traversalPoint in traversal)
            {
                BspSegment segment            = traversalPoint.Segment;
                Vec2D      endingPoint        = segment.Opposite(traversalPoint.Endpoint).Struct();
                bool       traversedFrontSide = CheckIfTraversedFrontSide(traversalPoint, rotation);

                SubsectorEdge edge = new SubsectorEdge(startPoint, endingPoint, segment.Line.Value, traversedFrontSide);
                subsectorEdges.Add(edge);

                Debug.Assert(startPoint != endingPoint, "Traversal produced the wrong endpoint indices");
                startPoint = endingPoint;
            }

            Debug.Assert(subsectorEdges.Count == traversal.Count, "Added too many subsector edges in traversal");
            return(subsectorEdges);
        }
예제 #2
0
        private static bool CheckIfTraversedFrontSide(ConvexTraversalPoint traversalPoint, Rotation rotation)
        {
            switch (rotation)
            {
            case Rotation.Left:
                return(traversalPoint.Endpoint == Endpoint.End);

            case Rotation.Right:
                return(traversalPoint.Endpoint == Endpoint.Start);

            default:
                Debug.Assert(false, "Should never be handling a non-rotational traversal");
                return(true);
            }
        }