List<LinkedList<ControlPoint>> CreateContours(Glyph glyphData, out List<Triangle> triangles)
        {
            triangles = new List<Triangle>();
            var contours = new List<LinkedList<ControlPoint>>();

            foreach (List<ControlPoint> contour in glyphData.Contours)
            {
                if (contour.Count > 1)
                {
                    var innerPoints = new LinkedList<ControlPoint>();
                    contours.Add(innerPoints);

                    Triangle firstTriangle = null;
                    for (int i = 0, a = contour.Count - 1, b = 1; i < contour.Count; a = i, b = (b + 1) % contour.Count, i++)
                    {
                        ControlPoint point = contour[i];

                        if (point.IsOnCurve)
                        {
                            innerPoints.AddLast(point);
                        }
                        else
                        {
                            var pointBefore = contour[a];
                            if (!pointBefore.IsOnCurve)
                            {
                                pointBefore = (pointBefore + point) / 2;
                                innerPoints.AddLast(pointBefore);
                            }

                            var pointAfter = contour[b];
                            if (!pointAfter.IsOnCurve) pointAfter = (pointAfter + point) / 2;

                            var triangle = new Triangle(point, pointBefore, pointAfter);
                            if (i > 0)
                                triangle.BNode = innerPoints.Last;
                            else
                                firstTriangle = triangle;
                            triangles.Add(triangle);
                        }
                    }
                    if (firstTriangle != null && firstTriangle.BNode == null)
                        firstTriangle.BNode = contour.Last().IsOnCurve ? innerPoints.Last : innerPoints.First;
                }
            }

            return contours;
        }
Beispiel #2
0
        public bool IntersectsWith(Triangle other)
        {
            var poly1 = new List<ControlPoint>() { this.A, this.B, this.C };
            var poly2 = new List<ControlPoint>() { other.A, other.B, other.C };

            if (Contains(poly2, this.A)) return true;
            if (Contains(poly2, this.B)) return true;
            if (Contains(poly2, this.C)) return true;

            if (Contains(poly1, other.A)) return true;
            if (Contains(poly1, other.B)) return true;
            if (Contains(poly1, other.C)) return true;

            return false;
        }
Beispiel #3
0
        public Triangle[] Split(out ControlPoint newOnPoint)
        {
            var a1 = (B + A) / 2;
            var a2 = (C + A) / 2;
            var cb = (a1 + a2) / 2;

            newOnPoint = cb;

            var result = new Triangle[2];
            result[0] = new Triangle(a1, B, cb);
            result[1] = new Triangle(a2, cb, C);
            return result;
        }