Skip to content

Commit 61eedd7

Browse files
committed
editorial, align with spec
1 parent ef87496 commit 61eedd7

1 file changed

Lines changed: 10 additions & 12 deletions

File tree

css/css-borders/corner-shape/resources/render-corner-shape.js

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ function outset_adjusted_border_radius(width, height, radius, outset_x, outset_y
181181
* @param {number} superellipse_param
182182
* @returns {number}
183183
*/
184-
function unit_superellipse_half_corner(superellipse_param) {
184+
function normalized_superellipse_half_corner(superellipse_param) {
185185
const n = 2 ** Math.abs(superellipse_param);
186186
const convexHalfCorner = 0.5 ** (1 / n);
187187
if (superellipse_param < 0) return 1 - convexHalfCorner;
@@ -209,14 +209,12 @@ function corner_clip_out_path(startRadius, endRadius, startInset, endInset,
209209
normalizedV2.scale(-startInset));
210210
const originalStart = extend_point(originalOuter, normalizedV3.scale(endRadius));
211211
const originalEnd = extend_point(originalOuter, normalizedV2.scale(startRadius));
212-
const originalCenter = extend_point(originalOuter, normalizedV3.scale(endRadius),
213-
normalizedV2.scale(startRadius));
214212

215213
function clamp(l, v, u) {
216214
return Math.max(l, Math.min(v, u));
217215
}
218216

219-
const halfCornerX = unit_superellipse_half_corner(superellipse_param);
217+
const halfCornerX = normalized_superellipse_half_corner(superellipse_param);
220218
const controlPointX = clamp(0, halfCornerX / (Math.SQRT2 - 1) - 1 / Math.SQRT2, 1);
221219

222220
const insetDiff = clamp(-startRadius, endInset - startInset, endRadius);
@@ -275,9 +273,9 @@ function corner_clip_out_path(startRadius, endRadius, startInset, endInset,
275273
adjustedEnd = miterEnd;
276274
}
277275

278-
const adjustedWidth = Vector2D.dot(Vector2D.fromPoints(adjustedEnd, adjustedStart), normalizedV3);
279-
const adjustedOuter = extend_point(adjustedStart, normalizedV3.scale(-adjustedWidth));
280-
const adjustedCenter = extend_point(adjustedEnd, normalizedV3.scale(adjustedWidth));
276+
const adjustedHeight = Vector2D.dot(Vector2D.fromPoints(adjustedStart, adjustedEnd), normalizedV2);
277+
const adjustedOuter = extend_point(adjustedEnd, normalizedV2.scale(-adjustedHeight));
278+
const adjustedCenter = extend_point(adjustedStart, normalizedV2.scale(adjustedHeight));
281279

282280
/**
283281
* @param {number} x
@@ -312,20 +310,20 @@ function corner_clip_out_path(startRadius, endRadius, startInset, endInset,
312310
return [...t_set].toSorted((a, b) => a - b);
313311
}
314312

315-
const path = new Path2D();
316-
path.moveTo(miterStart.x, miterStart.y);
317-
318313
let selfIntersection = null;
319314
if (superellipse_param < 0 && startInset < 0 && endInset < 0 &&
320315
(-endInset >= startRadius || -startInset >= endRadius)) {
321316
selfIntersection = segment_line_intersection([miterStart, adjustedStart], [miterEnd, adjustedEnd]);
322317
}
323318

319+
const path = new Path2D();
320+
path.moveTo(miterStart.x, miterStart.y);
321+
324322
if (selfIntersection) {
325323
path.lineTo(selfIntersection.x, selfIntersection.y);
326324
} else if (superellipse_param == -Infinity) {
327325
path.lineTo(adjustedCenter.x, adjustedCenter.y);
328-
} else if (superellipse_param > 0 || superellipse_param < -1) {
326+
} else if (superellipse_param > 0 || superellipse_param <= -1) {
329327
const n = 2 ** Math.abs(superellipse_param);
330328
const curveCenter = superellipse_param < 0 ? adjustedOuter : adjustedCenter;
331329

@@ -335,7 +333,7 @@ function corner_clip_out_path(startRadius, endRadius, startInset, endInset,
335333
const point = map_point_to_corner(x, y, adjustedStart, adjustedEnd, curveCenter);
336334
path.lineTo(point.x, point.y);
337335
}
338-
} else if (superellipse_param >= -1 && superellipse_param < 0) {
336+
} else if (superellipse_param > -1 && superellipse_param < 0) {
339337
const tangentIntersection = line_intersection(
340338
[adjustedStart, extend_point(adjustedStart, startTangent)],
341339
[adjustedEnd, extend_point(adjustedEnd, endTangent)])

0 commit comments

Comments
 (0)