Length returns the length of the path in millimeters. The length is approximated for cubic Béziers.
()
| 1231 | |
| 1232 | // Length returns the length of the path in millimeters. The length is approximated for cubic Béziers. |
| 1233 | func (p *Path) Length() float64 { |
| 1234 | d := 0.0 |
| 1235 | var start, end Point |
| 1236 | for i := 0; i < len(p.d); { |
| 1237 | cmd := p.d[i] |
| 1238 | switch cmd { |
| 1239 | case MoveToCmd: |
| 1240 | end = Point{p.d[i+1], p.d[i+2]} |
| 1241 | case LineToCmd, CloseCmd: |
| 1242 | end = Point{p.d[i+1], p.d[i+2]} |
| 1243 | d += end.Sub(start).Length() |
| 1244 | case QuadToCmd: |
| 1245 | cp := Point{p.d[i+1], p.d[i+2]} |
| 1246 | end = Point{p.d[i+3], p.d[i+4]} |
| 1247 | d += quadraticBezierLength(start, cp, end) |
| 1248 | case CubeToCmd: |
| 1249 | cp1 := Point{p.d[i+1], p.d[i+2]} |
| 1250 | cp2 := Point{p.d[i+3], p.d[i+4]} |
| 1251 | end = Point{p.d[i+5], p.d[i+6]} |
| 1252 | d += cubicBezierLength(start, cp1, cp2, end) |
| 1253 | case ArcToCmd: |
| 1254 | rx, ry, phi := p.d[i+1], p.d[i+2], p.d[i+3] |
| 1255 | large, sweep := toArcFlags(p.d[i+4]) |
| 1256 | end = Point{p.d[i+5], p.d[i+6]} |
| 1257 | _, _, theta1, theta2 := ellipseToCenter(start.X, start.Y, rx, ry, phi, large, sweep, end.X, end.Y) |
| 1258 | d += ellipseLength(rx, ry, theta1, theta2) |
| 1259 | } |
| 1260 | i += cmdLen(cmd) |
| 1261 | start = end |
| 1262 | } |
| 1263 | return d |
| 1264 | } |
| 1265 | |
| 1266 | // Transform transforms the path by the given transformation matrix. It modifies the path in-place. |
| 1267 | func (p *Path) Transform(m Matrix) *Path { |