public ShapePath GetShapePath(Vector3[] path = null, Quaternion[] rots = null) { if (path == null) { path = GetPathPoints(); } if (rots == null) { rots = GetPathRots(path); } ShapePath sp = new ShapePath(); sp.begin(); sp.moveTo(path[0], rots[0]); for (int n = 1; n < path.Length-1; n++) { Vector3 pos = Vector3.Lerp(path[n], path[n + 1], 0.5f); sp.curveTo(path[n], pos, rots[n]); } Vector3 posC = Vector3.Lerp(path[path.Length - 2], path[path.Length - 1], 0.5f); Vector3 posEnd = path[path.Length - 1]; sp.curveTo(posC, posEnd, rots[path.Length - 1]); sp.end(); return sp; }
public ShapePath.FlagsAndCommand vertex(out double x, out double y) { x = 0; y = 0; if (ShapePath.is_stop(m_NextPathCommand)) { return(ShapePath.FlagsAndCommand.CommandStop); } if ((m_CurrentFlatenAngle < endAngle - flatenDeltaAngle / 4) != ((int)EDirection.CounterClockWise == 1)) { x = originX + Math.Cos(endAngle) * radiusX; y = originY + Math.Sin(endAngle) * radiusY; m_NextPathCommand = ShapePath.FlagsAndCommand.CommandStop; return(ShapePath.FlagsAndCommand.CommandLineTo); } x = originX + Math.Cos(m_CurrentFlatenAngle) * radiusX; y = originY + Math.Sin(m_CurrentFlatenAngle) * radiusY; m_CurrentFlatenAngle += flatenDeltaAngle; ShapePath.FlagsAndCommand CurrentPathCommand = m_NextPathCommand; m_NextPathCommand = ShapePath.FlagsAndCommand.CommandLineTo; return(CurrentPathCommand); }
public void CorrectlySetsColorThicknessAndRectangle() { img.Draw(color, thickness, rectangle); Assert.NotEmpty(img.ProcessorApplications); DrawPathProcessor <Color> processor = Assert.IsType <DrawPathProcessor <Color> >(img.ProcessorApplications[0].processor); Assert.Equal(GraphicsOptions.Default, processor.Options); ShapePath shapepath = Assert.IsType <ShapePath>(processor.Path); Assert.NotEmpty(shapepath.Paths); SixLabors.Shapes.Rectangle rect = Assert.IsType <SixLabors.Shapes.Rectangle>(shapepath.Paths[0].AsShape()); Assert.Equal(rect.Location.X, rectangle.X); Assert.Equal(rect.Location.Y, rectangle.Y); Assert.Equal(rect.Size.Width, rectangle.Width); Assert.Equal(rect.Size.Height, rectangle.Height); Pen <Color> pen = Assert.IsType <Pen <Color> >(processor.Pen); Assert.Equal(thickness, pen.Width); SolidBrush <Color> brush = Assert.IsType <SolidBrush <Color> >(pen.Brush); Assert.Equal(color, brush.Color); }
public override ShapePath.FlagsAndCommand vertex(out double x, out double y) { x = 0; y = 0; ShapePath.FlagsAndCommand cmd = ShapePath.FlagsAndCommand.CommandStop; switch (m_idx) { case 0: case 1: case 2: cmd = m_stroke.vertex(out x, out y); break; case 3: case 4: case 5: case 6: cmd = m_ellipse.vertex(out x, out y); break; } if (!ShapePath.is_stop(cmd)) { ParentToChildTransform.transform(ref x, ref y); } return(cmd); }
public IEnumerable <VertexData> Vertices() { currentProcessingArc.init(bounds.Left + leftBottomRadius.x, bounds.Bottom + leftBottomRadius.y, leftBottomRadius.x, leftBottomRadius.y, Math.PI, Math.PI + Math.PI * 0.5); foreach (VertexData vertexData in currentProcessingArc.Vertices()) { if (ShapePath.is_stop(vertexData.command)) { break; } yield return(vertexData); } currentProcessingArc.init(bounds.Right - rightBottomRadius.x, bounds.Bottom + rightBottomRadius.y, rightBottomRadius.x, rightBottomRadius.y, Math.PI + Math.PI * 0.5, 0.0); foreach (VertexData vertexData in currentProcessingArc.Vertices()) { if (ShapePath.is_move_to(vertexData.command)) { // skip the initial moveto continue; } if (ShapePath.is_stop(vertexData.command)) { break; } yield return(vertexData); } currentProcessingArc.init(bounds.Right - rightTopRadius.x, bounds.Top - rightTopRadius.y, rightTopRadius.x, rightTopRadius.y, 0.0, Math.PI * 0.5); foreach (VertexData vertexData in currentProcessingArc.Vertices()) { if (ShapePath.is_move_to(vertexData.command)) { // skip the initial moveto continue; } if (ShapePath.is_stop(vertexData.command)) { break; } yield return(vertexData); } currentProcessingArc.init(bounds.Left + leftTopRadius.x, bounds.Top - leftTopRadius.y, leftTopRadius.x, leftTopRadius.y, Math.PI * 0.5, Math.PI); foreach (VertexData vertexData in currentProcessingArc.Vertices()) { if (ShapePath.is_move_to(vertexData.command)) { // skip the initial moveto continue; } if (ShapePath.is_stop(vertexData.command)) { break; } yield return(vertexData); } yield return(new VertexData(ShapePath.FlagsAndCommand.CommandEndPoly | ShapePath.FlagsAndCommand.FlagClose | ShapePath.FlagsAndCommand.FlagCCW, new Vector2())); yield return(new VertexData(ShapePath.FlagsAndCommand.CommandStop, new Vector2())); }
public void CorrectlySetsBrushThicknessRectangleAndOptions() { img.Draw(brush, thickness, rectangle, noneDefault); Assert.NotEmpty(img.ProcessorApplications); DrawPathProcessor <Color> processor = Assert.IsType <DrawPathProcessor <Color> >(img.ProcessorApplications[0].processor); Assert.Equal(noneDefault, processor.Options); ShapePath shapepath = Assert.IsType <ShapePath>(processor.Path); Assert.NotEmpty(shapepath.Paths); SixLabors.Shapes.Rectangle rect = Assert.IsType <SixLabors.Shapes.Rectangle>(shapepath.Paths[0].AsShape()); Assert.Equal(rect.Location.X, rectangle.X); Assert.Equal(rect.Location.Y, rectangle.Y); Assert.Equal(rect.Size.Width, rectangle.Width); Assert.Equal(rect.Size.Height, rectangle.Height); Pen <Color> pen = Assert.IsType <Pen <Color> >(processor.Pen); Assert.Equal(brush, pen.Brush); Assert.Equal(thickness, pen.Width); }
public void end_poly(ShapePath.FlagsAndCommand flags) { if (ShapePath.is_vertex(vertices.last_command())) { vertices.AddVertex(0.0, 0.0, ShapePath.FlagsAndCommand.CommandEndPoly | flags); } }
public void invert_polygon(int start) { // Skip all non-vertices at the beginning while (start < vertexDataManager.total_vertices() && !ShapePath.is_vertex(vertexDataManager.command(start))) { ++start; } // Skip all insignificant move_to while (start + 1 < vertexDataManager.total_vertices() && ShapePath.is_move_to(vertexDataManager.command(start)) && ShapePath.is_move_to(vertexDataManager.command(start + 1))) { ++start; } // Find the last vertex int end = start + 1; while (end < vertexDataManager.total_vertices() && !ShapePath.is_next_poly(vertexDataManager.command(end))) { ++end; } invert_polygon(start, end); }
public void end_poly(ShapePath.FlagsAndCommand flags) { if (ShapePath.is_vertex(vertexDataManager.last_command())) { vertexDataManager.AddVertex(0.0, 0.0, ShapePath.FlagsAndCommand.EndPoly | flags); } }
override public IEnumerable <VertexData> Vertices() { for (int i = 0; i < SourcPaths.Count; i++) { IVertexSource sourcePath = SourcPaths[i]; bool firstMove = true; foreach (VertexData vertexData in sourcePath.Vertices()) { // skip the initial command if it is not the first path and is a moveto. if (i > 0 && firstMove && ShapePath.is_move_to(vertexData.command)) { continue; } // when we hit a stop move on to the next path if (ShapePath.is_stop(vertexData.command)) { break; } yield return(vertexData); } } // and send the actual stop yield return(new VertexData(ShapePath.FlagsAndCommand.CommandStop, new Vector2())); }
void Update() { if (Application.isEditor) { path = pointList.GetPathPoints(); sp = pointList.GetShapePath(); DrawLinePoints(sp); } if (Application.isPlaying) { if (isPlayAnim && smooth) { target.transform.position = Vector3.Lerp(target.transform.position, targetPos, Time.deltaTime * damping); float dist = Vector3.Distance(target.transform.position, targetPos); //if(dist < 0.01f){ if (dist < 0.1f && progress == 1.0f) { isPlayAnim = false; } } } }
public ClosedLoopGlyphData(VertexStorage source) { storage = new VertexStorage(); var vertexData = source.Vertices().Where(v => v.command != ShapePath.FlagsAndCommand.FlagNone).ToArray(); var previous = default(VertexData); for (var i = 0; i < vertexData.Length; i++) { var current = vertexData[i]; // All MoveTo operations should be preceded by ClosePolygon if (i > 0 && current.IsMoveTo && ShapePath.is_vertex(previous.command)) { storage.ClosePolygon(); } // Add original VertexData storage.Add(current.position.X, current.position.Y, current.command); // Hold prior item previous = current; } // Ensure closed storage.ClosePolygon(); }
public void AddVertex(double x, double y, ShapePath.FlagsAndCommand cmd) { m_status = StrokeMath.status_e.initial; if (ShapePath.is_move_to(cmd)) { m_src_vertices.modify_last(new VertexDistance(x, y)); } else { if (ShapePath.is_vertex(cmd)) { m_src_vertices.add(new VertexDistance(x, y)); } else { if (ShapePath.is_end_poly(cmd)) { m_closed = (ShapePath.get_close_flag(cmd) == ShapePath.FlagsAndCommand.FlagClose); if (m_orientation == ShapePath.FlagsAndCommand.FlagNone) { m_orientation = ShapePath.get_orientation(cmd); } } } } }
internal ShapeContent(LottieDrawable lottieDrawable, BaseLayer layer, ShapePath shape) { Name = shape.Name; _lottieDrawable = lottieDrawable; _shapeAnimation = shape.GetShapePath().CreateAnimation(); layer.AddAnimation(_shapeAnimation); _shapeAnimation.ValueChanged += OnValueChanged; }
// Make path functions //-------------------------------------------------------------------- public int start_new_path() { if (!ShapePath.is_stop(vertices.last_command())) { vertices.AddVertex(0.0, 0.0, ShapePath.FlagsAndCommand.CommandStop); } return(vertices.total_vertices()); }
public void ShapePathFromPathMaxIntersectionsProxyToShape() { ShapePath region = new ShapePath(pathMock1.Object); int i = region.MaxIntersections; pathMock1.Verify(x => x.MaxIntersections); }
public void GetPointInfoCallSinglePathForPath() { ShapePath region = new ShapePath(pathMock1.Object); ImageSharp.Drawing.PointInfo info = region.GetPointInfo(10, 1); pathMock1.Verify(x => x.Distance(new Vector2(10, 1)), Times.Once); pathMock2.Verify(x => x.Distance(new Vector2(10, 1)), Times.Never); }
public ShapePath.FlagsAndCommand vertex(out double x, out double y) { ShapePath.FlagsAndCommand cmd = VertexSource.vertex(out x, out y); if (ShapePath.is_vertex(cmd)) { transformToApply.transform(ref x, ref y); } return(cmd); }
public void AddVertex(double x, double y, ShapePath.FlagsAndCommand CommandAndFlags) { allocate_if_required(m_num_vertices); m_coord_x[m_num_vertices] = x; m_coord_y[m_num_vertices] = y; m_CommandAndFlags[m_num_vertices] = CommandAndFlags; m_num_vertices++; }
public void ShapePathFromPathConvertsBoundsDoesNotProxyToShape() { ShapePath region = new ShapePath(pathMock1.Object); Assert.Equal(Math.Floor(bounds1.Left), region.Bounds.Left); Assert.Equal(Math.Ceiling(bounds1.Right), region.Bounds.Right); pathMock1.Verify(x => x.Bounds); }
public override ShapePath.FlagsAndCommand vertex(out double x, out double y) { x = 0; y = 0; ShapePath.FlagsAndCommand cmd = ShapePath.FlagsAndCommand.LineTo; switch (m_idx) { case 0: if (m_vertex == 0) { cmd = ShapePath.FlagsAndCommand.MoveTo; } if (m_vertex >= 4) { cmd = ShapePath.FlagsAndCommand.Stop; } x = m_vx[m_vertex]; y = m_vy[m_vertex]; m_vertex++; break; case 1: if (m_vertex == 0 || m_vertex == 4) { cmd = ShapePath.FlagsAndCommand.MoveTo; } if (m_vertex >= 8) { cmd = ShapePath.FlagsAndCommand.Stop; } x = m_vx[m_vertex]; y = m_vy[m_vertex]; m_vertex++; break; case 2: cmd = m_curve_poly.vertex(out x, out y); break; case 3: case 4: cmd = m_curve_pnt.vertex(out x, out y); break; default: cmd = ShapePath.FlagsAndCommand.Stop; break; } if (!ShapePath.is_stop(cmd)) { //OriginRelativeParentTransform.transform(ref x, ref y); } return(cmd); }
public void concat_path(IVertexSource vs, int path_id) { double x, y; ShapePath.FlagsAndCommand PathAndFlags; vs.rewind(path_id); while (!ShapePath.is_stop(PathAndFlags = vs.vertex(out x, out y))) { vertices.AddVertex(x, y, PathAndFlags); } }
public void flip_y(double y1, double y2) { for (int i = 0; i < vertexDataManager.total_vertices(); i++) { ShapePath.FlagsAndCommand PathAndFlags = vertexDataManager.vertex(i, out double x, out double y); if (ShapePath.is_vertex(PathAndFlags)) { vertexDataManager.modify_vertex(i, x, y2 - y + y1); } } }
public IEnumerable <VertexData> Vertices() { foreach (VertexData vertexData in VertexSource.Vertices()) { VertexData transformedVertex = vertexData; if (ShapePath.is_vertex(transformedVertex.command)) { transformToApply.transform(ref transformedVertex.position.x, ref transformedVertex.position.y); } yield return(transformedVertex); } }
public void rel_to_abs(ref double x, ref double y) { if (vertices.total_vertices() != 0) { double x2; double y2; if (ShapePath.is_vertex(vertices.last_vertex(out x2, out y2))) { x += x2; y += y2; } } }
private void DrawLinePoints(ShapePath sp) { /* * float split = sp.length / (sliceNum-1); * * LineRenderer lineRenderer = this.gameObject.GetComponent<LineRenderer>(); * lineRenderer.SetVertexCount(sliceNum); * for(int i = 0; i < sliceNum; i++){ * Vector3 sPos = sp.getPointInfoVec3(split * i); * lineRenderer.SetPosition(i, sPos); * } */ }
public void flip_y(double y1, double y2) { int i; double x, y; for (i = 0; i < vertices.total_vertices(); i++) { ShapePath.FlagsAndCommand PathAndFlags = vertices.vertex(i, out x, out y); if (ShapePath.is_vertex(PathAndFlags)) { vertices.modify_vertex(i, x, y2 - y + y1); } } }
// Flip all vertices horizontally or vertically, // between x1 and x2, or between y1 and y2 respectively //-------------------------------------------------------------------- public void flip_x(double x1, double x2) { int i; double x, y; for (i = 0; i < vertexDataManager.total_vertices(); i++) { ShapePath.FlagsAndCommand PathAndFlags = vertexDataManager.vertex(i, out x, out y); if (ShapePath.is_vertex(PathAndFlags)) { vertexDataManager.modify_vertex(i, x2 - x + x1, y); } } }
public ShapePath.FlagsAndCommand vertex(out double x, out double y) { if (!ShapePath.is_stop(m_curve3.vertex(out x, out y))) { lastX = x; lastY = y; return(ShapePath.FlagsAndCommand.CommandLineTo); } if (!ShapePath.is_stop(m_curve4.vertex(out x, out y))) { lastX = x; lastY = y; return(ShapePath.FlagsAndCommand.CommandLineTo); } double ct2_x; double ct2_y; double end_x; double end_y; ShapePath.FlagsAndCommand cmd = VertexSource.vertex(out x, out y); switch (cmd) { case ShapePath.FlagsAndCommand.CommandCurve3: VertexSource.vertex(out end_x, out end_y); m_curve3.init(lastX, lastY, x, y, end_x, end_y); m_curve3.vertex(out x, out y); // First call returns path_cmd_move_to m_curve3.vertex(out x, out y); // This is the first vertex of the curve cmd = ShapePath.FlagsAndCommand.CommandLineTo; break; case ShapePath.FlagsAndCommand.CommandCurve4: VertexSource.vertex(out ct2_x, out ct2_y); VertexSource.vertex(out end_x, out end_y); m_curve4.init(lastX, lastY, x, y, ct2_x, ct2_y, end_x, end_y); m_curve4.vertex(out x, out y); // First call returns path_cmd_move_to m_curve4.vertex(out x, out y); // This is the first vertex of the curve cmd = ShapePath.FlagsAndCommand.CommandLineTo; break; } lastX = x; lastY = y; return(cmd); }
public ShapePath AddPath(Point startPoint, List <Point> points, string color) { ShapePath path = new ShapePath( new Point(startPoint.X, 1 - startPoint.Y)); Point[] sortedPoints = points.Select( point => new Point(point.X, 1 - point.Y)).ToArray(); foreach (Point point in sortedPoints) { path.AddPoint(point); } path.Color = color; path.SetIsCurved(false); return(path); }
public void CorrectlySetsPenPathAndOptions() { img.Draw(pen, path, noneDefault); Assert.NotEmpty(img.ProcessorApplications); DrawPathProcessor <Color> processor = Assert.IsType <DrawPathProcessor <Color> >(img.ProcessorApplications[0].processor); Assert.Equal(noneDefault, processor.Options); ShapePath shapepath = Assert.IsType <ShapePath>(processor.Path); Assert.Equal(path, shapepath.Path); Assert.Equal(pen, processor.Pen); }
//-------------------------------------------------------------------- public void transform_all_paths(Transform.Affine trans) { int index; int num_ver = vertices.total_vertices(); for (index = 0; index < num_ver; index++) { double x, y; if (ShapePath.is_vertex(vertices.vertex(index, out x, out y))) { trans.transform(ref x, ref y); vertices.modify_vertex(index, x, y); } } }
// Update is called once per frame void OnDrawGizmos() { if(points == null || points.Count < 1){ return; } // ShapePath pointList = new PointList(); // ShapePath if (pointList != null) { shapePath = pointList.GetShapePath(points.ToArray(), rots.ToArray()); for (int i = 0; i < num; i++) { float v = (float)i / num; Vector3 pt; // pt = shapePath.getPointInfoVec3Percent(v); PathVector pv = shapePath.getPathInfo(v); pt = new Vector3(pv.x, pv.y, pv.z); Gizmos.color = color; Gizmos.DrawWireSphere(pt, 0.25f); Quaternion rot = pv.rot; // Gizmos.color = new Color(0, 0, 0, 0.25f); Gizmos.DrawRay(pt, rot * Vector3.up * 2); Gizmos.DrawRay(pt, rot * Vector3.right * 2); Quaternion q2 = GetQuaternionAt(v); Gizmos.color = Color.green; Gizmos.DrawRay (pt, q2* Vector3.up); Gizmos.color = Color.red; Gizmos.DrawRay (pt, q2* Vector3.right); } } }
public void Add(double x, double y, ShapePath.FlagsAndCommand flagsAndCommand) { vertices.AddVertex(x, y, flagsAndCommand); }
public void modify_vertex(int index, double x, double y, ShapePath.FlagsAndCommand PathAndFlags) { vertices.modify_vertex(index, x, y, PathAndFlags); }
public void modify_command(int index, ShapePath.FlagsAndCommand PathAndFlags) { vertices.modify_command(index, PathAndFlags); }
// Arrange the orientation of a polygon, all polygons in a path, // or in all paths. After calling arrange_orientations() or // arrange_orientations_all_paths(), all the polygons will have // the same orientation, i.e. path_flags_cw or path_flags_ccw //-------------------------------------------------------------------- public int arrange_polygon_orientation(int start, ShapePath.FlagsAndCommand orientation) { if(orientation == ShapePath.FlagsAndCommand.FlagNone) return start; // Skip all non-vertices at the beginning while(start < vertices.total_vertices() && !ShapePath.is_vertex(vertices.command(start))) ++start; // Skip all insignificant move_to while(start+1 < vertices.total_vertices() && ShapePath.is_move_to(vertices.command(start)) && ShapePath.is_move_to(vertices.command(start+1))) ++start; // Find the last vertex int end = start + 1; while(end < vertices.total_vertices() && !ShapePath.is_next_poly(vertices.command(end))) ++end; if(end - start > 2) { if(perceive_polygon_orientation(start, end) != orientation) { // Invert polygon, set orientation flag, and skip all end_poly invert_polygon(start, end); ShapePath.FlagsAndCommand PathAndFlags; while(end < vertices.total_vertices() && ShapePath.is_end_poly(PathAndFlags = vertices.command(end))) { vertices.modify_command(end++, PathAndFlags | orientation);// Path.set_orientation(cmd, orientation)); } } } return end; }
public int arrange_orientations(int start, ShapePath.FlagsAndCommand orientation) { if(orientation != ShapePath.FlagsAndCommand.FlagNone) { while(start < vertices.total_vertices()) { start = arrange_polygon_orientation(start, orientation); if(ShapePath.is_stop(vertices.command(start))) { ++start; break; } } } return start; }
public VertexData(ShapePath.FlagsAndCommand command, Vector2 position) { this.command = command; this.position = position; }
public void modify_command(int index, ShapePath.FlagsAndCommand CommandAndFlags) { m_CommandAndFlags[index] = CommandAndFlags; }
public void modify_vertex(int index, double x, double y, ShapePath.FlagsAndCommand CommandAndFlags) { m_coord_x[index] = x; m_coord_y[index] = y; m_CommandAndFlags[index] = CommandAndFlags; }
public void arrange_orientations_all_paths(ShapePath.FlagsAndCommand orientation) { if(orientation != ShapePath.FlagsAndCommand.FlagNone) { int start = 0; while(start < vertices.total_vertices()) { start = arrange_orientations(start, orientation); } } }
public void add_vertex(double x, double y, ShapePath.FlagsAndCommand unknown) { }
public void close_polygon(ShapePath.FlagsAndCommand flags) { end_poly(ShapePath.FlagsAndCommand.FlagClose | flags); }