class RobinsonTriangle {
constructor({ points, type, gen = 0, subbed }) {
this.type = type;
this.points = points;
this.gen = gen;
this.subbed = false;
if (this.gen < depth) this.subdivide();
}
subdivide() {
if (this.subbed) return;
let [a, b, c] = this.points;
if (this.type === "acute") {
let p = lerpxy(a, b, 1 / PHI);
this.subbed = true;
let triA = new RobinsonTriangle({
type: "acute",
points: [c, p, b],
gen: this.gen + 1,
maxGen: this.maxGen
});
let triB = new RobinsonTriangle({
type: "obtuse",
points: [p, c, a],
gen: this.gen + 1,
maxGen: this.maxGen
});
mutable tris.push(...[triA, triB]);
} else {
let q = lerpxy(b, a, 1 / PHI);
let r = lerpxy(b, c, 1 / PHI);
const triA = new RobinsonTriangle({
type: "obtuse",
points: [r, c, a],
gen: this.gen + 1,
maxGen: this.maxGen
});
const triB = new RobinsonTriangle({
type: "obtuse",
points: [q, r, b],
gen: this.gen + 1,
maxGen: this.maxGen
});
const triC = new RobinsonTriangle({
type: "acute",
points: [r, q, a],
gen: this.gen + 1,
maxGen: this.maxGen
});
mutable tris.push(...[triA, triB, triC]);
}
this.subbed = true;
}
get path() {
let [a, b, c] = this.points;
return lineGen([b, a, c]);
}
get svg() {
let [a, b, c] = this.points;
return htl.svg`<g>
<path d="${lineGen([b, a, c])}" fill="${this.color}"></path>
</g>`;
}
flip() {
let [a, b, c] = this.points;
return new RobinsonTriangle({ type: this.type, points: [a, c, b] });
}
}