|
|
|
@ -12,11 +12,14 @@ import {
|
|
|
|
|
TrashIcon,
|
|
|
|
|
} from "../../packages/excalidraw/components/icons";
|
|
|
|
|
import { STORAGE_KEYS } from "../app_constants";
|
|
|
|
|
import type { Arc, Curve } from "../../packages/math";
|
|
|
|
|
import {
|
|
|
|
|
isArc,
|
|
|
|
|
isLineSegment,
|
|
|
|
|
type GlobalPoint,
|
|
|
|
|
type LineSegment,
|
|
|
|
|
} from "../../packages/math";
|
|
|
|
|
import isCurve from "../../packages/math/curve";
|
|
|
|
|
|
|
|
|
|
const renderLine = (
|
|
|
|
|
context: CanvasRenderingContext2D,
|
|
|
|
@ -33,6 +36,48 @@ const renderLine = (
|
|
|
|
|
context.restore();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const renderCubicBezier = (
|
|
|
|
|
context: CanvasRenderingContext2D,
|
|
|
|
|
zoom: number,
|
|
|
|
|
[start, control1, control2, end]: Curve<GlobalPoint>,
|
|
|
|
|
color: string,
|
|
|
|
|
) => {
|
|
|
|
|
context.save();
|
|
|
|
|
context.strokeStyle = color;
|
|
|
|
|
context.beginPath();
|
|
|
|
|
context.moveTo(start[0] * zoom, start[1] * zoom);
|
|
|
|
|
context.bezierCurveTo(
|
|
|
|
|
control1[0] * zoom,
|
|
|
|
|
control1[1] * zoom,
|
|
|
|
|
control2[0] * zoom,
|
|
|
|
|
control2[1] * zoom,
|
|
|
|
|
end[0] * zoom,
|
|
|
|
|
end[1] * zoom,
|
|
|
|
|
);
|
|
|
|
|
context.stroke();
|
|
|
|
|
context.restore();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const renderArc = (
|
|
|
|
|
context: CanvasRenderingContext2D,
|
|
|
|
|
zoom: number,
|
|
|
|
|
a: Arc<GlobalPoint>,
|
|
|
|
|
color: string,
|
|
|
|
|
) => {
|
|
|
|
|
context.save();
|
|
|
|
|
context.strokeStyle = color;
|
|
|
|
|
context.beginPath();
|
|
|
|
|
context.arc(
|
|
|
|
|
a.center[0] * zoom,
|
|
|
|
|
a.center[1] * zoom,
|
|
|
|
|
a.radius * zoom,
|
|
|
|
|
a.startAngle,
|
|
|
|
|
a.endAngle,
|
|
|
|
|
);
|
|
|
|
|
context.stroke();
|
|
|
|
|
context.restore();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const renderOrigin = (context: CanvasRenderingContext2D, zoom: number) => {
|
|
|
|
|
context.strokeStyle = "#888";
|
|
|
|
|
context.save();
|
|
|
|
@ -60,6 +105,24 @@ const render = (
|
|
|
|
|
el.color,
|
|
|
|
|
);
|
|
|
|
|
break;
|
|
|
|
|
case isArc(el.data):
|
|
|
|
|
renderArc(
|
|
|
|
|
context,
|
|
|
|
|
appState.zoom.value,
|
|
|
|
|
el.data as Arc<GlobalPoint>,
|
|
|
|
|
el.color,
|
|
|
|
|
);
|
|
|
|
|
break;
|
|
|
|
|
case isCurve(el.data):
|
|
|
|
|
renderCubicBezier(
|
|
|
|
|
context,
|
|
|
|
|
appState.zoom.value,
|
|
|
|
|
el.data as Curve<GlobalPoint>,
|
|
|
|
|
el.color,
|
|
|
|
|
);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
throw new Error("Unknown element type");
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|