for quadratic Bézier use https://www.wolframalpha.com/input/?i=length+of+the+curve+%7Bx%3D2*(1-t)*t*50.00+%2B+t%5E2*100.00,+y%3D2*(1-t)*t*66.67+%2B+t%5E2*0.00%7D+from+0+to+1 for cubic Bézier use https://www.wolframalpha.com/input/?i=length+of+the+curve+%7Bx%3D3*(1-t)%5E2*t*0.00+%2B+3*(1-t)*t%5E2*100
(t *testing.T)
| 396 | // for cubic Bézier use https://www.wolframalpha.com/input/?i=length+of+the+curve+%7Bx%3D3*(1-t)%5E2*t*0.00+%2B+3*(1-t)*t%5E2*100.00+%2B+t%5E3*100.00,+y%3D3*(1-t)%5E2*t*66.67+%2B+3*(1-t)*t%5E2*66.67+%2B+t%5E3*0.00%7D+from+0+to+1 |
| 397 | // for ellipse use https://www.wolframalpha.com/input/?i=length+of+the+curve+%7Bx%3D10.00*cos(t),+y%3D20.0*sin(t)%7D+from+0+to+pi |
| 398 | func TestPathLength(t *testing.T) { |
| 399 | var tts = []struct { |
| 400 | p string |
| 401 | length float64 |
| 402 | }{ |
| 403 | {"M10 0z", 0.0}, |
| 404 | {"Q50 66.67 100 0", 124.533}, |
| 405 | {"Q100 0 100 0", 100.0000}, |
| 406 | {"C0 66.67 100 66.67 100 0", 158.5864}, |
| 407 | {"C0 0 100 66.67 100 0", 125.746}, |
| 408 | {"C0 0 100 0 100 0", 100.0000}, |
| 409 | {"C100 66.67 0 66.67 100 0", 143.9746}, |
| 410 | {"A10 20 0 0 0 20 0", 48.4422}, |
| 411 | {"A10 20 0 0 1 20 0", 48.4422}, |
| 412 | {"A10 20 0 1 0 20 0", 48.4422}, |
| 413 | {"A10 20 0 1 1 20 0", 48.4422}, |
| 414 | {"A10 20 30 0 0 20 0", 31.4622}, |
| 415 | } |
| 416 | for _, tt := range tts { |
| 417 | t.Run(tt.p, func(t *testing.T) { |
| 418 | length := MustParseSVGPath(tt.p).Length() |
| 419 | if math.Abs(tt.length-length)/length > 0.01 { |
| 420 | test.Fail(t, length, "!=", tt.length, "±1%") |
| 421 | } |
| 422 | }) |
| 423 | } |
| 424 | } |
| 425 | |
| 426 | func TestPathTransform(t *testing.T) { |
| 427 | var tts = []struct { |
nothing calls this directly
no test coverage detected