aboutsummaryrefslogtreecommitdiff
path: root/drawing/drawing.ha
diff options
context:
space:
mode:
Diffstat (limited to 'drawing/drawing.ha')
-rw-r--r--drawing/drawing.ha17
1 files changed, 14 insertions, 3 deletions
diff --git a/drawing/drawing.ha b/drawing/drawing.ha
index a7d9e1f..54116a3 100644
--- a/drawing/drawing.ha
+++ b/drawing/drawing.ha
@@ -103,9 +103,19 @@ export fn circle_hollow(picture: *picture, c: pos, r: i32, color: u32) void = {
export fn stroke(picture: *picture, c0: pos, c1: pos, r: i32, color: u32) void = {
const dx = c1.0 - c0.0;
const dy = c1.1 - c0.1;
- const count = (abs(dx)+abs(dy))/r;
- const sx = dx: f64 / (count-1): f64;
- const sy = dy: f64 / (count-1): f64;
+ const d = math::sqrtf64((dx*dx+dy*dy):f64):i32;
+ const count = d/r + 1;
+ if (count == 0) {
+ circle(picture, c1, r, color);
+ return;
+ } else if (count == 1) {
+ circle(picture, c0, r, color);
+ circle(picture, c1, r, color);
+ return;
+ };
+ fmt::printfln("count: {}",count)!;
+ const sx = dx: f64 / (count): f64;
+ const sy = dy: f64 / (count): f64;
for (let i = 0i32; i < count; i += 1) {
const cx = c0.0 + math::roundf64(i:f64*sx):i32;
@@ -113,6 +123,7 @@ export fn stroke(picture: *picture, c0: pos, c1: pos, r: i32, color: u32) void =
circle(picture, (cx, cy), r, color);
};
+ circle(picture, c1, r, color);
};
// ehh should check bounding box instead of doing all pictures maybe