Esempio n. 1
0
        //private PenPath travelMoveTo(Vector2f end, Matrix2f rot, Color c) {
        //    PenPath pp = new PenPath();
        //    pp.Add(new PenMove() { up = false, color = c });
        //    pp.Add(new PenMove() { destination = (rot * end) * viewBoxToPaperScale, up = true });
        //    return pp;
        //}

        IEnumerable <PenDrawingPath> outline(StripedPath stripedPath)
        {
            Matrix2f inverseRotation;
            PathData pdata;

            for (var stripeField = stripedPath.stripeField; stripeField != null; stripeField = stripeField.next)
            {
                inverseRotation = stripeField.rotation.Inverse();
                pdata           = new PathData(SvgParser.SvgPath.RotatedClone(stripedPath.path, stripeField.rotation), _svgFileData.isYAxisInverted);

                foreach (int entranceI in pdata.enterFromLeftEdgeIndices)
                {
                    Edge2f enterEdge = pdata.edgeAt(entranceI);
                    yield return(drawEdge(enterEdge + enterEdge.difference.Normalized.Perp * 5f, inverseRotation, ColorUtil.roygbivMod(entranceI)));

                    yield return(drawEdge(enterEdge, inverseRotation, pdata.isClockwiseOrdered ? ColorUtil.brown : ColorUtil.fuschia));
                }
                foreach (int exitI in pdata.exitFromLeftEdgeIndices)
                {
                    yield return(drawEdge(pdata.edgeAt(exitI) + pdata.edgeAt(exitI).difference.Normalized.Perp * 5f, inverseRotation, ColorUtil.roygbivMod(exitI)));

                    yield return(drawEdge(pdata.edgeAt(exitI), inverseRotation, pdata.isClockwiseOrdered ? new Color(.05f, .5f, 0f) : ColorUtil.pink));
                }
            }
        }
Esempio n. 2
0
        IEnumerable <PenDrawingPath> crosshatches(StripedPath stripedPath)
        {
            Matrix2f inverseRotation;
            PathData pdata;

            for (var stripeField = stripedPath.stripeField; stripeField != null; stripeField = stripeField.next)
            {
                inverseRotation = stripeField.rotation.Inverse();
                if (dbugSettings.dontRotateBackFinalPenPaths)
                {
                    inverseRotation = Matrix2f.Identity;
                }
                pdata = new PathData(SvgParser.SvgPath.RotatedClone(stripedPath.path, stripeField.rotation), _svgFileData.isYAxisInverted);

                int lastEnterEdgeIndex = -100;
                foreach (int i in pdata.enterFromLeftEdgeIndices)
                {
                    Vector2f edgeLower = pdata.areEnterLeftEdgesPosDelta ? pdata[i] : pdata.nextPoint(i);
                    Vector2f edgeUpper = pdata.areEnterLeftEdgesPosDelta ? pdata.nextPoint(i) : pdata[i];
                    Assert.IsTrue(edgeLower.y < edgeUpper.y, "something wrong at index: " + i);

                    Edge2f   leftEdge = new Edge2f(edgeLower, edgeUpper);
                    Vector2f leftIntersection;

                    // foreach y: find exit edges that span the y, find closest intersecion point
                    float y = stripeField.nextStripeYPosAbove(edgeLower.y);
                    for (; y < stripeField.nextStripeYPosAbove(edgeUpper.y); y += stripeField.interval)
                    {
                        if (!leftEdge.intersectionPointWithY(y, out leftIntersection))
                        {
                            continue;
                            //break; // want?
                        }


                        float closestXDelta = float.MaxValue;

                        for (int j = 0; j < pdata.exitFromLeftEdgeIndices.Count; ++j)
                        {
                            int    jV    = pdata.exitFromLeftEdgeIndices[j];
                            Edge2f jEdge = pdata.edgeAt(jV);

                            Vector2f intrsection;
                            if (jEdge.intersectionPointWithY(y, out intrsection))
                            {
                                float dif = intrsection.x - leftIntersection.x;
                                if (dif > 0f && dif < closestXDelta)
                                {
                                    closestXDelta = dif;
                                }
                            }
                        }

                        if (closestXDelta < float.MaxValue)
                        {
                            PenDrawingPath penPath = new PenDrawingPath();

                            penPath.addDownUpDrawMove(
                                (inverseRotation * leftIntersection) * viewBoxToPaperScale,
                                (inverseRotation * new Vector2f(leftIntersection.x + closestXDelta, y)) * viewBoxToPaperScale,
                                Color.black);
                            yield return(penPath);
                        }
                    }

                    lastEnterEdgeIndex = i;
                }
            }
        }