public static List <Vector2> GetPath(SVGMatrix matrix, SVGLineElement svgElement) { List <Vector2> output = new List <Vector2>() { matrix.Transform(new Vector2(svgElement.x1.value, svgElement.y1.value)), matrix.Transform(new Vector2(svgElement.x2.value, svgElement.y2.value)) }; return(output); }
public static List <Vector2> GetPath(SVGMatrix matrix, SVGPolylineElement svgElement) { List <Vector2> output = new List <Vector2>(svgElement.listPoints.Count + 1); List <Vector2> listPoints = svgElement.listPoints; for (int i = 0; i < listPoints.Count; i++) { output.Add(matrix.Transform(listPoints[i])); } // Douglas Peucker Reduction return(SVGBezier.Optimise(output, SVGGraphics.vpm)); }
protected static void WriteUVGradientCoordinates(ref Vector2[] uv, Vector3[] vertices, SVGPaintable svgPaintable, Rect bounds) { SVGFill svgFill = svgPaintable.svgFill; if (svgFill.fillType == FILL_TYPE.GRADIENT) { int meshVertexCount = vertices.Length; uv = new Vector2[meshVertexCount]; Vector2 uvPoint = Vector2.zero; SVGMatrix svgFillTransform = GetFillTransform(svgPaintable, bounds); Rect viewport = svgPaintable.viewport; for (int i = 0; i < meshVertexCount; i++) { uvPoint.x = vertices [i].x; uvPoint.y = vertices [i].y; uvPoint = svgFillTransform.Transform(uvPoint); uv [i].x = (uvPoint.x - viewport.x) / viewport.width; uv [i].y = (uvPoint.y - viewport.y) / viewport.height; } } }
public static List <Vector2> GetPath(SVGMatrix matrix, SVGRectElement svgElement) { List <Vector2> output = new List <Vector2>(); float width = svgElement.width.value, height = svgElement.height.value; float x = svgElement.x.value, y = svgElement.y.value, rx = svgElement.rx.value, ry = svgElement.ry.value; Vector2 p1 = new Vector2(x, y), p2 = new Vector2(x + width, y), p3 = new Vector2(x + width, y + height), p4 = new Vector2(x, y + height); if (rx == 0.0f && ry == 0.0f) { output = new List <Vector2>(new Vector2[] { matrix.Transform(p1), matrix.Transform(p2), matrix.Transform(p3), matrix.Transform(p4) }); } else { float t_rx = (rx == 0.0f) ? ry : rx; float t_ry = (ry == 0.0f) ? rx : ry; t_rx = (t_rx > (width * 0.5f - 2f)) ? (width * 0.5f - 2f) : t_rx; t_ry = (t_ry > (height * 0.5f - 2f)) ? (height * 0.5f - 2f) : t_ry; float angle = svgElement.transformAngle; Vector2 t_p1 = matrix.Transform(new Vector2(p1.x + t_rx, p1.y)); Vector2 t_p2 = matrix.Transform(new Vector2(p2.x - t_rx, p2.y)); Vector2 t_p3 = matrix.Transform(new Vector2(p2.x, p2.y + t_ry)); Vector2 t_p4 = matrix.Transform(new Vector2(p3.x, p3.y - t_ry)); Vector2 t_p5 = matrix.Transform(new Vector2(p3.x - t_rx, p3.y)); Vector2 t_p6 = matrix.Transform(new Vector2(p4.x + t_rx, p4.y)); Vector2 t_p7 = matrix.Transform(new Vector2(p4.x, p4.y - t_ry)); Vector2 t_p8 = matrix.Transform(new Vector2(p1.x, p1.y + t_ry)); output = SVGGeomUtils.RoundedRect(t_p1, t_p2, t_p3, t_p4, t_p5, t_p6, t_p7, t_p8, t_rx, t_ry, angle); } output.Add(output[0]); return(output); }
public static List <Vector2> Circle(float x0, float y0, float radius, SVGMatrix matrix) { List <Vector2> output = new List <Vector2>(); x0 -= radius; y0 -= radius; float handleDistance = circleConstant * radius; Vector2 handleRight = new Vector2(handleDistance, 0f); Vector2 handleLeft = new Vector2(-handleDistance, 0f); Vector2 handleUp = new Vector2(0f, -handleDistance); Vector2 handleDown = new Vector2(0f, handleDistance); Vector2 topCenter = new Vector2(x0 + radius, y0); Vector2 left = new Vector2(x0, y0 + radius); Vector2 right = new Vector2(x0 + radius * 2f, y0 + radius); Vector2 bottomCenter = new Vector2(x0 + radius, y0 + radius * 2f); output.AddRange(SVGGeomUtils.CubicCurve(matrix.Transform(topCenter), matrix.Transform(topCenter + handleRight), matrix.Transform(right + handleUp), matrix.Transform(right))); output.AddRange(SVGGeomUtils.CubicCurve(matrix.Transform(right), matrix.Transform(right + handleDown), matrix.Transform(bottomCenter + handleRight), matrix.Transform(bottomCenter))); output.AddRange(SVGGeomUtils.CubicCurve(matrix.Transform(bottomCenter), matrix.Transform(bottomCenter + handleLeft), matrix.Transform(left + handleDown), matrix.Transform(left))); output.AddRange(SVGGeomUtils.CubicCurve(matrix.Transform(left), matrix.Transform(left + handleUp), matrix.Transform(topCenter + handleLeft), matrix.Transform(topCenter))); return(output); }
public static List<Vector2> Ellipse(float cx, float cy, float rx, float ry, SVGMatrix matrix) { List<Vector2> output = new List<Vector2>(); cx -= rx; cy -= ry; float handleDistanceX = circleConstant * rx; float handleDistanceY = circleConstant * ry; Vector2 handleRight = new Vector2(handleDistanceX, 0f); Vector2 handleLeft = new Vector2(-handleDistanceX, 0f); Vector2 handleUp = new Vector2(0f, -handleDistanceY); Vector2 handleDown = new Vector2(0f, handleDistanceY); Vector2 topCenter = new Vector2(cx + rx, cy); Vector2 left = new Vector2(cx, cy + ry); // Vector2 center = new Vector2(cx + rx, cy + ry); Vector2 right = new Vector2(cx + rx * 2f, cy + ry ); Vector2 bottomCenter = new Vector2(cx + rx, cy + ry * 2f); output.AddRange(SVGGeomUtils.CubicCurve(matrix.Transform(topCenter), matrix.Transform(topCenter + handleRight), matrix.Transform(right + handleUp), matrix.Transform(right))); output.AddRange(SVGGeomUtils.CubicCurve(matrix.Transform(right), matrix.Transform(right + handleDown), matrix.Transform(bottomCenter + handleRight), matrix.Transform(bottomCenter))); output.AddRange(SVGGeomUtils.CubicCurve(matrix.Transform(bottomCenter), matrix.Transform(bottomCenter + handleLeft), matrix.Transform(left + handleDown), matrix.Transform(left))); output.AddRange(SVGGeomUtils.CubicCurve(matrix.Transform(left), matrix.Transform(left + handleUp), matrix.Transform(topCenter + handleLeft), matrix.Transform(topCenter))); return output; }
public static List <Vector2> Ellipse(float cx, float cy, float rx, float ry, SVGMatrix matrix) { List <Vector2> output = new List <Vector2>(); cx -= rx; cy -= ry; float handleDistanceX = circleConstant * rx; float handleDistanceY = circleConstant * ry; Vector2 handleRight = new Vector2(handleDistanceX, 0f); Vector2 handleLeft = new Vector2(-handleDistanceX, 0f); Vector2 handleUp = new Vector2(0f, -handleDistanceY); Vector2 handleDown = new Vector2(0f, handleDistanceY); Vector2 topCenter = new Vector2(cx + rx, cy); Vector2 left = new Vector2(cx, cy + ry); // Vector2 center = new Vector2(cx + rx, cy + ry); Vector2 right = new Vector2(cx + rx * 2f, cy + ry); Vector2 bottomCenter = new Vector2(cx + rx, cy + ry * 2f); output.AddRange(SVGGeomUtils.CubicCurve(matrix.Transform(topCenter), matrix.Transform(topCenter + handleRight), matrix.Transform(right + handleUp), matrix.Transform(right))); output.AddRange(SVGGeomUtils.CubicCurve(matrix.Transform(right), matrix.Transform(right + handleDown), matrix.Transform(bottomCenter + handleRight), matrix.Transform(bottomCenter))); output.AddRange(SVGGeomUtils.CubicCurve(matrix.Transform(bottomCenter), matrix.Transform(bottomCenter + handleLeft), matrix.Transform(left + handleDown), matrix.Transform(left))); output.AddRange(SVGGeomUtils.CubicCurve(matrix.Transform(left), matrix.Transform(left + handleUp), matrix.Transform(topCenter + handleLeft), matrix.Transform(topCenter))); return(output); }
public static List<Vector2> GetPath(SVGMatrix matrix, SVGPolygonElement svgElement) { List<Vector2> output = new List<Vector2>(svgElement.listPoints.Count + 1); List<Vector2> listPoints = svgElement.listPoints; for (int i = 0; i < listPoints.Count; i++) { output.Add(matrix.Transform(listPoints[i])); } output.Add(output[0]); // Douglas Peucker Reduction return SVGBezier.Optimise(output, SVGGraphics.vpm); }
public static List<Vector2> GetPath(SVGMatrix matrix, SVGLineElement svgElement) { List<Vector2> output = new List<Vector2>(){ matrix.Transform(new Vector2(svgElement.x1.value, svgElement.y1.value)), matrix.Transform(new Vector2(svgElement.x2.value, svgElement.y2.value)) }; return output; }
public static List<Vector2> Circle(float x0, float y0, float radius, SVGMatrix matrix) { List<Vector2> output = new List<Vector2>(); x0 -= radius; y0 -= radius; float handleDistance = circleConstant * radius; Vector2 handleRight = new Vector2(handleDistance, 0f); Vector2 handleLeft = new Vector2(-handleDistance, 0f); Vector2 handleUp = new Vector2(0f, -handleDistance); Vector2 handleDown = new Vector2(0f, handleDistance); Vector2 topCenter = new Vector2(x0 + radius, y0); Vector2 left = new Vector2(x0, y0 + radius); Vector2 right = new Vector2(x0 + radius * 2f, y0 + radius ); Vector2 bottomCenter = new Vector2(x0 + radius, y0 + radius * 2f); output.AddRange(SVGGeomUtils.CubicCurve(matrix.Transform(topCenter), matrix.Transform(topCenter + handleRight), matrix.Transform(right + handleUp), matrix.Transform(right))); output.AddRange(SVGGeomUtils.CubicCurve(matrix.Transform(right), matrix.Transform(right + handleDown), matrix.Transform(bottomCenter + handleRight), matrix.Transform(bottomCenter))); output.AddRange(SVGGeomUtils.CubicCurve(matrix.Transform(bottomCenter), matrix.Transform(bottomCenter + handleLeft), matrix.Transform(left + handleDown), matrix.Transform(left))); output.AddRange(SVGGeomUtils.CubicCurve(matrix.Transform(left), matrix.Transform(left + handleUp), matrix.Transform(topCenter + handleLeft), matrix.Transform(topCenter))); return output; }
public static List<Vector2> GetPath(SVGMatrix matrix, SVGRectElement svgElement) { List<Vector2> output = new List<Vector2>(); float width = svgElement.width.value, height = svgElement.height.value; float x = svgElement.x.value, y = svgElement.y.value, rx = svgElement.rx.value, ry = svgElement.ry.value; Vector2 p1 = new Vector2(x, y), p2 = new Vector2(x + width, y), p3 = new Vector2(x + width, y + height), p4 = new Vector2(x, y + height); if(rx == 0.0f && ry == 0.0f) { output = new List<Vector2>(new Vector2[]{ matrix.Transform(p1), matrix.Transform(p2), matrix.Transform(p3), matrix.Transform(p4) }); } else { float t_rx = (rx == 0.0f) ? ry : rx; float t_ry = (ry == 0.0f) ? rx : ry; t_rx = (t_rx > (width * 0.5f - 2f)) ? (width * 0.5f - 2f) : t_rx; t_ry = (t_ry > (height * 0.5f - 2f)) ? (height * 0.5f - 2f) : t_ry; float angle = svgElement.transformAngle; Vector2 t_p1 = matrix.Transform(new Vector2(p1.x + t_rx, p1.y)); Vector2 t_p2 = matrix.Transform(new Vector2(p2.x - t_rx, p2.y)); Vector2 t_p3 = matrix.Transform(new Vector2(p2.x, p2.y + t_ry)); Vector2 t_p4 = matrix.Transform(new Vector2(p3.x, p3.y - t_ry)); Vector2 t_p5 = matrix.Transform(new Vector2(p3.x - t_rx, p3.y)); Vector2 t_p6 = matrix.Transform(new Vector2(p4.x + t_rx, p4.y)); Vector2 t_p7 = matrix.Transform(new Vector2(p4.x, p4.y - t_ry)); Vector2 t_p8 = matrix.Transform(new Vector2(p1.x, p1.y + t_ry)); output = SVGGeomUtils.RoundedRect(t_p1, t_p2, t_p3, t_p4, t_p5, t_p6, t_p7, t_p8, t_rx, t_ry, angle); } output.Add(output[0]); return output; }