This commit is contained in:
2026-01-16 20:56:16 -06:00
parent 9f6435ece9
commit 22962bbd63
33 changed files with 643 additions and 315 deletions

View File

@@ -26,10 +26,10 @@ rasterize.ellipse = function ellipse(pos, radii, opt) {
var cx = pos[0], cy = pos[1]
var raw_start = opt.start || 0
var raw_end = opt.end || 1
var full_circle = number.abs(raw_end - raw_start) >= 1 - 1e-9
var full_circle = abs(raw_end - raw_start) >= 1 - 1e-9
var start = (raw_start % 1 + 1) % 1
var end = (raw_end % 1 + 1) % 1
var thickness = number.max(1, opt.thickness || 1)
var thickness = max(1, opt.thickness || 1)
var rx_i = rx - thickness,
ry_i = ry - thickness
@@ -46,8 +46,8 @@ rasterize.ellipse = function ellipse(pos, radii, opt) {
var pts = [
[cx + x, cy + y], [cx - x, cy + y],
[cx + x, cy - y], [cx - x, cy - y]
].filter(pt => within_wedge(pt[0]-cx, pt[1]-cy, start, end, full_circle))
points = points.concat(pts)
]
points = array(points, filter(pts, pt => within_wedge(pt[0]-cx, pt[1]-cy, start, end, full_circle)))
}
while (px < py) {
@@ -72,14 +72,14 @@ rasterize.ellipse = function ellipse(pos, radii, opt) {
for (var dy = -ry; dy <= ry; ++dy) {
var yy = dy * dy
var x_out = number.floor(rx * math.sqrt(1 - yy / ry_sq))
var x_out = floor(rx * math.sqrt(1 - yy / ry_sq))
var y_screen = cy + dy
var x_in = hole ? number.floor(rx_i * math.sqrt(1 - yy / ry_i_sq)) : -1
var x_in = hole ? floor(rx_i * math.sqrt(1 - yy / ry_i_sq)) : -1
var run_start = null
for (var dx = -x_out; dx <= x_out; ++dx) {
if (hole && number.abs(dx) <= x_in) { run_start = null; continue }
if (hole && abs(dx) <= x_in) { run_start = null; continue }
if (!within_wedge(dx, dy, start, end, full_circle)) { run_start = null; continue }
if (run_start == null) run_start = cx + dx
@@ -87,7 +87,7 @@ rasterize.ellipse = function ellipse(pos, radii, opt) {
var last = (dx == x_out)
var next_in_ring =
!last &&
!(hole && number.abs(dx+1) <= x_in) &&
!(hole && abs(dx+1) <= x_in) &&
within_wedge(dx+1, dy, start, end, full_circle)
if (last || !next_in_ring) {
@@ -140,7 +140,7 @@ rasterize.round_rect = function round_rect(rect, radius, thickness) {
return rasterize.fill_round_rect(rect, radius)
}
radius = number.min(radius, rect.width >> 1, rect.height >> 1)
radius = min(radius, rect.width >> 1, rect.height >> 1)
if ((thickness << 1) >= rect.width ||
(thickness << 1) >= rect.height ||
@@ -169,9 +169,9 @@ rasterize.round_rect = function round_rect(rect, radius, thickness) {
for (var dy = 0; dy < radius; ++dy) {
var dy_sq = dy * dy
var dx_out = number.floor(math.sqrt(r_out * r_out - dy_sq))
var dx_out = floor(math.sqrt(r_out * r_out - dy_sq))
var dx_in = (r_in > 0 && dy < r_in)
? number.floor(math.sqrt(r_in * r_in - dy_sq))
? floor(math.sqrt(r_in * r_in - dy_sq))
: -1
var w = dx_out - dx_in
if (w <= 0) continue
@@ -184,11 +184,11 @@ rasterize.round_rect = function round_rect(rect, radius, thickness) {
)
}
return {type: 'rects', data: rects.concat(strips)}
return {type: 'rects', data: array(rects, strips)}
}
rasterize.fill_round_rect = function fill_round_rect(rect, radius) {
radius = number.min(radius, rect.width >> 1, rect.height >> 1)
radius = min(radius, rect.width >> 1, rect.height >> 1)
var x0 = rect.x,
y0 = rect.y,
@@ -206,7 +206,7 @@ rasterize.fill_round_rect = function fill_round_rect(rect, radius) {
var caps = []
for (var dy = 0; dy < radius; ++dy) {
var dx = number.floor(math.sqrt(radius * radius - dy * dy))
var dx = floor(math.sqrt(radius * radius - dy * dy))
var w = (dx << 1) + 1
caps.push(
@@ -217,7 +217,7 @@ rasterize.fill_round_rect = function fill_round_rect(rect, radius) {
)
}
return {type: 'rects', data: rects.concat(caps)}
return {type: 'rects', data: array(rects, caps)}
}
return rasterize