//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)); } } }
public ArrowEnterExit fromLeftAtYWithEdgeAtIndex(float y, int index, out Vector2f intersectionPoint) { Vector2f v = pathPoints[index]; Vector2f vNext = nextPoint(index); Edge2f edge = new Edge2f(v, vNext); bool intersects = edge.intersectionPointWithY(y, out intersectionPoint); if (!intersects) { intersectionPoint = Vector2f.Zero; return(ArrowEnterExit.DoesntIntersect); } if (vNext.y > v.y == isClockwiseOrdered) { return(ArrowEnterExit.Enters); } return(ArrowEnterExit.Exits); }
private PenDrawingPath drawEdge(Edge2f e, Matrix2f rot, Color c) { return(twoPointPenPath(e.a, e.b, rot, c)); }
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; } } }