You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
641 B
25 lines
641 B
1 month ago
|
export function containStroke(x0, y0, x1, y1, lineWidth, x, y) {
|
||
|
if (lineWidth === 0) {
|
||
|
return false;
|
||
|
}
|
||
|
var _l = lineWidth;
|
||
|
var _a = 0;
|
||
|
var _b = x0;
|
||
|
if ((y > y0 + _l && y > y1 + _l)
|
||
|
|| (y < y0 - _l && y < y1 - _l)
|
||
|
|| (x > x0 + _l && x > x1 + _l)
|
||
|
|| (x < x0 - _l && x < x1 - _l)) {
|
||
|
return false;
|
||
|
}
|
||
|
if (x0 !== x1) {
|
||
|
_a = (y0 - y1) / (x0 - x1);
|
||
|
_b = (x0 * y1 - x1 * y0) / (x0 - x1);
|
||
|
}
|
||
|
else {
|
||
|
return Math.abs(x - x0) <= _l / 2;
|
||
|
}
|
||
|
var tmp = _a * x - y + _b;
|
||
|
var _s = tmp * tmp / (_a * _a + 1);
|
||
|
return _s <= _l / 2 * _l / 2;
|
||
|
}
|