webpd
Version:
WebPd is a compiler for audio programming language Pure Data allowing to run .pd patches on web pages.
37 lines (35 loc) • 1.1 kB
JavaScript
const makeTranslationTransform = (fromPoint, toPoint) => {
const xOffset = toPoint.x - fromPoint.x;
const yOffset = toPoint.y - fromPoint.y;
return (fromPoint) => {
return {
x: fromPoint.x + xOffset,
y: fromPoint.y + yOffset,
};
};
};
const sumPoints = (p1, p2) => ({
x: p1.x + p2.x,
y: p1.y + p2.y,
});
const computeRectanglesIntersection = (r1, r2) => {
const topLeft = {
x: Math.max(r1.topLeft.x, r2.topLeft.x),
y: Math.max(r1.topLeft.y, r2.topLeft.y),
};
const bottomRight = {
x: Math.min(r1.bottomRight.x, r2.bottomRight.x),
y: Math.min(r1.bottomRight.y, r2.bottomRight.y),
};
if (bottomRight.x <= topLeft.x || bottomRight.y <= topLeft.y) {
return null;
}
else {
return { topLeft, bottomRight };
}
};
const isPointInsideRectangle = (p, r) => r.topLeft.x <= p.x &&
p.x <= r.bottomRight.x &&
r.topLeft.y <= p.y &&
p.y <= r.bottomRight.y;
export { computeRectanglesIntersection, isPointInsideRectangle, makeTranslationTransform, sumPoints };