aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWarrick Lo <wlo@warricklo.net>2026-03-02 10:56:24 -0800
committerWarrick Lo <wlo@warricklo.net>2026-03-02 10:56:24 -0800
commitaaac26875f8999e16b05c620ea4ae6287ff44aff (patch)
tree095fc69720a7d18f79fe95e9724e791fe3b41a83
parentAdd main Reuleaux triangle geometry code for task 4 (diff)
Fix extra pixels plotting on the Reuleaux triangle
Signed-off-by: Warrick Lo <wlo@warricklo.net>
-rw-r--r--task4/reuleaux.sv32
1 files changed, 21 insertions, 11 deletions
diff --git a/task4/reuleaux.sv b/task4/reuleaux.sv
index 0b08225..b6c35a2 100644
--- a/task4/reuleaux.sv
+++ b/task4/reuleaux.sv
@@ -31,8 +31,7 @@ module reuleaux(clk, rst_n, colour, centre_x, centre_y, diameter, start, done,
assign radius = diameter;
/* sqrt(3)/3 * 2^12 = 2364.826...
- * Add 2^(N-1) before shifting by N to round
- * to the nearest integer. */
+ * Add 2^(N-1) before shifting by N to round to the nearest integer. */
assign y_offset = diameter * 2365;
assign centre_x1 = centre_x;
assign centre_y1 = centre_y - ((y_offset + (1 << 11)) >> 12);
@@ -45,50 +44,60 @@ module reuleaux(clk, rst_n, colour, centre_x, centre_y, diameter, start, done,
* - circle 1: octants 2 & 3;
* - circle 2: octants 5 & 6;
* - circle 3: octants 7 & 8.
- * Extra pixels will be taken care further below (not implemented). */
+ * Extra pixels will be taken care further below. */
always_comb case (octant)
3'd0: begin
- vga_plot_next = 1'b0;
vga_x_next = centre_x + offset_x;
vga_y_next = centre_y + offset_y;
end
3'd1: begin
- vga_plot_next = 1'b1;
vga_x_next = centre_x1 + offset_y;
vga_y_next = centre_y1 + offset_x;
end
3'd2: begin
- vga_plot_next = 1'b1;
vga_x_next = centre_x1 - offset_y;
vga_y_next = centre_y1 + offset_x;
end
3'd3: begin
- vga_plot_next = 1'b0;
vga_x_next = centre_x - offset_x;
vga_y_next = centre_y + offset_y;
end
3'd4: begin
- vga_plot_next = 1'b1;
vga_x_next = centre_x2 - offset_x;
vga_y_next = centre_y2 - offset_y;
end
3'd5: begin
- vga_plot_next = 1'b1;
vga_x_next = centre_x2 - offset_y;
vga_y_next = centre_y2 - offset_x;
end
3'd6: begin
- vga_plot_next = 1'b1;
vga_x_next = centre_x3 + offset_y;
vga_y_next = centre_y3 - offset_x;
end
3'd7: begin
- vga_plot_next = 1'b1;
vga_x_next = centre_x3 + offset_x;
vga_y_next = centre_y3 - offset_y;
end
endcase
+ /* Only plot the pixels of the triangle. */
+ always_comb begin
+ vga_plot_next = 1'b0;
+ /* Pixels of circle 1 that are below the centre of 2 or 3. */
+ if ((octant == 3'd1) || (octant == 3'd2))
+ if (vga_y_next > centre_y2)
+ vga_plot_next = 1'b1;
+ /* Pixels of circle 2 that are to the left of the centre. */
+ if ((octant == 3'd4) || (octant == 3'd5))
+ if (vga_x_next <= centre_x)
+ vga_plot_next = 1'b1;
+ /* Pixels of circle 3 that are to the right of the centre. */
+ if ((octant == 3'd6) || (octant == 3'd7))
+ if (vga_x_next >= centre_x)
+ vga_plot_next = 1'b1;
+ end
+
+ /* Main combinational logic for the Bresenham circle algorithm. */
always_comb begin
offset_x_next = offset_x;
offset_y_next = offset_y + 1;
@@ -172,4 +181,5 @@ module reuleaux(clk, rst_n, colour, centre_x, centre_y, diameter, start, done,
end else if (~start && done)
done <= 1'b0;
end
+
endmodule: reuleaux