pointBetween method
bool
pointBetween(
- Coordinate p,
- Coordinate left,
- Coordinate right
)
Implementation
bool pointBetween(
JTS.Coordinate p, JTS.Coordinate left, JTS.Coordinate right) {
// p must be collinear with left->right
// returns false if p == left, p == right, or left == right
if (pointsSame(p, left) || pointsSame(p, right)) return false;
var d_py_ly = p.y - left.y;
var d_rx_lx = right.x - left.x;
var d_px_lx = p.x - left.x;
var d_ry_ly = right.y - left.y;
var dot = d_px_lx * d_rx_lx + d_py_ly * d_ry_ly;
// dot < 0 is p is to the left of 'left'
if (dot < 0) return false;
var sqlen = d_rx_lx * d_rx_lx + d_ry_ly * d_ry_ly;
// dot <= sqlen is p is to the left of 'right'
return dot <= sqlen;
}