aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWarrick Lo <wlo@warricklo.net>2026-03-02 18:54:53 -0800
committerWarrick Lo <wlo@warricklo.net>2026-03-02 18:54:53 -0800
commitcadcf5cedb90c8f7c84043a0484fb5370cd1dae6 (patch)
tree003d47ce9dee17b4fb4f1a092b63df05f3b3c8c2
parentRemove plotting unused octants (diff)
Fix arc 1 not drawing when centre of circle 1 is off screen
Signed-off-by: Warrick Lo <wlo@warricklo.net>
-rw-r--r--task4/reuleaux.sv24
1 files changed, 12 insertions, 12 deletions
diff --git a/task4/reuleaux.sv b/task4/reuleaux.sv
index 68a3540..dbf57f8 100644
--- a/task4/reuleaux.sv
+++ b/task4/reuleaux.sv
@@ -16,15 +16,15 @@ module reuleaux(clk, rst_n, colour, centre_x, centre_y, diameter, start, done,
logic clear, ready, vga_plot_next;
logic [2:0] octant;
- logic [7:0] offset_x, offset_y, offset_x_next, offset_y_next;
- /* One bit larger since these are signed. */
- logic signed [7:0] vga_y_next;
- logic signed [8:0] vga_x_next, crit, crit_next;
+ /* Auxiliary value for calculations. 21-bit number since we multiply
+ * 8-bit and 13-bit numbers together. */
+ logic [20:0] diameter_scaled;
- logic [6:0] centre_y1, centre_y2, centre_y3;
- logic [7:0] centre_x1, centre_x2, centre_x3, radius;
- /* Auxiliary value for calculations. */
- logic [19:0] y_offset;
+ /* One bit larger since these are signed. */
+ logic signed [7:0] vga_y_next, offset_y, offset_y_next,
+ centre_y1, centre_y2, centre_y3;
+ logic signed [8:0] vga_x_next, offset_x, offset_x_next,
+ centre_x1, centre_x2, centre_x3, crit, crit_next, radius;
assign vga_colour = clear ? 3'b000 : colour;
/* Circle radius is the same as the Reuleaux triangle diameter. */
@@ -32,13 +32,13 @@ module reuleaux(clk, rst_n, colour, centre_x, centre_y, diameter, start, done,
/* sqrt(3)/3 * 2^12 = 2364.826...
* Add 2^(N-1) before shifting by N to round to the nearest integer. */
- assign y_offset = diameter * 2365;
+ assign diameter_scaled = diameter * 2365;
assign centre_x1 = centre_x;
- assign centre_y1 = centre_y - ((y_offset + (1 << 11)) >> 12);
+ assign centre_y1 = centre_y - ((diameter_scaled + (1 << 11)) >> 12);
assign centre_x2 = centre_x + (diameter >> 1);
- assign centre_y2 = centre_y + ((y_offset + (1 << 12)) >> 13);
+ assign centre_y2 = centre_y + ((diameter_scaled + (1 << 12)) >> 13);
assign centre_x3 = centre_x - (diameter >> 1);
- assign centre_y3 = centre_y + ((y_offset + (1 << 12)) >> 13);
+ assign centre_y3 = centre_y + ((diameter_scaled + (1 << 12)) >> 13);
/* Draw only the octants that are needed for each circle.
* Extra pixels will be taken care further below. */