|
|
|
@ -96,7 +96,7 @@ export function deconstructRectanguloidElement(
|
|
|
|
|
pointFrom<GlobalPoint>(r[0][0], r[0][1] + roundness),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const vecs = [
|
|
|
|
|
const offsets = [
|
|
|
|
|
vectorScale(
|
|
|
|
|
vectorNormalize(
|
|
|
|
|
vectorFromPoint(pointFrom(r[0][0] - offset, r[0][1] - offset), center),
|
|
|
|
@ -125,96 +125,86 @@ export function deconstructRectanguloidElement(
|
|
|
|
|
|
|
|
|
|
const corners = [
|
|
|
|
|
curve(
|
|
|
|
|
pointFromVector(vecs[0], left[1]),
|
|
|
|
|
pointFromVector(offsets[0], left[1]),
|
|
|
|
|
pointFromVector(
|
|
|
|
|
vecs[0],
|
|
|
|
|
offsets[0],
|
|
|
|
|
pointFrom<GlobalPoint>(
|
|
|
|
|
left[1][0] + (2 / 3) * (r[0][0] - left[1][0]),
|
|
|
|
|
left[1][1] + (2 / 3) * (r[0][1] - left[1][1]),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
pointFromVector(
|
|
|
|
|
vecs[0],
|
|
|
|
|
offsets[0],
|
|
|
|
|
pointFrom<GlobalPoint>(
|
|
|
|
|
top[0][0] + (2 / 3) * (r[0][0] - top[0][0]),
|
|
|
|
|
top[0][1] + (2 / 3) * (r[0][1] - top[0][1]),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
pointFromVector(vecs[0], top[0]),
|
|
|
|
|
pointFromVector(offsets[0], top[0]),
|
|
|
|
|
), // TOP LEFT
|
|
|
|
|
curve(
|
|
|
|
|
pointFromVector(vecs[1], top[1]),
|
|
|
|
|
pointFromVector(offsets[1], top[1]),
|
|
|
|
|
pointFromVector(
|
|
|
|
|
vecs[1],
|
|
|
|
|
offsets[1],
|
|
|
|
|
pointFrom<GlobalPoint>(
|
|
|
|
|
top[1][0] + (2 / 3) * (r[1][0] - top[1][0]),
|
|
|
|
|
top[1][1] + (2 / 3) * (r[0][1] - top[1][1]),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
pointFromVector(
|
|
|
|
|
vecs[1],
|
|
|
|
|
offsets[1],
|
|
|
|
|
pointFrom<GlobalPoint>(
|
|
|
|
|
right[0][0] + (2 / 3) * (r[1][0] - right[0][0]),
|
|
|
|
|
right[0][1] + (2 / 3) * (r[0][1] - right[0][1]),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
pointFromVector(vecs[1], right[0]),
|
|
|
|
|
pointFromVector(offsets[1], right[0]),
|
|
|
|
|
), // TOP RIGHT
|
|
|
|
|
curve(
|
|
|
|
|
pointFromVector(vecs[2], right[1]),
|
|
|
|
|
pointFromVector(offsets[2], right[1]),
|
|
|
|
|
pointFromVector(
|
|
|
|
|
vecs[2],
|
|
|
|
|
offsets[2],
|
|
|
|
|
pointFrom<GlobalPoint>(
|
|
|
|
|
right[1][0] + (2 / 3) * (r[1][0] - right[1][0]),
|
|
|
|
|
right[1][1] + (2 / 3) * (r[1][1] - right[1][1]),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
pointFromVector(
|
|
|
|
|
vecs[2],
|
|
|
|
|
offsets[2],
|
|
|
|
|
pointFrom<GlobalPoint>(
|
|
|
|
|
bottom[1][0] + (2 / 3) * (r[1][0] - bottom[1][0]),
|
|
|
|
|
bottom[1][1] + (2 / 3) * (r[1][1] - bottom[1][1]),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
pointFromVector(vecs[2], bottom[1]),
|
|
|
|
|
pointFromVector(offsets[2], bottom[1]),
|
|
|
|
|
), // BOTTOM RIGHT
|
|
|
|
|
curve(
|
|
|
|
|
pointFromVector(vecs[3], bottom[0]),
|
|
|
|
|
pointFromVector(offsets[3], bottom[0]),
|
|
|
|
|
pointFromVector(
|
|
|
|
|
vecs[3],
|
|
|
|
|
offsets[3],
|
|
|
|
|
pointFrom<GlobalPoint>(
|
|
|
|
|
bottom[0][0] + (2 / 3) * (r[0][0] - bottom[0][0]),
|
|
|
|
|
bottom[0][1] + (2 / 3) * (r[1][1] - bottom[0][1]),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
pointFromVector(
|
|
|
|
|
vecs[3],
|
|
|
|
|
offsets[3],
|
|
|
|
|
pointFrom<GlobalPoint>(
|
|
|
|
|
left[0][0] + (2 / 3) * (r[0][0] - left[0][0]),
|
|
|
|
|
left[0][1] + (2 / 3) * (r[1][1] - left[0][1]),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
pointFromVector(vecs[3], left[0]),
|
|
|
|
|
pointFromVector(offsets[3], left[0]),
|
|
|
|
|
), // BOTTOM LEFT
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const sides = [
|
|
|
|
|
//top,
|
|
|
|
|
lineSegment<GlobalPoint>(corners[0][3], corners[1][0]),
|
|
|
|
|
//right,
|
|
|
|
|
lineSegment<GlobalPoint>(corners[1][3], corners[2][0]),
|
|
|
|
|
//bottom,
|
|
|
|
|
lineSegment<GlobalPoint>(corners[2][3], corners[3][0]),
|
|
|
|
|
//left,
|
|
|
|
|
lineSegment<GlobalPoint>(corners[3][3], corners[0][0]),
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
debugClear();
|
|
|
|
|
sides.forEach((s) => debugDrawLine(s, { color: "red", permanent: true }));
|
|
|
|
|
corners.forEach((c) =>
|
|
|
|
|
debugDrawCubicBezier(c, { color: "green", permanent: true }),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return [sides, corners];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -235,6 +225,7 @@ export function deconstructDiamondElement(
|
|
|
|
|
const verticalRadius = getCornerRadius(Math.abs(topX - leftX), element);
|
|
|
|
|
const horizontalRadius = getCornerRadius(Math.abs(rightY - topY), element);
|
|
|
|
|
|
|
|
|
|
if (element.roundness?.type == null) {
|
|
|
|
|
const [top, right, bottom, left]: GlobalPoint[] = [
|
|
|
|
|
pointFrom(element.x + topX, element.y + topY - offset),
|
|
|
|
|
pointFrom(element.x + rightX + offset, element.y + rightY),
|
|
|
|
@ -261,58 +252,109 @@ export function deconstructDiamondElement(
|
|
|
|
|
pointFrom(top[0] - verticalRadius, top[1] + horizontalRadius),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const curves = element.roundness
|
|
|
|
|
? [
|
|
|
|
|
return [[topRight, bottomRight, bottomLeft, topLeft], []];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const center = pointFrom<GlobalPoint>(
|
|
|
|
|
element.x + element.width / 2,
|
|
|
|
|
element.y + element.height / 2,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const [top, right, bottom, left]: GlobalPoint[] = [
|
|
|
|
|
pointFrom(element.x + topX, element.y + topY),
|
|
|
|
|
pointFrom(element.x + rightX, element.y + rightY),
|
|
|
|
|
pointFrom(element.x + bottomX, element.y + bottomY),
|
|
|
|
|
pointFrom(element.x + leftX, element.y + leftY),
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const offsets = [
|
|
|
|
|
vectorScale(vectorNormalize(vectorFromPoint(right, center)), offset), // RIGHT
|
|
|
|
|
vectorScale(vectorNormalize(vectorFromPoint(bottom, center)), offset), // BOTTOM
|
|
|
|
|
vectorScale(vectorNormalize(vectorFromPoint(left, center)), offset), // LEFT
|
|
|
|
|
vectorScale(vectorNormalize(vectorFromPoint(top, center)), offset), // TOP
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const corners = [
|
|
|
|
|
curve(
|
|
|
|
|
pointFromVector(
|
|
|
|
|
offsets[0],
|
|
|
|
|
pointFrom<GlobalPoint>(
|
|
|
|
|
right[0] - verticalRadius,
|
|
|
|
|
right[1] - horizontalRadius,
|
|
|
|
|
),
|
|
|
|
|
right,
|
|
|
|
|
right,
|
|
|
|
|
),
|
|
|
|
|
pointFromVector(offsets[0], right),
|
|
|
|
|
pointFromVector(offsets[0], right),
|
|
|
|
|
pointFromVector(
|
|
|
|
|
offsets[0],
|
|
|
|
|
pointFrom<GlobalPoint>(
|
|
|
|
|
right[0] - verticalRadius,
|
|
|
|
|
right[1] + horizontalRadius,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
), // RIGHT
|
|
|
|
|
curve(
|
|
|
|
|
pointFromVector(
|
|
|
|
|
offsets[1],
|
|
|
|
|
pointFrom<GlobalPoint>(
|
|
|
|
|
bottom[0] + verticalRadius,
|
|
|
|
|
bottom[1] - horizontalRadius,
|
|
|
|
|
),
|
|
|
|
|
bottom,
|
|
|
|
|
bottom,
|
|
|
|
|
),
|
|
|
|
|
pointFromVector(offsets[1], bottom),
|
|
|
|
|
pointFromVector(offsets[1], bottom),
|
|
|
|
|
pointFromVector(
|
|
|
|
|
offsets[1],
|
|
|
|
|
pointFrom<GlobalPoint>(
|
|
|
|
|
bottom[0] - verticalRadius,
|
|
|
|
|
bottom[1] - horizontalRadius,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
), // BOTTOM
|
|
|
|
|
curve(
|
|
|
|
|
pointFromVector(
|
|
|
|
|
offsets[2],
|
|
|
|
|
pointFrom<GlobalPoint>(
|
|
|
|
|
left[0] + verticalRadius,
|
|
|
|
|
left[1] + horizontalRadius,
|
|
|
|
|
),
|
|
|
|
|
left,
|
|
|
|
|
left,
|
|
|
|
|
),
|
|
|
|
|
pointFromVector(offsets[2], left),
|
|
|
|
|
pointFromVector(offsets[2], left),
|
|
|
|
|
pointFromVector(
|
|
|
|
|
offsets[2],
|
|
|
|
|
pointFrom<GlobalPoint>(
|
|
|
|
|
left[0] + verticalRadius,
|
|
|
|
|
left[1] - horizontalRadius,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
), // LEFT
|
|
|
|
|
curve(
|
|
|
|
|
pointFromVector(
|
|
|
|
|
offsets[3],
|
|
|
|
|
pointFrom<GlobalPoint>(
|
|
|
|
|
top[0] - verticalRadius,
|
|
|
|
|
top[1] + horizontalRadius,
|
|
|
|
|
),
|
|
|
|
|
top,
|
|
|
|
|
top,
|
|
|
|
|
),
|
|
|
|
|
pointFromVector(offsets[3], top),
|
|
|
|
|
pointFromVector(offsets[3], top),
|
|
|
|
|
pointFromVector(
|
|
|
|
|
offsets[3],
|
|
|
|
|
pointFrom<GlobalPoint>(
|
|
|
|
|
top[0] + verticalRadius,
|
|
|
|
|
top[1] + horizontalRadius,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
), // TOP
|
|
|
|
|
]
|
|
|
|
|
: [];
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const sides = [
|
|
|
|
|
lineSegment<GlobalPoint>(corners[0][3], corners[1][0]),
|
|
|
|
|
lineSegment<GlobalPoint>(corners[1][3], corners[2][0]),
|
|
|
|
|
lineSegment<GlobalPoint>(corners[2][3], corners[3][0]),
|
|
|
|
|
lineSegment<GlobalPoint>(corners[3][3], corners[0][0]),
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
return [[topRight, bottomRight, bottomLeft, topLeft], curves];
|
|
|
|
|
return [sides, corners];
|
|
|
|
|
}
|
|
|
|
|