Exemplo n.º 1
0
        private static void MoveSegmentSymmetrically(GenericPosture posture, GenericPostureImpactHorizontalSymmetry impact)
        {
            // Moves a segment so it is symmetric to another segment relatively to a vertical symmetry axis.

            GenericPostureSegment impacting = posture.Segments[impact.Impacting];
            GenericPostureSegment impacted  = posture.Segments[impact.Impacted];
            GenericPostureSegment axis      = posture.Segments[impact.Axis];

            Vector vStart = new Vector(posture.PointList[impacting.Start], posture.PointList[axis.Start]);

            posture.PointList[impacted.Start] = new PointF(posture.PointList[axis.Start].X + vStart.X, posture.PointList[impacting.Start].Y);

            Vector vEnd = new Vector(posture.PointList[impacting.End], posture.PointList[axis.End]);

            posture.PointList[impacted.End] = new PointF(posture.PointList[axis.End].X + vEnd.X, posture.PointList[impacting.End].Y);
        }
        private bool IsPointOnSegment(GenericPostureSegment segment, PointF point, IImageToViewportTransformer transformer)
        {
            PointF start = segment.Start >= 0 ? genericPosture.PointList[segment.Start] : GetUntransformedComputedPoint(segment.Start);
            PointF end   = segment.End >= 0 ? genericPosture.PointList[segment.End] : GetUntransformedComputedPoint(segment.End);

            if (start == end)
            {
                return(false);
            }

            using (GraphicsPath path = new GraphicsPath())
            {
                path.AddLine(start, end);
                return(HitTester.HitTest(path, point, segment.Width, false, transformer));
            }
        }
        private void DrawDebug(double opacity, Graphics canvas, IImageToViewportTransformer transformer, List <Point> points)
        {
            // Note: some of the labels are drawn during the normal method with an extra test there.
            PointF offset = new PointF(10, 10);

            // Points id.
            for (int i = 0; i < genericPosture.PointList.Count; i++)
            {
                string label = string.Format("P{0}", i);
                PointF p     = points[i];
                DrawDebugText(p, offset, label, canvas, opacity, transformer);
            }

            // Segments id and name.
            for (int i = 0; i < genericPosture.Segments.Count; i++)
            {
                GenericPostureSegment segment = genericPosture.Segments[i];
                if (segment.Start < 0 || segment.End < 0)
                {
                    continue;
                }

                PointF start  = points[segment.Start];
                PointF end    = points[segment.End];
                PointF middle = GeometryHelper.GetMiddlePoint(start, end);

                string label = "";
                if (!string.IsNullOrEmpty(segment.Name))
                {
                    label = string.Format("S{0} [P{1}, P{2}]: {3}", i, segment.Start, segment.End, segment.Name);
                }
                else
                {
                    label = string.Format("S{0} [P{1}, P{2}]", i, segment.Start, segment.End);
                }

                DrawDebugText(middle, offset, label, canvas, opacity, transformer);
            }
        }