MCPcopy
hub / github.com/tdewolff/canvas / TestIntersectionLineCube

Function TestIntersectionLineCube

path_intersection_test.go:288–336  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

286}
287
288func TestIntersectionLineCube(t *testing.T) {
289 var tts = []struct {
290 line, cube string
291 zs Intersections
292 }{
293 // secant
294 {"M0 5L10 5", "C8 0 8 10 0 10", Intersections{
295 {Point{6.0, 5.0}, [2]float64{0.6, 0.5}, [2]float64{0.0, 0.5 * math.Pi}, false, false},
296 }},
297 {"M0 1L1 1", "C0 2 1 0 1 2", Intersections{ // parallel at intersection
298 {Point{0.5, 1.0}, [2]float64{0.5, 0.5}, [2]float64{0.0, 0.0}, false, false},
299 }},
300 {"M0 1L1 1", "M0 2C0 0 1 2 1 0", Intersections{ // parallel at intersection
301 {Point{0.5, 1.0}, [2]float64{0.5, 0.5}, [2]float64{0.0, 0.0}, false, false},
302 }},
303 {"M0 1L1 1", "C0 3 1 -1 1 2", Intersections{ // three intersections
304 {Point{0.0791512117, 1.0}, [2]float64{0.0791512117, 0.1726731646}, [2]float64{0.0, 74.05460410 / 180.0 * math.Pi}, false, false},
305 {Point{0.5, 1.0}, [2]float64{0.5, 0.5}, [2]float64{0.0, 315 / 180.0 * math.Pi}, false, false},
306 {Point{0.9208487883, 1.0}, [2]float64{0.9208487883, 0.8273268354}, [2]float64{0.0, 74.05460410 / 180.0 * math.Pi}, false, false},
307 }},
308
309 // tangent
310 {"L0 10", "C8 0 8 10 0 10", Intersections{
311 {Point{0.0, 0.0}, [2]float64{0.0, 0.0}, [2]float64{0.5 * math.Pi, 0.0}, true, false},
312 {Point{0.0, 10.0}, [2]float64{1.0, 1.0}, [2]float64{0.5 * math.Pi, math.Pi}, true, false},
313 }},
314 {"M6 0L6 10", "C8 0 8 10 0 10", Intersections{
315 {Point{6.0, 5.0}, [2]float64{0.5, 0.5}, [2]float64{0.5 * math.Pi, 0.5 * math.Pi}, true, false},
316 }},
317
318 // none
319 {"M-1 0L-1 10", "C8 0 8 10 0 10", Intersections{}},
320 }
321 origEpsilon := Epsilon
322 for _, tt := range tts {
323 t.Run(fmt.Sprint(tt.line, "x", tt.cube), func(t *testing.T) {
324 Epsilon = origEpsilon
325 line := MustParseSVGPath(tt.line).ReverseScanner()
326 cube := MustParseSVGPath(tt.cube).ReverseScanner()
327 line.Scan()
328 cube.Scan()
329
330 zs := intersectionLineCube(nil, line.Start(), line.End(), cube.Start(), cube.CP1(), cube.CP2(), cube.End())
331 Epsilon = 3.0 * origEpsilon
332 test.T(t, zs, tt.zs)
333 })
334 }
335 Epsilon = origEpsilon
336}
337
338func TestIntersectionLineEllipse(t *testing.T) {
339 var tts = []struct {

Callers

nothing calls this directly

Calls 10

MustParseSVGPathFunction · 0.85
intersectionLineCubeFunction · 0.85
ReverseScannerMethod · 0.80
TMethod · 0.80
RunMethod · 0.45
ScanMethod · 0.45
StartMethod · 0.45
EndMethod · 0.45
CP1Method · 0.45
CP2Method · 0.45

Tested by

no test coverage detected