Example #1
0
        GetBounds()
        {
            AssertValid();

            if (m_oEdge.IsSelfLoop)
            {
                Debug.Assert(false);
                throw new InvalidOperationException("Edge is self-loop.");
            }

            // Start with a rectangle that has the same dimensions as the edge, but
            // that starts at the origin and has an angle of zero.

            Point oVertex1Location = WpfGraphicsUtil.PointFToWpfPoint(
                m_oEdge.Vertex1.Location);

            Point oVertex2Location = WpfGraphicsUtil.PointFToWpfPoint(
                m_oEdge.Vertex2.Location);

            Double dLength = WpfGraphicsUtil.GetDistanceBetweenPoints(
                oVertex1Location, oVertex2Location);

            Double dAngleDegrees = MathUtil.RadiansToDegrees(
                WpfGraphicsUtil.GetAngleBetweenPointsRadians(
                    oVertex1Location, oVertex2Location));

            Double dHalfWidth = m_dWidth / 2.0;

            Point[] ao4BoundingPoints = new Point[4] {
                new Point(0, -dHalfWidth),
                new Point(dLength, -dHalfWidth),
                new Point(dLength, dHalfWidth),
                new Point(0, dHalfWidth),
            };

            // Rotate the rectangle so it is at the same angle as the edge.

            TransformPoints(new RotateTransform(dAngleDegrees), ao4BoundingPoints);

            // Translate the rotated rectangle to the location of the edge's first
            // endpoint.

            TransformPoints(
                new TranslateTransform(oVertex1Location.X, oVertex1Location.Y),
                ao4BoundingPoints);

            // Create a PathGeometry from the bounding points.

            return(WpfPathGeometryUtil.GetPathGeometryFromPoints(
                       ao4BoundingPoints[0],
                       ao4BoundingPoints[1],
                       ao4BoundingPoints[2],
                       ao4BoundingPoints[3]
                       ));
        }