RectangularPathFinder

Class which finds rectangular path, i.e. path with 90 degrees turns, between two boxes.

Configs

9
endArrowMargin: Number= 12

Default end arrow staff size in pixels

endShift: Number= 0

Default ending connection point shift from box's arrow pointing side middle point

endSide: top | bottom | left | right= left

Default end arrow pointing direction, possible values are: 'left', 'right', 'top', 'bottom'

horizontalMargin: Number= 5

Start / End box horizontal margin, the amount of pixels from left and right line of a box where drawing

otherBoxes: Object[]

Other rectangular areas (obstacles) to search path through

startArrowMargin: Number= 12

Default start arrow staff size in pixels

startShift: Number= 0

Default starting connection point shift from box's arrow pointing side middle point

startSide: top | bottom | left | right= right

Default start connection side: 'left', 'right', 'top', 'bottom'

verticalMargin: Number= 2

Start / End box vertical margin, the amount of pixels from top and bottom line of a box where drawing is prohibited

Functions

1

Returns list of horizontal and vertical segments connecting two boxes

   |    | |  |    |       |
 --+----+----+----*-------*---
 --+=>Start  +----*-------*--
 --+----+----+----*-------*--
   |    | |  |    |       |
   |    | |  |    |       |
 --*----*-+-------+-------+--
 --*----*-+         End <=+--
 --*----*-+-------+-------+--
   |    | |  |    |       |

Path goes by lines (-=) and turns at intersections (+), boxes depicted are adjusted by horizontal/vertical margin and arrow margin, original boxes are smaller (path can't go at original box borders). Algorithm finds the shortest path with minimum amount of turns. In short it's mix of "Lee" and "Dijkstra pathfinding" with turns amount taken into account for distance calculation.

The algorithm is not very performant though, it's O(N^2), where N is amount of points in the grid, but since the maximum amount of points in the grid might be up to 34 (not 36 since two box middle points are not permitted) that might be ok for now.

ParameterTypeDescription
lineDefObject

An object containing any of the class configuration option overrides as well as startBox, endBox, startHorizontalMargin, startVerticalMargin, endHorizontalMargin, endVerticalMargin properties

lineDef.startBoxObject

An object containing start, end, top, bottom properties

lineDef.endBoxObject

An object containing start, end, top, bottom properties

lineDef.startHorizontalMarginNumber

Horizontal margin override for start box

lineDef.startVerticalMarginNumber

Vertical margin override for start box

lineDef.endHorizontalMarginNumber

Horizontal margin override for end box

lineDef.endVerticalMarginNumber

Vertical margin override for end box

Returns: Number[] | Boolean -

Array of line segments or false if path cannot be found