예제 #1
0
        //
        // Find the figure segment which acts as the median of this trapezoid
        //
        public void FindMedian()
        {
            if (Segment.figureSegments.Count == 0)
            {
                //Segments have not yet been recorded for the figure, wait to check for median
                SetMedianChecked(false);
                return;
            }

            foreach (Segment medianCand in Segment.figureSegments)
            {
                // The median is parallel to the bases.
                if (medianCand.IsParallelWith(this.baseSegment) && medianCand.IsParallelWith(this.oppBaseSegment))
                {
                    // The median must be between the bases and connect to the legs.
                    Point leftIntersection = leftLeg.FindIntersection(medianCand);
                    if (leftLeg.PointLiesOnAndExactlyBetweenEndpoints(leftIntersection))
                    {
                        Point rightIntersection = rightLeg.FindIntersection(medianCand);
                        if (rightLeg.PointLiesOnAndExactlyBetweenEndpoints(rightIntersection))
                        {
                            // Success, we have a median
                            // Acquire the exact figure segment (if it exists) otherwise the segment which contains the median
                            this.median = Segment.GetFigureSegment(leftIntersection, rightIntersection);

                            // If we have a median at all in the figure
                            if (this.median != null)
                            {
                                // If this is not the exact median, create the exact median.
                                Segment actualMedian = new Segment(leftIntersection, rightIntersection);
                                if (!this.median.StructurallyEquals(actualMedian))
                                {
                                    this.median = actualMedian;
                                    break;
                                }
                            }
                        }
                    }
                }
            }

            if (this.median == null)
            {
                this.SetMedianInvalid();
            }

            SetMedianChecked(true);
        }