@@ -27,26 +27,33 @@ const findWireIntersections = (wires) => {
27
27
return { x : parseInt ( point . x ) , y : parseInt ( point . y ) }
28
28
} )
29
29
30
- return ints . sort ( isCloser )
30
+ return ints . sort ( isCloser . manhattan )
31
31
}
32
32
33
- const isCloser = ( intA , intB ) => {
34
- const origin = { x : 0 , y : 0 }
35
- intA . distance = distance ( origin , intA )
36
- intB . distance = distance ( origin , intB )
37
- if ( intA . distance < intB . distance ) {
38
- return - 1
33
+ const isCloser = {
34
+ manhattan : ( intA , intB ) => {
35
+ const origin = { x : 0 , y : 0 }
36
+ intA . distance = distance ( origin , intA )
37
+ intB . distance = distance ( origin , intB )
38
+ if ( intA . distance < intB . distance ) {
39
+ return - 1
40
+ }
41
+ if ( intA . distance > intB . distance ) {
42
+ return 1
43
+ }
44
+ if ( intA . distance === intB . distance ) {
45
+ return 0
46
+ }
39
47
}
40
- if ( intA . distance > intB . distance ) {
41
- return 1
42
- }
43
- if ( intA . distance === intB . distance ) {
44
- return 0
48
+ }
45
49
}
46
50
}
47
51
48
- const getClosesetIntersection = ( intersections ) => {
49
- intersections . sort ( isCloser )
52
+ const getClosesetIntersection = ( {
53
+ intersections,
54
+ method = 'manhattan'
55
+ } ) => {
56
+ intersections . sort ( isCloser [ method ] )
50
57
51
58
// TODO: Remove workaround for bug in SVG intersection library
52
59
// https://github.com/bpmn-io/path-intersection/issues/10
0 commit comments