private static void PrintLineEnd(GCodeSketch turtle, bool drawGlpyphs, int i, Vector2 currentPos) { if (drawGlpyphs && CalibrationLine.Glyphs.TryGetValue(i, out IVertexSource vertexSource)) { var flattened = new FlattenCurves(vertexSource); var verticies = flattened.Vertices(); var firstItem = verticies.First(); var position = turtle.CurrentPosition; var scale = 0.32; if (firstItem.command != ShapePath.FlagsAndCommand.MoveTo) { turtle.MoveTo((firstItem.position * scale) + currentPos); } bool closed = false; foreach (var item in verticies) { switch (item.command) { case ShapePath.FlagsAndCommand.MoveTo: turtle.MoveTo((item.position * scale) + currentPos); break; case ShapePath.FlagsAndCommand.LineTo: turtle.LineTo((item.position * scale) + currentPos); break; case ShapePath.FlagsAndCommand.FlagClose: turtle.LineTo((firstItem.position * scale) + currentPos); closed = true; break; } } if (!closed) { turtle.LineTo((firstItem.position * scale) + currentPos); } } }
private static void PrintLineEnd(GCodeSketch turtle, bool drawGlyphs, int i, Vector2 currentPos, bool lift = false) { var originalSpeed = turtle.Speed; turtle.Speed = Math.Min(700, turtle.Speed); if (drawGlyphs && CalibrationLine.Glyphs.TryGetValue(i, out IVertexSource vertexSource)) { turtle.WriteRaw("; LineEnd Marker"); var flattened = new FlattenCurves(vertexSource); var verticies = flattened.Vertices(); var firstItem = verticies.First(); var position = turtle.CurrentPosition; var scale = 0.3; if (firstItem.command != ShapePath.FlagsAndCommand.MoveTo) { if (lift) { turtle.PenUp(); } turtle.MoveTo((firstItem.position * scale) + currentPos); } bool closed = false; foreach (var item in verticies) { switch (item.command) { case ShapePath.FlagsAndCommand.MoveTo: if (lift) { turtle.PenUp(); } turtle.MoveTo((item.position * scale) + currentPos); if (lift) { turtle.PenDown(); } break; case ShapePath.FlagsAndCommand.LineTo: turtle.LineTo((item.position * scale) + currentPos); break; case ShapePath.FlagsAndCommand.FlagClose: turtle.LineTo((firstItem.position * scale) + currentPos); closed = true; break; } } bool atStartingPosition = position.Equals(turtle.CurrentPosition, .1); if (!closed && !atStartingPosition) { turtle.LineTo((firstItem.position * scale) + currentPos); atStartingPosition = position.Equals(turtle.CurrentPosition, .1); } // Restore original speed turtle.Speed = originalSpeed; if (!atStartingPosition) { // Return to original position turtle.PenUp(); turtle.MoveTo(currentPos); turtle.PenDown(); } } }