2022-01-29 14:25:18 +01:00
|
|
|
enum LINE_STYLE {
|
|
|
|
solid,
|
|
|
|
dashed
|
|
|
|
}
|
|
|
|
|
2022-01-13 05:24:03 +01:00
|
|
|
function draw_line_curve(x0, y0, x1, y1, thick = 1) {
|
|
|
|
var xc = (x0 + x1) / 2;
|
|
|
|
var sample = max(8, ceil((abs(x0 - x1) + abs(y0 - y1)) / 4));
|
|
|
|
|
|
|
|
//var buff = vertex_create_buffer();
|
|
|
|
//vertex_begin(buff, global.format_pc);
|
|
|
|
|
|
|
|
var c = draw_get_color();
|
|
|
|
var ox, oy, nx, ny, t, it;
|
|
|
|
for( var i = 0; i <= sample; i++ ) {
|
|
|
|
t = i / sample;
|
|
|
|
it = 1 - t;
|
|
|
|
|
|
|
|
nx = x0 * t * t * t + 3 * xc * it * t * t + 3 * xc * it * it * t + x1 * it * it * it;
|
|
|
|
ny = y0 * t * t * t + 3 * y0 * it * t * t + 3 * y1 * it * it * t + y1 * it * it * it;
|
|
|
|
|
|
|
|
if(i) {
|
|
|
|
draw_line_width(ox, oy, nx, ny, thick);
|
|
|
|
//vertex_position(buff, ox, oy); vertex_color(buff, c, 1);
|
|
|
|
//vertex_position(buff, nx, ny); vertex_color(buff, c, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
ox = nx;
|
|
|
|
oy = ny;
|
|
|
|
}
|
|
|
|
|
|
|
|
//vertex_end(buff);
|
|
|
|
//vertex_submit(buff, pr_linelist, -1);
|
|
|
|
|
|
|
|
//buffer_delete(buff);
|
|
|
|
}
|
|
|
|
|
2022-01-29 14:25:18 +01:00
|
|
|
function draw_line_curve_color(x0, y0, x1, y1, thick, col1, col2, type = LINE_STYLE.solid) {
|
2022-01-13 05:24:03 +01:00
|
|
|
var xc = (x0 + x1) / 2;
|
|
|
|
var sample = max(8, ceil((abs(x0 - x1) + abs(y0 - y1)) / 4));
|
|
|
|
|
|
|
|
var c = draw_get_color();
|
|
|
|
var ox, oy, nx, ny, t, it, oc, nc;
|
2022-01-29 14:25:18 +01:00
|
|
|
var dash_distance = 2;
|
2022-01-13 05:24:03 +01:00
|
|
|
|
|
|
|
for( var i = 0; i <= sample; i++ ) {
|
|
|
|
t = i / sample;
|
|
|
|
it = 1 - t;
|
|
|
|
|
|
|
|
nx = x0 * t * t * t + 3 * xc * it * t * t + 3 * xc * it * it * t + x1 * it * it * it;
|
|
|
|
ny = y0 * t * t * t + 3 * y0 * it * t * t + 3 * y1 * it * it * t + y1 * it * it * it;
|
|
|
|
nc = merge_color(col1, col2, t);
|
|
|
|
|
|
|
|
if(i) {
|
2022-01-29 14:25:18 +01:00
|
|
|
switch(type) {
|
|
|
|
case LINE_STYLE.solid :
|
|
|
|
draw_line_width_color(ox, oy, nx, ny, thick, oc, nc);
|
|
|
|
break;
|
|
|
|
case LINE_STYLE.dashed :
|
|
|
|
if(floor(i / dash_distance) % 2)
|
|
|
|
draw_line_width_color(ox, oy, nx, ny, thick, oc, nc);
|
|
|
|
break;
|
|
|
|
}
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ox = nx;
|
|
|
|
oy = ny;
|
|
|
|
oc = nc;
|
|
|
|
}
|
|
|
|
}
|
2022-01-25 04:05:30 +01:00
|
|
|
|
|
|
|
function distance_to_curve(mx, my, x0, y0, x1, y1) {
|
|
|
|
var xc = (x0 + x1) / 2;
|
|
|
|
var sample = max(8, ceil((abs(x0 - x1) + abs(y0 - y1)) / 4));
|
|
|
|
|
|
|
|
var dist = 999999;
|
|
|
|
var ox, oy, nx, ny, t, it;
|
|
|
|
|
|
|
|
for( var i = 0; i <= sample; i++ ) {
|
|
|
|
t = i / sample;
|
|
|
|
it = 1 - t;
|
|
|
|
|
|
|
|
nx = x0 * t * t * t + 3 * xc * it * t * t + 3 * xc * it * it * t + x1 * it * it * it;
|
|
|
|
ny = y0 * t * t * t + 3 * y0 * it * t * t + 3 * y1 * it * it * t + y1 * it * it * it;
|
|
|
|
|
|
|
|
if(i)
|
|
|
|
dist = min(dist, distance_to_line(mx, my, ox, oy, nx, ny));
|
|
|
|
|
|
|
|
ox = nx;
|
|
|
|
oy = ny;
|
|
|
|
}
|
|
|
|
|
|
|
|
return dist;
|
2022-09-21 06:09:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function draw_line_elbow(x0, y0, x1, y1, thick = 1, type = LINE_STYLE.solid) {
|
|
|
|
var cx = (x0 + x1) / 2;
|
|
|
|
draw_line_width(x0, y0, cx, y0, thick);
|
|
|
|
draw_line_width(cx, y0 - thick / 2, cx, y1 + thick / 2, thick);
|
|
|
|
draw_line_width(cx, y1, x1, y1, thick);
|
|
|
|
}
|
|
|
|
|
|
|
|
function draw_line_elbow_color(x0, y0, x1, y1, thick, col1, col2, type = LINE_STYLE.solid) {
|
|
|
|
var cx = (x0 + x1) / 2;
|
|
|
|
var cm = merge_color(col1, col2, 0.5);
|
|
|
|
|
|
|
|
if(type == LINE_STYLE.solid) {
|
|
|
|
draw_line_width_color(x0, y0, cx, y0, thick, col1, cm);
|
|
|
|
draw_line_width_color(cx, y0 - thick / 2, cx, y1 + thick / 2, thick, cm, cm);
|
|
|
|
draw_line_width_color(cx, y1, x1, y1, thick, cm, col2);
|
|
|
|
} else {
|
2022-12-16 09:18:09 +01:00
|
|
|
draw_line_dashed_color(x0, y0, cx, y0, thick, col1, cm, 12);
|
|
|
|
draw_line_dashed_color(cx, y0 - thick / 2, cx, y1 + thick / 2, thick, cm, cm, 12);
|
|
|
|
draw_line_dashed_color(cx, y1, x1, y1, thick, cm, col2, 12);
|
2022-09-21 06:09:40 +02:00
|
|
|
}
|
2022-01-25 04:05:30 +01:00
|
|
|
}
|