/
githubmirror
/
pixijs
Обзор
Документация
Войти
/
githubmirror
/
pixijs
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
dev
examples/misc_spinners/intersect.ts
36 строк
1 KB
Zyie
chore: overhaul documentation system with TypeDoc plugins, examples, and guides (#11905)
12 фев 2026, 16:28
Не верифицирован
12 фев 2026, 16:28
ab6752d
Код
Авторство
О чём код?
/** * Helper functions * * line intercept math by Paul Bourke http://paulbourke.net/geometry/pointlineplane/ * Determine the intersection point of two line segments * Return FALSE if the lines don't intersect * * Code modified from original to match pixi examples linting rules. */ export function intersect(x1, y1, x2, y2, x3, y3, x4, y4) { // Check if none of the lines are of length 0 if ((x1 === x2 && y1 === y2) || (x3 === x4 && y3 === y4)) { return false; } const denominator = ((y4 - y3) * (x2 - x1)) - ((x4 - x3) * (y2 - y1)); // Lines are parallel if (denominator === 0) { return false; } const ua = (((x4 - x3) * (y1 - y3)) - ((y4 - y3) * (x1 - x3))) / denominator; const ub = (((x2 - x1) * (y1 - y3)) - ((y2 - y1) * (x1 - x3))) / denominator; // is the intersection along the segments if (ua < 0 || ua > 1 || ub < 0 || ub > 1) { return false; } // Return a object with the x and y coordinates of the intersection const x = x1 + (ua * (x2 - x1)); const y = y1 + (ua * (y2 - y1)); return { x, y }; }