ef-infinite-canvas
Version:
An infinite version of the html canvas
1,748 lines • 217 kB
JavaScript
var Ti = Object.defineProperty;
var Si = (s, t, e) => t in s ? Ti(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e;
var a = (s, t, e) => Si(s, typeof t != "symbol" ? t + "" : t, e);
let yi = class {
constructor(t) {
this.viewBox = t;
}
restore() {
this.viewBox.restoreState();
}
save() {
this.viewBox.saveState();
}
reset() {
this.viewBox.resetState();
}
};
const X = class X {
constructor(t, e) {
this.x = t, this.y = e;
}
mod() {
return Math.sqrt(this.modSq());
}
modSq() {
return this.x * this.x + this.y * this.y;
}
minus(t) {
return new X(this.x - t.x, this.y - t.y);
}
plus(t) {
return new X(this.x + t.x, this.y + t.y);
}
dot(t) {
return this.x * t.x + this.y * t.y;
}
cross(t) {
return this.x * t.y - this.y * t.x;
}
equals(t) {
return this.x === t.x && this.y === t.y;
}
getPerpendicular() {
return new X(-this.y, this.x);
}
scale(t) {
return new X(t * this.x, t * this.y);
}
projectOn(t) {
return t.scale(this.dot(t) / t.modSq());
}
matrix(t, e, n, i) {
return new X(t * this.x + e * this.y, n * this.x + i * this.y);
}
inSameDirectionAs(t) {
return this.cross(t) === 0 && this.dot(t) >= 0;
}
isInOppositeDirectionAs(t) {
return this.cross(t) === 0 && this.dot(t) < 0;
}
isOnSameSideOfOriginAs(t, e) {
return this.isInSmallerAngleBetweenPoints(t, e) || t.isInSmallerAngleBetweenPoints(this, e) || e.isInSmallerAngleBetweenPoints(this, t);
}
isInSmallerAngleBetweenPoints(t, e) {
const n = t.cross(e);
return n > 0 ? t.cross(this) >= 0 && this.cross(e) >= 0 : n < 0 ? t.cross(this) <= 0 && this.cross(e) <= 0 : t.dot(e) > 0 ? this.cross(t) === 0 && this.dot(t) > 0 : !0;
}
};
a(X, "origin", new X(0, 0));
let h = X;
function ht(s) {
return s.toFixed(10).replace(/\.?0+$/, "");
}
const b = class b {
constructor(t, e, n, i, r, o) {
a(this, "scale");
this.a = t, this.b = e, this.c = n, this.d = i, this.e = r, this.f = o, this.scale = Math.sqrt(t * i - e * n);
}
getMaximumLineWidthScale() {
const t = this.a + this.c, e = this.b + this.d, n = this.a - this.c, i = this.b - this.d;
return Math.sqrt(Math.max(t * t + e * e, n * n + i * i));
}
getRotationAngle() {
const t = this.a / this.scale, e = this.b / this.scale;
if (t === 0)
return e > 0 ? Math.PI / 2 : 3 * Math.PI / 2;
const n = Math.atan(e / t);
return t > 0 ? e > 0 ? n : e === 0 ? 0 : 2 * Math.PI + n : e > 0 ? Math.PI + n : e === 0 ? Math.PI : Math.PI + n;
}
applyToPointAtInfinity(t) {
return { direction: this.untranslated().apply(t.direction) };
}
apply(t) {
return new h(this.a * t.x + this.c * t.y + this.e, this.b * t.x + this.d * t.y + this.f);
}
untranslated() {
const { x: t, y: e } = this.apply(h.origin);
return this.before(b.translation(-t, -e));
}
before(t) {
const e = t.a * this.a + t.c * this.b, n = t.b * this.a + t.d * this.b, i = t.a * this.c + t.c * this.d, r = t.b * this.c + t.d * this.d, o = t.a * this.e + t.c * this.f + t.e, c = t.b * this.e + t.d * this.f + t.f;
return new b(e, n, i, r, o, c);
}
equals(t) {
return this.a === t.a && this.b === t.b && this.c === t.c && this.d === t.d && this.e === t.e && this.f === t.f;
}
inverse() {
var t = this.a * this.d - this.b * this.c;
if (t == 0)
throw new Error("error calculating inverse: zero determinant");
const e = this.d / t, n = -this.b / t, i = -this.c / t, r = this.a / t, o = (this.c * this.f - this.d * this.e) / t, c = (this.b * this.e - this.a * this.f) / t;
return new b(e, n, i, r, o, c);
}
static translation(t, e) {
return new b(1, 0, 0, 1, t, e);
}
static scale(t) {
return new b(t, 0, 0, t, 0, 0);
}
static zoom(t, e, n, i, r) {
const o = 1 - n;
return i !== void 0 ? new b(n, 0, 0, n, t * o + i, e * o + r) : new b(n, 0, 0, n, t * o, e * o);
}
static translateZoom(t, e, n, i, r, o, c, l) {
const u = n - t, d = i - e, f = u * u + d * d;
if (f === 0)
throw new Error("divide by 0");
const m = c - r, C = l - o, I = m * m + C * C, O = Math.sqrt(I / f);
return b.zoom(t, e, O, r - t, o - e);
}
static rotation(t, e, n) {
const i = Math.cos(n), r = Math.sin(n), o = 1 - i;
return new b(
i,
r,
-r,
i,
t * o + e * r,
-t * r + e * o
);
}
static translateRotateZoom(t, e, n, i, r, o, c, l) {
const u = n - t, d = i - e, f = u * u + d * d;
if (f === 0)
throw new Error("divide by 0");
const m = c - r, C = l - o, I = t * i - e * n, O = n * u + i * d, E = t * u + e * d, j = (u * m + d * C) / f, at = (u * C - d * m) / f, ct = -at, Ct = j, It = (r * O - c * E - I * C) / f, Tt = (o * O - l * E + I * m) / f;
return new b(j, at, ct, Ct, It, Tt);
}
static create(t) {
if (t instanceof b)
return t;
const { a: e, b: n, c: i, d: r, e: o, f: c } = t;
return new b(e, n, i, r, o, c);
}
toString() {
return `x: (${ht(this.a)}, ${ht(this.b)}), y: (${ht(this.c)}, ${ht(this.d)}), d: (${ht(this.e)}, ${ht(this.f)})`;
}
};
a(b, "identity", new b(1, 0, 0, 1, 0, 0));
let v = b;
class S {
constructor(t, e) {
this.propertyName = t, this.noopInstruction = e;
}
changeInstanceValue(t, e) {
return this.valuesAreEqual(t[this.propertyName], e) ? t : t.changeProperty(this.propertyName, e);
}
isEqualForInstances(t, e) {
return this.valuesAreEqual(t[this.propertyName], e[this.propertyName]);
}
getInstructionToChange(t, e) {
return this.valuesAreEqual(t[this.propertyName], e[this.propertyName]) ? this.noopInstruction : this.changeToNewValue(e[this.propertyName]);
}
valueIsTransformableForInstance(t) {
return !0;
}
}
const P = { execute() {
} };
class xi {
constructor(t) {
this.transformation = t;
}
execute(t, e) {
const { a: n, b: i, c: r, d: o, e: c, f: l } = e.getTransformationForInstruction(this.transformation);
t.setTransform(n, i, r, o, c, l);
}
}
class bi extends S {
valuesAreEqual(t, e) {
return t.equals(e);
}
changeToNewValue(t) {
return new xi(t);
}
}
const Xt = new bi("transformation", P);
class Oi {
constructor(t) {
this.viewBox = t;
}
getTransform() {
if (DOMMatrix) {
const t = this.viewBox.state.current.transformation;
return new DOMMatrix([
t.a,
t.b,
t.c,
t.d,
t.e,
t.f
]);
}
}
resetTransform() {
this.viewBox.changeState((t) => Xt.changeInstanceValue(t, v.identity));
}
rotate(t) {
this.addTransformation(v.rotation(0, 0, t));
}
scale(t, e) {
this.addTransformation(new v(t, 0, 0, e, 0, 0));
}
setTransform(t, e, n, i, r, o) {
let c, l, u, d, f, m;
typeof t == "number" ? (c = t, l = e, u = n, d = i, f = r, m = o) : t.a !== void 0 ? (c = t.a, l = t.b, u = t.c, d = t.d, f = t.e, m = t.f) : (c = t.m11, l = t.m12, u = t.m21, d = t.m22, f = t.m41, m = t.m42), this.viewBox.changeState((C) => Xt.changeInstanceValue(C, new v(c, l, u, d, f, m)));
}
transform(t, e, n, i, r, o) {
this.addTransformation(new v(t, e, n, i, r, o));
}
translate(t, e) {
this.addTransformation(v.translation(t, e));
}
addTransformation(t) {
const e = this.viewBox.state.current.transformation, n = t.before(e);
this.viewBox.changeState((i) => Xt.changeInstanceValue(i, n));
}
}
class x {
constructor(t, e) {
this.propName = t, this.value = e;
}
execute(t) {
t[this.propName] = this.value;
}
}
class Li extends S {
valuesAreEqual(t, e) {
return t === e;
}
changeToNewValue(t) {
return new x("globalAlpha", t);
}
}
const Dn = new Li("globalAlpha", P);
class Bi extends S {
valuesAreEqual(t, e) {
return t === e;
}
changeToNewValue(t) {
return new x("globalCompositeOperation", t);
}
}
const En = new Bi("globalCompositeOperation", P);
class Ai {
constructor(t) {
this.viewBox = t;
}
get globalAlpha() {
return this.viewBox.state.current.globalAlpha;
}
set globalAlpha(t) {
this.viewBox.changeState((e) => Dn.changeInstanceValue(e, t));
}
get globalCompositeOperation() {
return this.viewBox.state.current.globalCompositeOperation;
}
set globalCompositeOperation(t) {
this.viewBox.changeState((e) => En.changeInstanceValue(e, t));
}
}
class Di extends S {
valuesAreEqual(t, e) {
return t === e;
}
changeToNewValue(t) {
return new x("imageSmoothingEnabled", t);
}
}
const Rn = new Di("imageSmoothingEnabled", P);
class Ei extends S {
valuesAreEqual(t, e) {
return t === e;
}
changeToNewValue(t) {
return new x("imageSmoothingQuality", t);
}
}
const Fn = new Ei("imageSmoothingQuality", P);
class Ri {
constructor(t) {
this.viewBox = t;
}
get imageSmoothingEnabled() {
return this.viewBox.state.current.imageSmoothingEnabled;
}
set imageSmoothingEnabled(t) {
this.viewBox.changeState((e) => Rn.changeInstanceValue(e, t));
}
get imageSmoothingQuality() {
return this.viewBox.state.current.imageSmoothingQuality;
}
set imageSmoothingQuality(t) {
this.viewBox.changeState((e) => Fn.changeInstanceValue(e, t));
}
}
class $t {
}
class Wn extends $t {
constructor(t) {
super(), this.fillStrokeStyle = t;
}
setTransform(t) {
this.fillStrokeStyle.setTransform(t);
}
getInstructionToSetUntransformed(t) {
return new x(t, this.fillStrokeStyle);
}
getInstructionToSetTransformed(t) {
return new x(t, this.fillStrokeStyle);
}
}
class kn {
constructor(t) {
this.propName = t;
}
changeInstanceValue(t, e) {
return t.changeProperty(this.propName, e);
}
isEqualForInstances(t, e) {
return t[this.propName] === e[this.propName];
}
getInstructionToChange(t, e) {
const n = e[this.propName];
return this.isEqualForInstances(t, e) ? !(n instanceof $t) || t.fillAndStrokeStylesTransformed === e.fillAndStrokeStylesTransformed ? P : e.fillAndStrokeStylesTransformed ? n.getInstructionToSetTransformed(this.propName) : n.getInstructionToSetUntransformed(this.propName) : n instanceof $t ? e.fillAndStrokeStylesTransformed ? n.getInstructionToSetTransformed(this.propName) : n.getInstructionToSetUntransformed(this.propName) : new x(this.propName, n);
}
valueIsTransformableForInstance(t) {
return !(t[this.propName] instanceof Wn);
}
}
const Hn = new kn("fillStyle"), Vn = new kn("strokeStyle");
class Fi {
constructor(t) {
this.viewBox = t;
}
set fillStyle(t) {
this.viewBox.changeState((e) => Hn.changeInstanceValue(e, t));
}
set strokeStyle(t) {
this.viewBox.changeState((e) => Vn.changeInstanceValue(e, t));
}
createLinearGradient(t, e, n, i) {
return this.viewBox.createLinearGradient(t, e, n, i);
}
createPattern(t, e) {
return this.viewBox.createPattern(t, e);
}
createRadialGradient(t, e, n, i, r, o) {
return this.viewBox.createRadialGradient(t, e, n, i, r, o);
}
createConicGradient(t, e, n) {
return this.viewBox.createConicGradient(t, e, n);
}
}
class Wi extends S {
valuesAreEqual(t, e) {
return t === e;
}
changeToNewValue(t) {
return new x("shadowColor", t);
}
}
const Nn = new Wi("shadowColor", P);
class ki {
constructor(t) {
this.shadowOffset = t;
}
execute(t, e) {
const n = v.translation(this.shadowOffset.x, this.shadowOffset.y), i = e.translateInfiniteCanvasContextTransformationToBitmapTransformation(n), { x: r, y: o } = i.apply(h.origin);
t.shadowOffsetX = r, t.shadowOffsetY = o;
}
}
class Hi extends S {
changeToNewValue(t) {
return new ki(t);
}
valuesAreEqual(t, e) {
return t.x === e.x && t.y == e.y;
}
}
const Oe = new Hi("shadowOffset", P);
class Vi {
constructor(t) {
this.shadowBlur = t;
}
execute(t, e) {
const n = v.translation(this.shadowBlur, 0), r = e.translateInfiniteCanvasContextTransformationToBitmapTransformation(n).apply(h.origin).mod();
t.shadowBlur = r;
}
}
class Ni extends S {
changeToNewValue(t) {
return new Vi(t);
}
valuesAreEqual(t, e) {
return t === e;
}
}
const Mn = new Ni("shadowBlur", P);
class Mi {
constructor(t) {
this.viewBox = t;
}
get shadowBlur() {
return this.viewBox.state.current.shadowBlur;
}
set shadowBlur(t) {
this.viewBox.changeState((e) => Mn.changeInstanceValue(e, t));
}
get shadowOffsetX() {
return this.viewBox.state.current.shadowOffset.x;
}
set shadowOffsetX(t) {
const e = new h(t, this.viewBox.state.current.shadowOffset.y);
this.viewBox.changeState((n) => Oe.changeInstanceValue(n, e));
}
get shadowOffsetY() {
return this.viewBox.state.current.shadowOffset.y;
}
set shadowOffsetY(t) {
const e = new h(this.viewBox.state.current.shadowOffset.x, t);
this.viewBox.changeState((n) => Oe.changeInstanceValue(n, e));
}
get shadowColor() {
return this.viewBox.state.current.shadowColor;
}
set shadowColor(t) {
this.viewBox.changeState((e) => Nn.changeInstanceValue(e, t));
}
}
const qn = "[+-]?(?:\\d*\\.)?\\d+(?:e[+-]?\\d+)?", zn = "[+-]?(?:0*\\.)?0+(?:e[+-]?\\d+)?", Gn = "(?:ch|em|ex|ic|rem|vh|vw|vmax|vmin|vb|vi|cqw|cqh|cqi|cqb|cqmin|cqmax|px|cm|mm|Q|in|pc|pt)", Ut = `(?:${zn}|${qn}${Gn})`, Yn = `blur\\((${Ut})\\)`, fn = "[^())\\s]+(?:\\([^)]*?\\))?", Xn = `drop-shadow\\((${Ut})\\s+(${Ut})\\s*?(?:(?:(${Ut})\\s*?(${fn})?)|(${fn}))?\\)`, gn = `${Yn}|${Xn}`;
function H(s, t) {
const e = s.match(new RegExp(`(?:(${zn})|(${qn})(${Gn}))`));
return e[1] ? 0 : t.getNumberOfPixels(Number.parseFloat(e[2]), e[3]);
}
class mn {
constructor(t) {
this.stringRepresentation = t;
}
toTransformedString() {
return this.stringRepresentation;
}
getShadowOffset() {
return null;
}
}
class ke {
constructor(t, e) {
this.stringRepresentation = t, this.size = e;
}
toTransformedString(t) {
return `blur(${t.translateInfiniteCanvasContextTransformationToBitmapTransformation(v.translation(this.size, 0)).apply(h.origin).mod()}px)`;
}
getShadowOffset() {
return null;
}
static tryCreate(t, e) {
const n = t.match(new RegExp(Yn));
return n === null ? null : new ke(t, H(n[1], e));
}
}
class ut {
constructor(t, e, n, i, r) {
this.stringRepresentation = t, this.offsetX = e, this.offsetY = n, this.blurRadius = i, this.color = r;
}
toTransformedString(t) {
const e = t.translateInfiniteCanvasContextTransformationToBitmapTransformation(v.translation(this.offsetX, this.offsetY)), { x: n, y: i } = e.apply(h.origin);
if (this.blurRadius !== null) {
const o = t.translateInfiniteCanvasContextTransformationToBitmapTransformation(v.translation(this.blurRadius, 0)).apply(h.origin).mod();
return this.color ? `drop-shadow(${n}px ${i}px ${o}px ${this.color})` : `drop-shadow(${n}px ${i}px ${o}px)`;
}
return this.color ? `drop-shadow(${n}px ${i}px ${this.color})` : `drop-shadow(${n}px ${i}px)`;
}
getShadowOffset() {
return new h(this.offsetX, this.offsetY);
}
static tryCreate(t, e) {
const n = t.match(new RegExp(Xn));
return n === null ? null : n[5] ? new ut(
t,
H(n[1], e),
H(n[2], e),
null,
n[5]
) : n[4] ? new ut(
t,
H(n[1], e),
H(n[2], e),
H(n[3], e),
n[4]
) : n[3] ? new ut(
t,
H(n[1], e),
H(n[2], e),
H(n[3], e),
null
) : new ut(
t,
H(n[1], e),
H(n[2], e),
null,
null
);
}
}
const xt = class xt {
constructor(t, e) {
this.stringRepresentation = t, this.parts = e;
}
toString() {
return this.parts.map((t) => t.stringRepresentation).join(" ");
}
toTransformedString(t) {
return this.parts.map((e) => e.toTransformedString(t)).join(" ");
}
getShadowOffset() {
for (const t of this.parts) {
const e = t.getShadowOffset();
if (e !== null)
return e;
}
return null;
}
static create(t, e) {
const i = t.match(new RegExp(`${gn}|((?!\\s|${gn}).)+`, "g")).map((r) => this.createPart(r, e));
return new xt(t, i);
}
static createPart(t, e) {
let n = ke.tryCreate(t, e);
return n !== null || (n = ut.tryCreate(t, e), n != null) ? n : new mn(t);
}
};
a(xt, "none", new xt("none", [new mn("none")]));
let Kt = xt;
class qi {
constructor(t) {
this.value = t;
}
execute(t, e) {
t.filter = this.value.toTransformedString(e);
}
}
class zi extends S {
valuesAreEqual(t, e) {
return t.stringRepresentation === e.stringRepresentation;
}
changeToNewValue(t) {
return new qi(t);
}
}
const Un = new zi("filter", P);
class Gi {
constructor(t, e) {
this.viewBox = t, this.cssLengthConverterFactory = e;
}
get filter() {
return this.viewBox.state.current.filter.stringRepresentation;
}
set filter(t) {
const e = Kt.create(t, this.cssLengthConverterFactory.create());
this.viewBox.changeState((n) => Un.changeInstanceValue(n, e));
}
}
class Yi {
constructor(t) {
this.fillRule = t;
}
execute(t) {
t.fill(this.fillRule);
}
}
class jt {
execute(t) {
t.fill();
}
static create(t) {
return t === void 0 ? Xi : new Yi(t);
}
}
const Xi = new jt();
class Ui {
constructor(t) {
this.viewBox = t;
}
clearRect(t, e, n, i) {
this.viewBox.clearArea(t, e, n, i);
}
fillRect(t, e, n, i) {
const r = jt.create();
this.viewBox.fillRect(t, e, n, i, r);
}
strokeRect(t, e, n, i) {
this.viewBox.strokeRect(t, e, n, i);
}
}
class $i {
constructor(t) {
this.fillRule = t;
}
execute(t) {
t.clip(this.fillRule);
}
}
class Le {
execute(t) {
t.clip();
}
static create(t) {
return t === void 0 ? Ki : new $i(t);
}
}
const Ki = new Le();
class ji {
constructor(t) {
this.viewBox = t;
}
isFillRule(t) {
return t === "evenodd" || t === "nonzero";
}
beginPath() {
this.viewBox.beginPath();
}
clip(t, e) {
const n = this.isFillRule(t) ? Le.create(t) : Le.create();
this.viewBox.clipPath(n);
}
fill(t, e) {
if ((!t || this.isFillRule(t)) && !this.viewBox.currentPathCanBeFilled())
return;
const n = this.isFillRule(t) ? jt.create(t) : jt.create();
this.viewBox.fillPath(n);
}
isPointInPath(t, e, n, i) {
return !0;
}
isPointInStroke(t, e, n) {
return !0;
}
stroke(t) {
this.viewBox.strokePath();
}
}
class Qi {
drawFocusIfNeeded(t, e) {
}
scrollPathIntoView(t) {
}
}
var z = /* @__PURE__ */ ((s) => (s[s.None = 0] = "None", s[s.Relative = 1] = "Relative", s[s.Absolute = 2] = "Absolute", s))(z || {}), y = /* @__PURE__ */ ((s) => (s[s.Positive = 0] = "Positive", s[s.Negative = 1] = "Negative", s))(y || {});
const Qt = { direction: new h(0, 1) }, Jt = { direction: new h(0, -1) }, Zt = { direction: new h(-1, 0) }, _t = { direction: new h(1, 0) };
function Ji(s, t, e, n) {
const i = e.minus(s), r = n.cross(t), o = n.getPerpendicular().dot(i) / r;
return s.plus(t.scale(o));
}
class st {
constructor(t, e, n) {
a(this, "leftNormal");
a(this, "rightNormal");
this.point = t, this.leftHalfPlane = e, this.rightHalfPlane = n, this.leftNormal = e.normalTowardInterior, this.rightNormal = n.normalTowardInterior;
}
replaceLeftHalfPlane(t) {
return new st(this.point, t, this.rightHalfPlane);
}
replaceRightHalfPlane(t) {
return new st(this.point, this.leftHalfPlane, t);
}
isContainedByHalfPlaneWithNormal(t) {
return t.isInSmallerAngleBetweenPoints(this.leftNormal, this.rightNormal);
}
containsPoint(t) {
return this.leftHalfPlane.containsPoint(t) && this.rightHalfPlane.containsPoint(t);
}
containsLineSegmentWithDirection(t) {
return this.containsPoint(this.point.plus(t)) || this.containsPoint(this.point.minus(t));
}
isContainedByVertex(t) {
return this.isContainedByHalfPlaneWithNormal(t.leftNormal) && this.isContainedByHalfPlaneWithNormal(t.rightNormal);
}
getContainingHalfPlaneThroughPoint(t) {
let e = t.minus(this.point).getPerpendicular();
if (e.cross(this.leftHalfPlane.normalTowardInterior) === 0)
return this.leftHalfPlane;
if (e.cross(this.rightHalfPlane.normalTowardInterior) === 0)
return this.rightHalfPlane;
const n = this.leftNormal.plus(this.rightNormal);
return e.dot(n) <= 0 && (e = e.scale(-1)), new w(t, e);
}
static create(t, e, n) {
return e.normalTowardInterior.cross(n.normalTowardInterior) >= 0 ? new st(t, e, n) : new st(t, n, e);
}
}
class w {
constructor(t, e) {
a(this, "lengthOfNormal");
this.base = t, this.normalTowardInterior = e, this.lengthOfNormal = e.mod();
}
getDistanceFromEdge(t) {
return t.minus(this.base).dot(this.normalTowardInterior) / this.lengthOfNormal;
}
transform(t) {
const e = t.apply(this.base), n = t.apply(this.base.plus(this.normalTowardInterior.getPerpendicular())), i = t.apply(this.base.plus(this.normalTowardInterior));
return w.throughPointsAndContainingPoint(e, n, i);
}
complement() {
return new w(this.base, this.normalTowardInterior.scale(-1));
}
expandByDistance(t) {
const e = this.base.plus(this.normalTowardInterior.scale(-t / this.normalTowardInterior.mod()));
return new w(e, this.normalTowardInterior);
}
expandToIncludePoint(t) {
return this.containsPoint(t) ? this : new w(t, this.normalTowardInterior);
}
containsPoint(t) {
return this.getDistanceFromEdge(t) >= 0;
}
interiorContainsPoint(t) {
return this.getDistanceFromEdge(t) > 0;
}
containsInfinityInDirection(t) {
return t.dot(this.normalTowardInterior) >= 0;
}
isContainedByHalfPlane(t) {
return this.normalTowardInterior.inSameDirectionAs(t.normalTowardInterior) && t.getDistanceFromEdge(this.base) >= 0;
}
intersectWithLine(t, e) {
return {
point: Ji(this.base, this.normalTowardInterior.getPerpendicular(), t, e),
halfPlane: this
};
}
isParallelToLine(t, e) {
return this.normalTowardInterior.getPerpendicular().cross(e) === 0;
}
getIntersectionWith(t) {
const e = this.intersectWithLine(t.base, t.normalTowardInterior.getPerpendicular());
return st.create(e.point, this, t);
}
static throughPointsAndContainingPoint(t, e, n) {
const i = w.withBorderPoints(t, e);
for (let r of i)
if (r.containsPoint(n))
return r;
}
static withBorderPointAndInfinityInDirection(t, e) {
return w.withBorderPoints(t, t.plus(e));
}
static withBorderPoints(t, e) {
const n = e.minus(t).getPerpendicular();
return [
new w(t, n),
new w(t, n.scale(-1))
];
}
}
class Zi {
getVertices() {
return [];
}
expandToIncludePoint(t) {
return this;
}
expandToIncludePolygon(t) {
return this;
}
expandToIncludeInfinityInDirection(t) {
return this;
}
expandByDistance(t) {
return this;
}
intersects(t) {
return !0;
}
expandToInclude(t) {
return this;
}
transform(t) {
return this;
}
intersectWithLineSegment(t) {
return t;
}
contains(t) {
return !0;
}
intersectWith(t) {
return t;
}
join(t) {
return this;
}
intersectWithRay(t) {
return t;
}
intersectWithLine(t) {
return t;
}
intersectWithConvexPolygon(t) {
return t;
}
isContainedByRay(t) {
return !1;
}
isContainedByLineSegment(t) {
return !1;
}
isContainedByLine(t) {
return !1;
}
isContainedByConvexPolygon(t) {
return !1;
}
intersectsRay(t) {
return !0;
}
intersectsLineSegment(t) {
return !0;
}
intersectsLine(t) {
return !0;
}
intersectsConvexPolygon(t) {
return !0;
}
}
const vt = new Zi();
class _i {
getVertices() {
return [];
}
intersectWith(t) {
return this;
}
join(t) {
return t;
}
intersectWithConvexPolygon(t) {
return this;
}
intersects(t) {
return !1;
}
intersectWithLineSegment(t) {
return this;
}
intersectWithRay(t) {
return this;
}
intersectWithLine(t) {
return this;
}
expandToInclude(t) {
return t;
}
transform(t) {
return this;
}
contains(t) {
return !1;
}
isContainedByConvexPolygon(t) {
return !0;
}
isContainedByRay(t) {
return !0;
}
isContainedByLineSegment(t) {
return !0;
}
isContainedByLine(t) {
return !0;
}
intersectsRay(t) {
return !1;
}
intersectsConvexPolygon(t) {
return !1;
}
intersectsLineSegment(t) {
return !1;
}
intersectsLine(t) {
return !1;
}
expandByDistance(t) {
return this;
}
expandToIncludePoint(t) {
return this;
}
expandToIncludeInfinityInDirection(t) {
return this;
}
expandToIncludePolygon(t) {
return t;
}
}
const A = new _i();
class p {
constructor(t, e) {
a(this, "halfPlanes");
this.vertices = e, this.halfPlanes = t, this.vertices = this.vertices || p.getVertices(this.halfPlanes);
}
findVertex(t) {
for (let e of this.vertices)
if (e.point.equals(t))
return e;
}
intersects(t) {
return t.intersectsConvexPolygon(this);
}
intersectWith(t) {
return t.intersectWithConvexPolygon(this);
}
join(t) {
if (this.contains(t))
return this;
if (t.contains(this))
return t;
let e = t;
for (let n of this.vertices)
e = e.expandToIncludePoint(n.point);
for (let n of this.getPointsAtInfinityFromHalfPlanes())
this.containsInfinityInDirection(n) && (e = e.expandToIncludeInfinityInDirection(n));
return e;
}
intersectWithRay(t) {
return t.intersectWithConvexPolygon(this);
}
intersectWithLine(t) {
return t.intersectWithConvexPolygon(this);
}
intersectWithLineSegment(t) {
return t.intersectWithConvexPolygon(this);
}
contains(t) {
return t.isContainedByConvexPolygon(this);
}
containsHalfPlane(t) {
for (let e of this.halfPlanes)
if (!t.isContainedByHalfPlane(e))
return !1;
return !0;
}
isContainedByHalfPlane(t) {
for (let n of this.vertices)
if (!t.containsPoint(n.point))
return !1;
const e = t.complement();
for (let n of this.halfPlanes)
if (n.isContainedByHalfPlane(t))
return !0;
for (let n of this.halfPlanes) {
const i = this.getVerticesOnHalfPlane(n);
if (i.length <= 1 && (n.isContainedByHalfPlane(e) || e.isContainedByHalfPlane(n)))
return !1;
const r = n.getIntersectionWith(t), o = i.find((c) => c.point.equals(r.point));
if (o) {
if (!o.isContainedByHalfPlaneWithNormal(t.normalTowardInterior))
return !1;
} else {
if (i.length === 0)
return !1;
if (this.containsPoint(r.point))
return !1;
}
}
return !this.containsHalfPlane(t);
}
getVertices() {
return this.vertices.map((t) => t.point);
}
expandToIncludePoint(t) {
if (this.vertices.length === 0) {
const d = this.halfPlanes.map((f) => f.expandToIncludePoint(t));
return new p(d);
}
const e = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ new Set();
let i = null, r = null;
const o = [], c = /* @__PURE__ */ new Set();
for (const d of this.vertices) {
const f = d.leftHalfPlane;
n.has(f) ? n.delete(f) : e.add(f);
const m = d.rightHalfPlane;
if (e.has(m) ? e.delete(m) : n.add(m), f.containsPoint(t)) {
if (c.add(f), m.containsPoint(t)) {
c.add(m), o.push(d);
continue;
}
i = d;
continue;
}
m.containsPoint(t) && (c.add(m), r = d);
}
if (o.length === this.vertices.length)
return this;
let l, u;
if (i === null) {
const d = [...e][0];
if (!d)
return this;
l = d.expandToIncludePoint(t);
} else
l = i.getContainingHalfPlaneThroughPoint(t), l !== i.leftHalfPlane && o.push(i.replaceRightHalfPlane(l));
if (r === null) {
const d = [...n][0];
if (!d)
return this;
u = d.expandToIncludePoint(t);
} else
u = r.getContainingHalfPlaneThroughPoint(t), u !== r.rightHalfPlane && o.push(r.replaceLeftHalfPlane(u));
return c.add(l), c.add(u), o.push(new st(t, l, u)), new p([...c], o);
}
expandToIncludeInfinityInDirection(t) {
if (this.containsInfinityInDirection(t))
return this;
let e = this.halfPlanes.filter((n) => n.containsInfinityInDirection(t)).concat(this.getTangentPlanesThroughInfinityInDirection(t));
return e = p.getHalfPlanesNotContainingAnyOther(e), e.length === 0 ? vt : new p(e);
}
getIntersectionsWithLine(t, e) {
const n = [];
for (let i of this.halfPlanes) {
if (i.isParallelToLine(t, e))
continue;
const r = i.intersectWithLine(t, e), o = this.findVertex(r.point);
o && !o.containsLineSegmentWithDirection(e) || this.containsPoint(r.point) && n.push(r);
}
return n;
}
expandByDistance(t) {
return new p(this.halfPlanes.map((e) => e.expandByDistance(t)));
}
transform(t) {
return new p(this.halfPlanes.map((e) => e.transform(t)));
}
intersectWithConvexPolygon(t) {
if (t.isContainedByConvexPolygon(this))
return t;
if (this.isContainedByConvexPolygon(t))
return this;
if (this.isOutsideConvexPolygon(t))
return A;
const e = p.getHalfPlanesNotContainingAnyOther(this.halfPlanes.concat(t.halfPlanes)), r = p.groupVerticesByPoint(p.getVertices(e)).map((c) => p.getVerticesNotContainingAnyOther(c)).reduce((c, l) => c.concat(l), []);
if (r.length === 0)
return new p(e);
const o = p.getHalfPlanes(r);
return new p(o);
}
containsInfinityInDirection(t) {
for (let e of this.halfPlanes)
if (!e.containsInfinityInDirection(t))
return !1;
return !0;
}
containsPoint(t) {
for (let e of this.halfPlanes)
if (!e.containsPoint(t))
return !1;
return !0;
}
intersectsRay(t) {
return t.intersectsConvexPolygon(this);
}
intersectsLineSegment(t) {
return t.intersectsConvexPolygon(this);
}
intersectsLine(t) {
return t.intersectsConvexPolygon(this);
}
intersectsConvexPolygon(t) {
return this.isContainedByConvexPolygon(t) || t.isContainedByConvexPolygon(this) ? !0 : !this.isOutsideConvexPolygon(t);
}
isOutsideConvexPolygon(t) {
for (let e of t.halfPlanes)
if (this.isContainedByHalfPlane(e.complement()))
return !0;
for (let e of this.halfPlanes)
if (t.isContainedByHalfPlane(e.complement()))
return !0;
return !1;
}
getVerticesOnHalfPlane(t) {
const e = [];
for (let n of this.vertices)
(n.leftHalfPlane === t || n.rightHalfPlane === t) && e.push(n);
return e;
}
hasAtMostOneVertex(t) {
let e = 0;
for (let n of this.vertices)
if ((n.leftHalfPlane === t || n.rightHalfPlane === t) && (e++, e > 1))
return !1;
return !0;
}
getTangentPlanesThroughInfinityInDirection(t) {
const e = [];
for (let n of this.vertices) {
const i = w.withBorderPointAndInfinityInDirection(n.point, t);
for (let r of i)
this.isContainedByHalfPlane(r) && e.push(r);
}
return e;
}
getPointsAtInfinityFromHalfPlanes() {
const t = [];
for (let e of this.halfPlanes) {
const n = e.normalTowardInterior, i = n.getPerpendicular();
t.push(n), t.push(i), t.push(i.scale(-1));
}
return t;
}
isContainedByRay(t) {
return !1;
}
isContainedByLineSegment(t) {
return !1;
}
isContainedByLine(t) {
return !1;
}
isContainedByConvexPolygon(t) {
for (let e of t.halfPlanes)
if (!this.isContainedByHalfPlane(e))
return !1;
return !0;
}
static getHalfPlanes(t) {
const e = [];
for (let n of t)
e.indexOf(n.leftHalfPlane) === -1 && e.push(n.leftHalfPlane), e.indexOf(n.rightHalfPlane) === -1 && e.push(n.rightHalfPlane);
return e;
}
static getVerticesNotContainingAnyOther(t) {
const e = [];
for (let n = 0; n < t.length; n++) {
let i = !0;
for (let r = 0; r < t.length; r++)
if (n !== r && t[r].isContainedByVertex(t[n])) {
i = !1;
break;
}
i && e.push(t[n]);
}
return e;
}
static getHalfPlanesNotContainingAnyOther(t) {
const e = [];
for (let n of t) {
let i = !0;
for (let r of e)
if (r.isContainedByHalfPlane(n)) {
i = !1;
break;
}
i && e.push(n);
}
return e;
}
static groupVerticesByPoint(t) {
const e = [];
for (let n of t) {
let i;
for (let r of e)
if (r[0].point.equals(n.point)) {
i = r;
break;
}
i ? i.push(n) : e.push([n]);
}
return e;
}
static getVertices(t) {
const e = [];
for (let n = 0; n < t.length; n++)
for (let i = n + 1; i < t.length; i++) {
const r = t[n], o = t[i];
if (r.complement().isContainedByHalfPlane(o))
continue;
const c = r.getIntersectionWith(o);
let l = !0;
for (let u = 0; u < t.length; u++) {
if (u === n || u === i)
continue;
if (!t[u].containsPoint(c.point)) {
l = !1;
break;
}
}
l && e.push(c);
}
return e;
}
static createTriangleWithInfinityInTwoDirections(t, e, n) {
const i = e.getPerpendicular(), r = n.getPerpendicular();
return e.cross(n) < 0 ? new p([
new w(t, i.scale(-1)),
new w(t, r)
]) : new p([
new w(t, i),
new w(t, r.scale(-1))
]);
}
static createFromHalfPlane(t) {
return new p([t]);
}
static createTriangleWithInfinityInDirection(t, e, n) {
const i = e.minus(t).projectOn(n.getPerpendicular());
return new p([
new w(t, i),
new w(e, i.scale(-1)),
w.throughPointsAndContainingPoint(t, e, t.plus(n))
]);
}
static createTriangle(t, e, n) {
return new p([
w.throughPointsAndContainingPoint(t, e, n),
w.throughPointsAndContainingPoint(t, n, e),
w.throughPointsAndContainingPoint(e, n, t)
]);
}
}
class ts {
constructor(t) {
this.instructions = t;
}
execute(t, e, n) {
for (const i of this.instructions)
i.execute(t, e, n);
}
}
class es {
constructor(t, e) {
this.instruction = t, this.tempStateInstruction = e;
}
execute(t, e) {
t.save(), this.tempStateInstruction.execute(t, e), this.instruction.execute(t, e), t.restore();
}
}
class ns {
constructor(t) {
this.getTransformation = t;
}
execute(t, e) {
const { a: n, b: i, c: r, d: o, e: c, f: l } = this.getTransformation(e);
t.setTransform(n, i, r, o, c, l);
}
}
class is {
constructor(t) {
this.getTransformation = t;
}
execute(t, e) {
const { a: n, b: i, c: r, d: o, e: c, f: l } = this.getTransformation(e);
t.transform(n, i, r, o, c, l);
}
}
class ss {
constructor(t, e) {
this.instruction = t, this.infinity = e;
}
execute(t, e) {
this.instruction.execute(t, e, this.infinity);
}
}
function rs(s, t) {
return t ? new es(s, t) : s;
}
function os(s, t) {
return new ss(s, t);
}
function F(...s) {
return new ts(s);
}
function as(s) {
return s === z.Relative ? new is((t) => t.getBitmapTransformationToTransformedInfiniteCanvasContext()) : s === z.Absolute ? new ns((t) => t.getBitmapTransformationToInfiniteCanvasContext()) : null;
}
function cs(s, t) {
let e = s.area;
return e && t.lineWidth > 0 && (e = e.expandByDistance(t.lineWidth / 2)), e;
}
function hs(s) {
return {
lineWidth: s.current.getMaximumLineWidth(),
lineDashPeriod: s.current.getLineDashPeriod(),
shadowOffsets: s.current.getShadowOffsets()
};
}
function ls(s) {
return {
lineWidth: 0,
lineDashPeriod: 0,
shadowOffsets: s.current.getShadowOffsets()
};
}
class M {
constructor(t, e, n, i, r, o, c) {
this.instruction = t, this.area = e, this.build = n, this.takeClippingRegionIntoAccount = i, this.transformationKind = r, this.state = o, this.tempState = c;
}
static forStrokingPath(t, e, n) {
return M.forPath(t, e, hs, n);
}
static forFillingPath(t, e, n) {
return M.forPath(t, e, ls, n);
}
static forPath(t, e, n, i) {
const r = e.current.isTransformable(), o = r ? z.None : z.Relative, c = e.currentlyTransformed(r), l = n(c), u = i(c), d = cs(u, l);
return new M(
t,
d,
(f) => u.drawPath(f, c, l),
!0,
o,
c
);
}
getDrawnArea() {
let t = this.area;
const e = this.state;
if (e.current.shadowBlur !== 0 || !e.current.shadowOffset.equals(h.origin)) {
const n = t.expandByDistance(e.current.shadowBlur).transform(v.translation(e.current.shadowOffset.x, e.current.shadowOffset.y));
t = t.join(n);
}
return e.current.clippingRegion && this.takeClippingRegionIntoAccount && (t = t.intersectWith(e.current.clippingRegion)), t;
}
getModifiedInstruction() {
let t = as(this.transformationKind);
if (this.tempState) {
const n = this.takeClippingRegionIntoAccount ? this.state.getInstructionToConvertToStateWithClippedPath(this.tempState) : this.state.getInstructionToConvertToState(this.tempState);
t = F(t, n);
}
return rs(this.instruction, t);
}
}
class He {
constructor(t) {
a(this, "added", []);
a(this, "addedLast");
this.initiallyWithState = t;
}
get length() {
return this.added.length;
}
get currentlyWithState() {
return this.addedLast ? this.addedLast : this.initiallyWithState;
}
reconstructState(t, e) {
e.setInitialState(t);
}
get stateOfFirstInstruction() {
return this.initiallyWithState.stateOfFirstInstruction;
}
get state() {
return this.currentlyWithState.state;
}
get initialState() {
return this.initiallyWithState.initialState;
}
addClippedPath(t) {
this.currentlyWithState.addClippedPath(t);
}
add(t) {
this.added.push(t), this.addedLast = t;
}
removeAll(t) {
let e;
for (; (e = this.added.findIndex(t)) > -1; )
this.removeAtIndex(e);
}
contains(t) {
return !!this.added.find(t);
}
setInitialState(t) {
this.initiallyWithState.setInitialState(t);
}
setInitialStateWithClippedPaths(t) {
this.initiallyWithState.setInitialStateWithClippedPaths(t);
}
beforeIndex(t) {
return t === 0 ? this.initiallyWithState.state : this.added[t - 1].state;
}
removeAtIndex(t) {
t === this.added.length - 1 ? this.added.length === 1 ? this.addedLast = void 0 : this.addedLast = this.added[t - 1] : this.reconstructState(this.beforeIndex(t), this.added[t + 1]), this.added.splice(t, 1);
}
}
class Ve {
constructor(t, e) {
a(this, "stateConversion");
this.initialState = t, this.state = e, this.stateConversion = P;
}
setInitialState(t) {
this.initialState = t;
const e = this.initialState.getInstructionToConvertToState(this.state);
this.stateConversion = e;
}
get stateOfFirstInstruction() {
return this.state;
}
addClippedPath(t) {
this.state = this.state.withClippedPath(t);
}
setInitialStateWithClippedPaths(t) {
this.initialState = t;
const e = this.initialState.getInstructionToConvertToStateWithClippedPath(this.state);
this.stateConversion = e;
}
}
class K extends Ve {
constructor(t, e, n, i) {
super(t, e), this.instruction = n, this.stateConversion = i;
}
execute(t, e) {
this.stateConversion && this.stateConversion.execute(t, e), this.instruction.execute(t, e);
}
static create(t, e) {
return new K(t, t, e, P);
}
}
class pt extends Ve {
constructor(t, e, n, i) {
super(t, e), this.instruction = n, this.stateConversion = i;
}
makeExecutable() {
return new K(this.initialState, this.state, this.instruction, this.stateConversion);
}
static create(t, e) {
return new pt(t, t, e, P);
}
}
function T(s) {
return s.direction !== void 0;
}
function Z(s, t) {
return T(s) ? t.applyToPointAtInfinity(s) : t.apply(s);
}
class us {
constructor(t, e) {
this.areaBuilder = t, this.transformation = e;
}
addPosition(t) {
this.areaBuilder.addPosition(Z(t, this.transformation));
}
}
class Ne {
constructor(t, e) {
this.base = t, this.direction = e;
}
pointIsOnSameLine(t) {
return t.minus(this.base).cross(this.direction) === 0;
}
comesBefore(t, e) {
return e.minus(t).dot(this.direction) >= 0;
}
lineSegmentIsOnSameLine(t) {
return this.direction.cross(t.direction) === 0 && this.pointIsOnSameLine(t.point1);
}
expandLineByDistance(t) {
const e = this.direction.getPerpendicular(), n = new w(this.base, e).expandByDistance(t), i = new w(this.base, e.scale(-1)).expandByDistance(t);
return new p([n, i]);
}
getPointsInSameDirection(t, e) {
return this.comesBefore(e, t) ? { point1: e, point2: t } : { point1: t, point2: e };
}
pointIsBetweenPoints(t, e, n) {
return t.minus(e).dot(this.direction) * t.minus(n).dot(this.direction) <= 0;
}
intersectsConvexPolygon(t) {
if (this.isContainedByConvexPolygon(t))
return !0;
const e = t.getIntersectionsWithLine(this.base, this.direction);
for (let n of e)
if (this.interiorContainsPoint(n.point))
return !0;
return !1;
}
}
class le extends Ne {
getVertices() {
return [];
}
intersectWith(t) {
return t.intersectWithLine(this);
}
join(t) {
return t.expandToIncludeInfinityInDirection(this.direction).expandToIncludeInfinityInDirection(this.direction.scale(-1));
}
intersectWithConvexPolygon(t) {
if (!this.intersectsConvexPolygon(t))
return A;
if (this.isContainedByConvexPolygon(t))
return this;
const e = t.getIntersectionsWithLine(this.base, this.direction);
let n, i;
for (let r of e)
(!n && !i || !n && this.comesBefore(r.point, i) || !i && this.comesBefore(n, r.point) || n && i && this.pointIsBetweenPoints(r.point, n, i)) && (r.halfPlane.normalTowardInterior.dot(this.direction) > 0 ? n = r.point : i = r.point);
return n && i ? new R(n, i) : n ? new q(n, this.direction) : new q(i, this.direction.scale(-1));
}
intersectWithLine(t) {
return this.intersectsLine(t) ? this : A;
}
intersectWithLineSegment(t) {
return this.lineSegmentIsOnSameLine(t) ? t : A;
}
intersectWithRay(t) {
return this.intersectsRay(t) ? t : A;
}
isContainedByConvexPolygon(t) {
return t.containsPoint(this.base) && t.containsInfinityInDirection(this.direction) && t.containsInfinityInDirection(this.direction.scale(-1));
}
isContainedByLine(t) {
return this.intersectsSubsetOfLine(t);
}
isContainedByLineSegment(t) {
return !1;
}
isContainedByRay(t) {
return !1;
}
contains(t) {
return t.isContainedByLine(this);
}
intersectsLine(t) {
return this.intersectsSubsetOfLine(t);
}
intersectsSubsetOfLine(t) {
return this.pointIsOnSameLine(t.base) && this.direction.cross(t.direction) === 0;
}
intersectsLineSegment(t) {
return this.lineSegmentIsOnSameLine(t);
}
intersectsRay(t) {
return this.intersectsSubsetOfLine(t);
}
intersects(t) {
return t.intersectsLine(this);
}
expandToIncludePoint(t) {
return this.pointIsOnSameLine(t) ? this : p.createTriangleWithInfinityInDirection(this.base, t, this.direction).expandToIncludeInfinityInDirection(this.direction.scale(-1));
}
expandByDistance(t) {
return this.expandLineByDistance(t);
}
expandToIncludeInfinityInDirection(t) {
const e = t.cross(this.direction), n = this.direction.getPerpendicular();
return e === 0 ? this : e > 0 ? p.createFromHalfPlane(new w(this.base, n.scale(-1))) : p.createFromHalfPlane(new w(this.base, n));
}
transform(t) {
const e = t.apply(this.base);
return new le(e, t.apply(this.base.plus(this.direction)).minus(e));
}
interiorContainsPoint(t) {
return this.pointIsOnSameLine(t);
}
}
class q extends Ne {
getVertices() {
return [this.base];
}
intersectWith(t) {
return t.intersectWithRay(this);
}
join(t) {
return t.expandToIncludePoint(this.base).expandToIncludeInfinityInDirection(this.direction);
}
intersectWithConvexPolygon(t) {
if (!this.intersectsConvexPolygon(t))
return A;
if (this.isContainedByConvexPolygon(t))
return this;
const e = t.getIntersectionsWithLine(this.base, this.direction);
let n = this.base, i;
for (let r of e)
(!i && this.comesBefore(n, r.point) || i && this.pointIsBetweenPoints(r.point, n, i)) && (r.halfPlane.normalTowardInterior.dot(this.direction) > 0 ? n = r.point : i = r.point);
return i ? new R(n, i) : new q(n, this.direction);
}
intersectWithRay(t) {
return this.isContainedByRay(t) ? this : t.isContainedByRay(this) ? t : this.interiorContainsPoint(t.base) ? new R(this.base, t.base) : A;
}
intersectWithLine(t) {
return t.intersectWithRay(this);
}
intersectWithLineSegment(t) {
if (t.isContainedByRay(this))
return t;
if (!this.lineSegmentIsOnSameLine(t))
return A;
let { point2: e } = this.getPointsInSameDirection(t.point1, t.point2);
return this.comesBefore(e, this.base) ? A : new R(this.base, e);
}
isContainedByConvexPolygon(t) {
return t.containsPoint(this.base) && t.containsInfinityInDirection(this.direction);
}
isContainedByRay(t) {
return t.containsPoint(this.base) && t.containsInfinityInDirection(this.direction);
}
isContainedByLine(t) {
return t.intersectsSubsetOfLine(this);
}
isContainedByLineSegment(t) {
return !1;
}
contains(t) {
return t.isContainedByRay(this);
}
intersectsRay(t) {
return this.isContainedByRay(t) || t.isContainedByRay(this) || this.interiorContainsPoint(t.base);
}
intersectsLine(t) {
return t.intersectsSubsetOfLine(this);
}
intersectsLineSegment(t) {
if (t.isContainedByRay(this))
return !0;
if (!this.lineSegmentIsOnSameLine(t))
return !1;
let { point2: e } = this.getPointsInSameDirection(t.point1, t.point2);
return !this.comesBefore(e, this.base);
}
intersects(t) {
return t.intersectsRay(this);
}
expandToIncludePoint(t) {
return this.containsPoint(t) ? this : this.pointIsOnSameLine(t) ? new q(t, this.direction) : p.createTriangleWithInfinityInDirection(this.base, t, this.direction);
}
expandByDistance(t) {
const e = this.expandLineByDistance(t), n = new w(this.base, this.direction).expandByDistance(t);
return e.intersectWithConvexPolygon(new p([n]));
}
expandToIncludeInfinityInDirection(t) {
return t.inSameDirectionAs(this.direction) ? this : this.direction.cross(t) === 0 ? new le(this.base, this.direction) : p.createTriangleWithInfinityInTwoDirections(this.base, this.direction, t);
}
transform(t) {
const e = t.apply(this.base);
return new q(e, t.apply(this.base.plus(this.direction)).minus(e));
}
interiorContainsPoint(t) {
return this.pointIsOnSameLine(t) && !this.comesBefore(t, this.base);
}
containsInfinityInDirection(t) {
return this.direction.inSameDirectionAs(t);
}
containsPoint(t) {
return this.pointIsOnSameLine(t) && this.comesBefore(this.base, t);
}
}
class R extends Ne {
constructor(t, e) {
super(t, e.minus(t)), this.point1 = t, this.point2 = e;
}
getVertices() {
return [this.point1, this.point2];
}
join(t) {
return t.expandToIncludePoint(this.point1).expandToIncludePoint(this.point2);
}
intersectWith(t) {
return t.intersectWithLineSegment(this);
}
intersectWithLineSegment(t) {
if (this.isContainedByLineSegment(t))
return this;
if (t.isContainedByLineSegment(this))
return t;
if (!this.lineSegmentIsOnSameLine(t))
return A;
let { point1: e, point2: n } = this.getPointsInSameDirection(t.point1, t.point2);
return this.comesBefore(n, this.point1) || this.comesBefore(this.point2, e) ? A : this.comesBefore(this.point1, e) ? new R(e, this.point2) : new R(this.point1, n);
}
intersectWithRay(t) {
return t.intersectWithLineSegment(this);
}
intersectWithLine(t) {
return t.intersectWithLineSegment(this);
}
isContainedByRay(t) {
return t.containsPoint(this.point1) && t.containsPoint(this.point2);
}
isContainedByLine(t) {
return t.intersectsSubsetOfLine(this);
}
isContainedByLineSegment(t) {
return t.containsPoint(this.point1) && t.containsPoint(this.point2);
}
intersectWithConvexPolygon(t) {
if (!this.intersectsConvexPolygon(t))
return A;
if (this.isContainedByConvexPolygon(t))
return this;
const e = t.getIntersectionsWithLine(this.point1, this.direction);
let n = this.point1, i = this.point2;
for (let r of e)
this.pointIsBetweenPoints(r.point, n, i) && (r.halfPlane.normalTowardInterior.dot(this.direction) > 0 ? n = r.point : i = r.point);
return new R(n, i);
}
isContainedByConvexPolygon(t) {
return t.containsPoint(this.point1) && t.containsPoint(this.point2);
}
contains(t) {
return t.isContainedByLineSegment(this);
}
pointIsStrictlyBetweenPoints(t, e, n) {
return t.minus(e).dot(this.direction) * t.minus(n).dot(this.direction) < 0;
}
containsPoint(t) {
return this.pointIsOnSameLine(t) && this.pointIsBetweenPoints(t, this.point1, this.point2);
}
interiorContainsPoint(t) {
return this.pointIsOnSameLine(t) && this.pointIsStrictlyBetweenPoints(t, this.point1, this.point2);
}
intersectsRay(t) {
return t.intersectsLineSegment(this);
}
intersectsLineSegment(t) {
if (this.isContainedByLineSegment(t) || t.isContainedByLineSegment(this))
return !0;
if (!this.lineSegmentIsOnSameLine(t))
return !1;
const { point1: e, point2: n } = this.getPointsInSameDirection(t.point1, t.point2);
return !this.comesBefore(n, this.point1) && !this.comesBefore(this.point2, e);
}
intersectsLine(t) {
return t.intersectsSubsetOfLine(this);
}
intersects(t) {
return t.intersectsLineSegment(this);
}
expandByDistance(t) {
const e = this.expandLineByDistance(t), n = new w(this.base, this.direction).expandByDistance(t