예제 #1
0
        /// <summary>
        /// Creates a wedge from the inbound and outbound segments.
        /// </summary>
        /// <param name="inbound">The inbound segment, which means its ending
        /// point is shared with the outbound starting vertex.</param>
        /// <param name="outbound">The outbound segment, which means its
        /// starting point matches the inbounds ending point.</param>
        public JunctionWedge(BspSegment inbound, BspSegment outbound)
        {
            Debug.Assert(inbound.EndIndex == outbound.StartIndex, "The inbound and outbound do not meet at a shared vertex");

            Inbound  = inbound;
            Outbound = outbound;
            Obtuse   = !inbound.OnRight(outbound);
        }
예제 #2
0
 protected void HandleSegmentOnSide(BspSegment splitter, BspSegment segmentToSplit)
 {
     if (splitter.OnRight(segmentToSplit))
     {
         States.RightSegments.Add(segmentToSplit);
     }
     else
     {
         States.LeftSegments.Add(segmentToSplit);
     }
 }
예제 #3
0
 protected void HandleParallelSegment(BspSegment splitter, BspSegment segment)
 {
     if (splitter.Collinear(segment))
     {
         HandleCollinearSegment(splitter, segment);
     }
     else if (splitter.OnRight(segment.Start))
     {
         States.RightSegments.Add(segment);
     }
     else
     {
         States.LeftSegments.Add(segment);
     }
 }
예제 #4
0
        /// <summary>
        /// Calculates a 'score', which is an arbitrary number that tells us
        /// how close the angle is for the wedge provided.
        /// </summary>
        /// <remarks>
        /// For example, if there were 3 segs A, B, and C, where we were
        /// trying to see whether AB has a smaller wedge than AC, if the
        /// score of AB is less than that of AC, it has a smaller angle.
        /// </remarks>
        /// <param name="inbound">The inbound segment.</param>
        /// <param name="outbound">The outbound segment.</param>
        /// <returns>A score that is to be used only for ordering reasons
        /// (where a lower score means it's a tighter angle than a larger
        /// score).</returns>
        private static double CalculateAngleScore(BspSegment inbound, BspSegment outbound)
        {
            Vec2D endToOriginPoint   = (inbound.Start - inbound.End).Struct();
            Vec2D startToOriginPoint = (outbound.End - outbound.Start).Struct();

            double dot      = startToOriginPoint.Dot(endToOriginPoint);
            double length   = startToOriginPoint.Length() * endToOriginPoint.Length();
            double cosTheta = dot / length;

            double score = cosTheta;

            if (inbound.OnRight(outbound.End))
            {
                score = -score;
            }
            else
            {
                score += 2.0;
            }

            return(score);
        }