mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-03-14 05:33:59 -04:00
box-drawing: LIGHT ARC: test using a circle equation instead of a bezier curve
This commit is contained in:
parent
128883fa05
commit
87dcdc2b3b
1 changed files with 35 additions and 73 deletions
108
box-drawing.c
108
box-drawing.c
|
|
@ -1210,22 +1210,6 @@ draw_box_drawings_double_vertical_and_horizontal(struct buf *buf)
|
||||||
vline(hmid + 2 * thick, buf->height, vmid + 2 * thick, thick);
|
vline(hmid + 2 * thick, buf->height, vmid + 2 * thick, thick);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define cubic_bezier_x(t) __extension__ \
|
|
||||||
({ \
|
|
||||||
double tm1 = 1 - t; \
|
|
||||||
double tm1_3 = tm1 * tm1 * tm1; \
|
|
||||||
double t_3 = t * t * t; \
|
|
||||||
tm1_3 * start_x + 3 * t * tm1 * (tm1 * c1_x + t * c2_x) + t_3 * end_x; \
|
|
||||||
})
|
|
||||||
|
|
||||||
#define cubic_bezier_y(t) __extension__ \
|
|
||||||
({ \
|
|
||||||
double tm1 = 1 - t; \
|
|
||||||
double tm1_3 = tm1 * tm1 * tm1; \
|
|
||||||
double t_3 = t * t * t; \
|
|
||||||
tm1_3 * start_y + 3 * t * tm1 * (tm1 * c1_y + t * c2_y) + t_3 * end_y; \
|
|
||||||
})
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
draw_box_drawings_light_arc(wchar_t wc, struct buf *buf)
|
draw_box_drawings_light_arc(wchar_t wc, struct buf *buf)
|
||||||
{
|
{
|
||||||
|
|
@ -1233,74 +1217,52 @@ draw_box_drawings_light_arc(wchar_t wc, struct buf *buf)
|
||||||
int delta = thick / 2;
|
int delta = thick / 2;
|
||||||
int extra = thick % 2;
|
int extra = thick % 2;
|
||||||
|
|
||||||
|
/* x^2 / a^2 + y^2 / b^2 == 1 */
|
||||||
|
|
||||||
int hw = (buf->width - thick) / 2;
|
int hw = (buf->width - thick) / 2;
|
||||||
int hh = (buf->height - thick) / 2;
|
int hh = (buf->height - thick) / 2;
|
||||||
int start_x, start_y, end_x, end_y, c1_x, c1_y, c2_x, c2_y;
|
|
||||||
|
|
||||||
if (wc == L'╭') {
|
double a = hw;
|
||||||
start_x = hw;
|
double b = hh;
|
||||||
start_y = 2 * hh;
|
|
||||||
|
|
||||||
end_x = 2 * hw;
|
double a2 = a * a;
|
||||||
end_y = hh;
|
double b2 = b * b;
|
||||||
|
|
||||||
c1_x = hw;
|
int num_samples = buf->height * 16;
|
||||||
c1_y = 3 * buf->height / 4;
|
for (int i = 0; i < num_samples; i++) {
|
||||||
|
double y = i / 16.;
|
||||||
|
double x = sqrt(a2 * (1. - y * y / b2));
|
||||||
|
int row = round(y);
|
||||||
|
int col = round(x);
|
||||||
|
|
||||||
c2_x = hw;
|
if (col < 0)
|
||||||
c2_y = hh;
|
continue;
|
||||||
} else if (wc == L'╮') {
|
|
||||||
start_x = hw;
|
|
||||||
start_y = 2 * hh;
|
|
||||||
|
|
||||||
end_x = 0;
|
switch (wc) {
|
||||||
end_y = hh;
|
case L'╭':
|
||||||
|
row = buf->height - row - 1 - (1 - buf->height % 2);
|
||||||
|
col = buf->width - col - 1 - (1 - buf->width % 2);
|
||||||
|
break;
|
||||||
|
|
||||||
c1_x = hw;
|
case L'╮':
|
||||||
c1_y = 3 * buf->height / 4;
|
row = buf->height - row - 1 - (1 - buf->height % 2);
|
||||||
|
break;
|
||||||
|
|
||||||
c2_x = hw;
|
case L'╰':
|
||||||
c2_y = hh;
|
col = buf->width - col - 1 - (1 - buf->width % 2);
|
||||||
} else if (wc == L'╯') {
|
break;
|
||||||
start_x = hw;
|
}
|
||||||
start_y = 0;
|
|
||||||
|
|
||||||
end_x = 0;
|
for (int r = row - delta; r < row + delta + extra; r++) {
|
||||||
end_y = hh;
|
if (r < 0 || r >= buf->height)
|
||||||
|
continue;
|
||||||
|
|
||||||
c1_x = hw;
|
for (int c = col - delta; c < col + delta + extra; c++) {
|
||||||
c1_y = buf->height / 4;
|
if (c >= 0 && c < buf->width) {
|
||||||
|
size_t idx = c / 8;
|
||||||
c2_x = hw;
|
size_t bit_no = c % 8;
|
||||||
c2_y = hh;
|
buf->data[r * buf->stride + idx] |= 1 << bit_no;
|
||||||
} else {
|
}
|
||||||
assert(wc == L'╰');
|
|
||||||
|
|
||||||
start_x = hw;
|
|
||||||
start_y = 0;
|
|
||||||
|
|
||||||
end_x = 2 * hw;
|
|
||||||
end_y = hh;
|
|
||||||
|
|
||||||
c1_x = hw;
|
|
||||||
c1_y = buf->height / 4;
|
|
||||||
|
|
||||||
c2_x = hw;
|
|
||||||
c2_y = hh;
|
|
||||||
}
|
|
||||||
|
|
||||||
int num_samples = buf->height * 4;
|
|
||||||
|
|
||||||
for (size_t i = 0; i < num_samples + 1; i++) {
|
|
||||||
double t = (double)i / num_samples;
|
|
||||||
int p_x = round(cubic_bezier_x(t));
|
|
||||||
int p_y = round(cubic_bezier_y(t));
|
|
||||||
|
|
||||||
for (int y = max(p_y - delta, 0); y < min(p_y + delta + extra, buf->height); y++) {
|
|
||||||
for (int x = max(p_x - delta, 0); x < min(p_x + delta + extra, buf->width); x++) {
|
|
||||||
size_t ofs = x / 8;
|
|
||||||
size_t bit_no = x % 8;
|
|
||||||
buf->data[y * buf->stride + ofs] |= 1 << bit_no;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue