export function addLinesForTriangle( elements: Array<Renderable>, origin: Coords2d, sign: number) { let v0 = origin; let v1 = Coords2d.fromXY(origin.x + sign*triWidth, origin.y); let v2 = Coords2d.fromXY( origin.x + sign*triWidth/2, origin.y + sign * triHeight); elements.push(new Line(v0, v1)); elements.push(new Line(v1, v2)); elements.push(new Line(v2, v0)); elements.push(new Line( origin.plus(triBase[0].asOffsetFromOrigin().timesReal(sign)), origin.plus(triRight.asOffsetFromOrigin().timesReal(sign)))); let inner = [ triInner[0].asOffsetFromOrigin(), triInner[1].asOffsetFromOrigin()]; elements.push(new Line( origin.plus(triLeft.asOffsetFromOrigin().timesReal(sign)), origin.plus(inner[0].timesReal(sign)))); elements.push(new Line( origin.plus(triBase[2].asOffsetFromOrigin().timesReal(sign)), origin.plus(inner[1].timesReal(sign)))); return elements; }
center (): Coords2d { return this.origin.plus(this.size.asOffsetCoords().timesReal(0.5)); }
center (): Coords2d { return this.origin.plus(this.diagonal.timesReal(0.5)); }
export function addLinesForSquare( elements: Array<Renderable>, origin: Coords2d, angle: number) { // Extract the dimensions for the capstone triangle from its // simplest orientation in the base of the equilateral triangle. let bottom = capLeft; let top = 1 - capLeft; let sin = Math.sin(angle); let cos = Math.cos(angle); let basis = [ OffsetCoords2d.fromDxDy(cos, sin), OffsetCoords2d.fromDxDy(-sin, cos), ]; // All six corners in two adjacent grid squares, ordered // widdershins from the base. let corners = [ origin, origin.plus(basis[0]), origin.plus(basis[0].timesReal(2)), origin.plus(basis[0].timesReal(2)).plus(basis[1]), origin.plus(basis[0]).plus(basis[1]), origin.plus(basis[1])]; elements.push(new Line(corners[0], corners[2])); elements.push(new Line(corners[2], corners[3])); elements.push(new Line(corners[3], corners[5])); elements.push(new Line(corners[5], corners[0])); elements.push(new Line(corners[1], corners[4])); let vTop = [ corners[5].plus(basis[0].timesReal(top)), corners[3].plus(basis[0].timesReal(-bottom))]; let vBottom = [ corners[0].plus(basis[0].timesReal(bottom)), corners[2].plus(basis[0].timesReal(-top))]; let vLeft = corners[0].plus(basis[1].timesReal(0.5)); let vCenter = corners[1].plus(basis[1].timesReal(0.5)); let vRight = corners[2].plus(basis[1].timesReal(0.5)); let innerVecs = [ vLeft.asOffsetFrom(vBottom[0]), vRight.asOffsetFrom(vTop[1])]; let innerCoeff = triBase[0].x / (triWidth / 2); let vInner = [ vBottom[0].plus(innerVecs[0].timesReal(innerCoeff)), vTop[1].plus(innerVecs[1].timesReal(innerCoeff))]; elements.push(new Line(vLeft, vBottom[0])); elements.push(new Line(vInner[0], vCenter)); elements.push(new Line(vInner[0], vTop[0])); elements.push(new Line(vTop[1], vRight)); elements.push(new Line(vInner[1], vCenter)); elements.push(new Line(vInner[1], vBottom[1])); let vOutsideLeft = corners[5].plus(basis[0].timesReal(-capLeft)); elements.push(new Line(vOutsideLeft, vLeft)); let vOutsideRight = corners[2].plus(basis[0].timesReal(capLeft)); elements.push(new Line(vRight, vOutsideRight)); console.log(`Horizontal shift: ${1 - top}`); }