Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(edgeless): optimizing branches #6660

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ function renderPoints(
curve: boolean
) {
const { seed, stroke, strokeWidth, roughness, rough } = model;
const rc = renderer.rc;
const realStrokeColor = renderer.getVariableColor(stroke);

if (rough) {
Expand All @@ -70,51 +69,54 @@ function renderPoints(
stroke: realStrokeColor,
strokeWidth,
};

if (curve) {
const b = getBezierParameters(model.absolutePath);
rc.path(
`M${b[0][0]},${b[0][1]} C${b[1][0]},${b[1][1]} ${b[2][0]},${b[2][1]} ${b[3][0]},${b[3][1]} `,
renderer.rc.path(
`M${b[0][0]},${b[0][1]} C${b[1][0]},${b[1][1]} ${b[2][0]},${b[2][1]} ${b[3][0]},${b[3][1]}`,
options
);
} else {
rc.linearPath(points as unknown as [number, number][], options);
return;
}

renderer.rc.linearPath(points as unknown as [number, number][], options);
return;
}

ctx.save();
ctx.strokeStyle = realStrokeColor;
ctx.lineWidth = strokeWidth;
ctx.lineJoin = 'round';
dash && ctx.setLineDash([12, 12]);
ctx.beginPath();
if (curve) {
points.forEach((point, index) => {
if (index === 0) {
ctx.moveTo(point[0], point[1]);
} else {
const last = points[index - 1];
ctx.bezierCurveTo(
last.absOut[0],
last.absOut[1],
point.absIn[0],
point.absIn[1],
point[0],
point[1]
);
}
});
} else {
ctx.save();
ctx.strokeStyle = realStrokeColor;
ctx.lineWidth = model.strokeWidth;
ctx.lineJoin = 'round';
dash && ctx.setLineDash([12, 12]);
ctx.beginPath();
if (curve) {
points.forEach((point, index) => {
if (index === 0) {
ctx.moveTo(point[0], point[1]);
} else {
const last = points[index - 1];
ctx.bezierCurveTo(
last.absOut[0],
last.absOut[1],
point.absIn[0],
point.absIn[1],
point[0],
point[1]
);
}
});
} else {
points.forEach((point, index) => {
if (index === 0) {
ctx.moveTo(point[0], point[1]);
} else {
ctx.lineTo(point[0], point[1]);
}
});
}
ctx.stroke();
ctx.closePath();
ctx.restore();
points.forEach((point, index) => {
if (index === 0) {
ctx.moveTo(point[0], point[1]);
} else {
ctx.lineTo(point[0], point[1]);
}
});
}
ctx.stroke();
ctx.closePath();
ctx.restore();
}

function renderEndpoint(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,23 @@ export function diamond(
);

if (shapeStyle === 'General') {
drawGeneralShape(ctx, model, renderer);
} else {
rc.polygon(
[
[renderWidth / 2, 0],
[renderWidth, renderHeight / 2],
[renderWidth / 2, renderHeight],
[0, renderHeight / 2],
],
{
seed,
roughness: shapeStyle === 'Scribbled' ? roughness : 0,
strokeLineDash: strokeStyle === 'dash' ? [12, 12] : undefined,
stroke: strokeStyle === 'none' ? 'none' : realStrokeColor,
strokeWidth,
fill: filled ? realFillColor : undefined,
}
);
return drawGeneralShape(ctx, model, renderer);
}

rc.polygon(
[
[renderWidth / 2, 0],
[renderWidth, renderHeight / 2],
[renderWidth / 2, renderHeight],
[0, renderHeight / 2],
],
{
seed,
roughness,
strokeLineDash: strokeStyle === 'dash' ? [12, 12] : undefined,
stroke: strokeStyle === 'none' ? 'none' : realStrokeColor,
strokeWidth,
fill: filled ? realFillColor : undefined,
}
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@ export function ellipse(
);

if (shapeStyle === 'General') {
drawGeneralShape(ctx, model, renderer);
} else {
rc.ellipse(cx, cy, renderWidth, renderHeight, {
seed,
roughness: shapeStyle === 'Scribbled' ? roughness : 0,
strokeLineDash: strokeStyle === 'dash' ? [12, 12] : undefined,
stroke: strokeStyle === 'none' ? 'none' : realStrokeColor,
strokeWidth,
fill: filled ? realFillColor : undefined,
curveFitting: 1,
});
return drawGeneralShape(ctx, model, renderer);
}

rc.ellipse(cx, cy, renderWidth, renderHeight, {
seed,
roughness,
strokeLineDash: strokeStyle === 'dash' ? [12, 12] : undefined,
stroke: strokeStyle === 'none' ? 'none' : realStrokeColor,
strokeWidth,
fill: filled ? realFillColor : undefined,
curveFitting: 1,
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ export function rect(
);

if (shapeStyle === 'General') {
drawGeneralShape(ctx, model, renderer);
} else {
rc.path(
`
return drawGeneralShape(ctx, model, renderer);
}

rc.path(
`
M ${r} 0
L ${renderWidth - r} 0
C ${renderWidth - K_RECT * r} 0 ${renderWidth} ${
Expand All @@ -65,14 +66,13 @@ export function rect(
C 0 ${K_RECT * r} ${K_RECT * r} 0 ${r} 0
Z
`,
{
seed,
roughness: shapeStyle === 'Scribbled' ? roughness : 0,
strokeLineDash: strokeStyle === 'dash' ? [12, 12] : undefined,
stroke: strokeStyle === 'none' ? 'none' : realStrokeColor,
strokeWidth,
fill: filled ? realFillColor : undefined,
}
);
}
{
seed,
roughness,
strokeLineDash: strokeStyle === 'dash' ? [12, 12] : undefined,
stroke: strokeStyle === 'none' ? 'none' : realStrokeColor,
strokeWidth,
fill: filled ? realFillColor : undefined,
}
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,22 @@ export function triangle(
);

if (shapeStyle === 'General') {
drawGeneralShape(ctx, model, renderer);
} else {
rc.polygon(
[
[renderWidth / 2, 0],
[renderWidth, renderHeight],
[0, renderHeight],
],
{
seed,
roughness: shapeStyle === 'Scribbled' ? roughness : 0,
strokeLineDash: strokeStyle === 'dash' ? [12, 12] : undefined,
stroke: strokeStyle === 'none' ? 'none' : realStrokeColor,
strokeWidth,
fill: filled ? realFillColor : undefined,
}
);
return drawGeneralShape(ctx, model, renderer);
}

rc.polygon(
[
[renderWidth / 2, 0],
[renderWidth, renderHeight],
[0, renderHeight],
],
{
seed,
roughness,
strokeLineDash: strokeStyle === 'dash' ? [12, 12] : undefined,
stroke: strokeStyle === 'none' ? 'none' : realStrokeColor,
strokeWidth,
fill: filled ? realFillColor : undefined,
}
);
}