MCPcopy Index your code
hub / github.com/tdewolff/canvas / intersectionSegment

Function intersectionSegment

path_intersection_util.go:14–85  ·  view source on GitHub ↗

see https://github.com/signavio/svg-intersections see https://github.com/w8r/bezier-intersect see https://cs.nyu.edu/exact/doc/subdiv1.pdf intersect for path segments a and b, starting at a0 and b0. Note that all intersection functions return upto two intersections.

(zs Intersections, a0 Point, a []float64, b0 Point, b []float64)

Source from the content-addressed store, hash-verified

12// intersect for path segments a and b, starting at a0 and b0. Note that all intersection functions
13// return upto two intersections.
14func intersectionSegment(zs Intersections, a0 Point, a []float64, b0 Point, b []float64) Intersections {
15 n := len(zs)
16 swapCurves := false
17 if a[0] == LineToCmd || a[0] == CloseCmd {
18 if b[0] == LineToCmd || b[0] == CloseCmd {
19 zs = intersectionLineLine(zs, a0, Point{a[1], a[2]}, b0, Point{b[1], b[2]})
20 } else if b[0] == QuadToCmd {
21 zs = intersectionLineQuad(zs, a0, Point{a[1], a[2]}, b0, Point{b[1], b[2]}, Point{b[3], b[4]})
22 } else if b[0] == CubeToCmd {
23 zs = intersectionLineCube(zs, a0, Point{a[1], a[2]}, b0, Point{b[1], b[2]}, Point{b[3], b[4]}, Point{b[5], b[6]})
24 } else if b[0] == ArcToCmd {
25 rx := b[1]
26 ry := b[2]
27 phi := b[3] * math.Pi / 180.0
28 large, sweep := toArcFlags(b[4])
29 cx, cy, theta0, theta1 := ellipseToCenter(b0.X, b0.Y, rx, ry, phi, large, sweep, b[5], b[6])
30 zs = intersectionLineEllipse(zs, a0, Point{a[1], a[2]}, Point{cx, cy}, Point{rx, ry}, phi, theta0, theta1)
31 }
32 } else if a[0] == QuadToCmd {
33 if b[0] == LineToCmd || b[0] == CloseCmd {
34 zs = intersectionLineQuad(zs, b0, Point{b[1], b[2]}, a0, Point{a[1], a[2]}, Point{a[3], a[4]})
35 swapCurves = true
36 } else if b[0] == QuadToCmd {
37 panic("unsupported intersection for quad-quad")
38 } else if b[0] == CubeToCmd {
39 panic("unsupported intersection for quad-cube")
40 } else if b[0] == ArcToCmd {
41 panic("unsupported intersection for quad-arc")
42 }
43 } else if a[0] == CubeToCmd {
44 if b[0] == LineToCmd || b[0] == CloseCmd {
45 zs = intersectionLineCube(zs, b0, Point{b[1], b[2]}, a0, Point{a[1], a[2]}, Point{a[3], a[4]}, Point{a[5], a[6]})
46 swapCurves = true
47 } else if b[0] == QuadToCmd {
48 panic("unsupported intersection for cube-quad")
49 } else if b[0] == CubeToCmd {
50 panic("unsupported intersection for cube-cube")
51 } else if b[0] == ArcToCmd {
52 panic("unsupported intersection for cube-arc")
53 }
54 } else if a[0] == ArcToCmd {
55 rx := a[1]
56 ry := a[2]
57 phi := a[3] * math.Pi / 180.0
58 large, sweep := toArcFlags(a[4])
59 cx, cy, theta0, theta1 := ellipseToCenter(a0.X, a0.Y, rx, ry, phi, large, sweep, a[5], a[6])
60 if b[0] == LineToCmd || b[0] == CloseCmd {
61 zs = intersectionLineEllipse(zs, b0, Point{b[1], b[2]}, Point{cx, cy}, Point{rx, ry}, phi, theta0, theta1)
62 swapCurves = true
63 } else if b[0] == QuadToCmd {
64 panic("unsupported intersection for arc-quad")
65 } else if b[0] == CubeToCmd {
66 panic("unsupported intersection for arc-cube")
67 } else if b[0] == ArcToCmd {
68 rx2 := b[1]
69 ry2 := b[2]
70 phi2 := b[3] * math.Pi / 180.0
71 large2, sweep2 := toArcFlags(b[4])

Callers 1

optimizeInnerBendMethod · 0.85

Calls 7

intersectionLineLineFunction · 0.85
intersectionLineQuadFunction · 0.85
intersectionLineCubeFunction · 0.85
toArcFlagsFunction · 0.85
ellipseToCenterFunction · 0.85
intersectionLineEllipseFunction · 0.85

Tested by

no test coverage detected