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

Function TestPathRelate

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

Source from the content-addressed store, hash-verified

1367)
1368
1369func TestPathRelate(t *testing.T) {
1370 var tts = []struct {
1371 p, q string
1372 rel relTest
1373 zs []Point
1374 }{
1375 {"L10 0L5 10z", "M0 5L10 5L5 15z", relOverlaps, []Point{{2.5, 5}, {7.5, 5}}},
1376 {"L10 0L5 10z", "M0 10L10 10L5 20z", relTouches, []Point{{5, 10}}},
1377 {"L10 0L5 10z", "M0 11L10 11L5 21z", relDisjoint, []Point{}},
1378 {"L10 0L5 10z", "M5 10L15 10L10 20z", relTouches, []Point{{5, 10}}},
1379 {"L10 0L5 10z", "M5 10L10 0L15 10z", relTouches, []Point{{5, 10}, {10, 0}}},
1380 {"L10 0L5 10z", "M10 0L20 0L15 10z", relTouches, []Point{{10, 0}}},
1381 {"L10 0L5 10z", "M11 0L21 0L16 10z", relDisjoint, []Point{}},
1382 //{"L10 0L5 10z", "M0 -5L10 -5A5 5 0 0 1 0 -5", []Point{{5, 0}}},
1383 //{"M5 5L0 0", "M-5 0A5 5 0 0 0 5 0", []Point{{5.0 / math.Sqrt(2.0), 5.0 / math.Sqrt(2.0)}}},
1384 {"L10 0", "M-1 0L0 0", relTouches, []Point{{0, 0}}},
1385 {"L10 0", "M10 0L20 0", relTouches, []Point{{10, 0}}},
1386 {"L10 0", "M11 0L21 0", relDisjoint, []Point{}},
1387 {"L10 0", "M0 1L10 1", relDisjoint, []Point{}},
1388 {"L10 0", "M0 -5L0 5", relTouches, []Point{{0, 0}}},
1389 {"L10 0", "M5 -5L5 5", relOverlaps, []Point{{5, 0}}},
1390 {"L10 0", "M10 -5L10 5", relTouches, []Point{{10, 0}}},
1391 {"L10 10L10 0L0 10z", "L10 10L10 0L0 10z", relEquals, []Point{}},
1392 //{"L10 0L10 10L0 10z", "", relDisjoint, []Point{}},
1393 //{"L10 10L10 0L0 10z", "", relIntersects, []Point{{5, 5}}},
1394 //{"M2 1L0 0L0 2L2 1L1 0L1 2z", "", relIntersects, []Point{{1, 0.5}, {1, 1.5}, {2, 1}}},
1395
1396 // containment
1397 {"L10 0L5 10z", "M1 1L9 1L5 9z", relContains, []Point{}},
1398 {"M1 1L9 1L5 9z", "L10 0L5 10z", relWithin, []Point{}},
1399 {"L10 0L5 10z", "M1 2L9 2L5 10z", relContains, []Point{{1, 2}, {9, 2}}},
1400 {"L10 0L5 10z", "L10 0L5 10z", relEquals, []Point{}},
1401 {"L10 0", "M1 0L9 0", relContains, []Point{{1, 0}, {9, 0}}},
1402 {"L10 0", "M-1 0L1 0", relOverlaps, []Point{{0, 0}, {1, 0}}},
1403 {"L10 0", "M1 0L11 0", relOverlaps, []Point{{1, 0}, {10, 0}}},
1404 {"L10 0", "L10 0", relEquals, []Point{}},
1405 {"L10 0", "M0 1L0 0L10 0L10 1", relIntersects | relWithin | relCoveredBy, []Point{ /*{0, 0},*/ {10, 0}}}, // TODO
1406
1407 // intersection on one segment endpoint
1408 {"L0 15", "M5 0L0 5L5 5", relOverlaps, []Point{{0, 5}}}, // unexpected, should be relTouches
1409 {"L0 15", "M5 0L0 5L-5 5", relOverlaps, []Point{{0, 5}}},
1410 {"L10 0", "M0 10L10 0", relTouches, []Point{{10, 0}}},
1411 {"L10 0L20 10", "M0 10L10 0", relTouches, []Point{{10, 0}}},
1412 {"L10 0L20 10", "M10 0L20 0", relTouches, []Point{{10, 0}}},
1413 {"L10 0", "M5 0L15 0", relOverlaps, []Point{{5, 0}, {10, 0}}},
1414 {"L10 0", "M5 5L10 0L15 5", relTouches, []Point{{10, 0}}},
1415 //{"L0 10", "M5 0A5 5 0 0 0 0 5A5 5 0 0 0 5 10", []Point{{0, 5}}},
1416 //{"L0 5L5 5", "M5 0A5 5 0 0 0 5 10", []Point{{0, 5}}},
1417
1418 // intersection on two segment endpoint
1419 {"L10 6L20 0", "M0 10L10 6L20 10", relOverlaps, []Point{{10, 6}}}, // unexpected, should be relTouches
1420 {"L10 6L20 10", "M0 10L10 6L20 0", relOverlaps, []Point{{10, 6}}},
1421 {"M4 1L4 3L0 3", "M3 4L4 3L3 2", relOverlaps, []Point{{4, 3}}},
1422 //{"M0 1L4 1L4 3L0 3z", MustParseSVGPath("M4 3A1 1 0 0 0 2 3A1 1 0 0 0 4 3z").Flatten(Tolerance).ToSVG(), []Point{{4, 3}, {2, 3}}},
1423 //{"M5 1L9 1L9 5L5 5z", MustParseSVGPath("M9 5A4 4 0 0 1 1 5A4 4 0 0 1 9 5z").Flatten(Tolerance).ToSVG(), []Point{{9, 5}, {5, 1.00828530}}},
1424
1425 // touches / same
1426 {"L2 0L2 2L0 2z", "M2 0L4 0L4 2L2 2z", relTouches, []Point{{2, 0}, {2, 2}}},

Callers

nothing calls this directly

Calls 13

MustParseSVGPathFunction · 0.85
RelateMethod · 0.80
TMethod · 0.80
DisjointMethod · 0.80
IntersectsMethod · 0.80
CoversMethod · 0.80
WithinMethod · 0.80
CoveredByMethod · 0.80
RunMethod · 0.45
TouchesMethod · 0.45
OverlapsMethod · 0.45
EqualsMethod · 0.45

Tested by

no test coverage detected