Skip to content

Commit

Permalink
Fix clockwise arc rendering in raster renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
Argmaster committed May 30, 2024
1 parent d7bf2e7 commit ccc4813
Show file tree
Hide file tree
Showing 70 changed files with 764 additions and 71 deletions.
55 changes: 48 additions & 7 deletions src/pygerber/gerberx3/renderer2/raster.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,8 +483,8 @@ def render_arc(self, command: Arc2) -> None:
self.frame.arc(
command.transform.polarity,
bbox,
start_angle,
end_angle,
start_angle,
width=self.convert_size(command.aperture.get_stroke_width()),
)

Expand All @@ -500,12 +500,53 @@ def render_arc(self, command: Arc2) -> None:

def render_cc_arc(self, command: CCArc2) -> None:
"""Render arc to target image."""
return self.render_arc(
command.model_copy(
update={
"start_point": command.start_point,
"end_point": command.end_point,
},
command.aperture.render_flash(
self.renderer,
Flash2(
transform=command.transform,
attributes=command.attributes,
aperture=command.aperture,
flash_point=command.start_point,
),
)

start_angle = (
command.get_relative_start_point().angle_between(
Vector2D.UNIT_X,
)
% 360
)
end_angle = (
command.get_relative_end_point().angle_between(
Vector2D.UNIT_X,
)
% 360
)
bbox = self.convert_bbox(
BoundingBox.from_diameter(
(command.get_radius() * 2) + (command.aperture.get_stroke_width()),
)
+ command.center_point,
)

if end_angle <= start_angle:
end_angle += 360

self.frame.arc(
command.transform.polarity,
bbox,
start_angle,
end_angle,
width=self.convert_size(command.aperture.get_stroke_width()),
)

command.aperture.render_flash(
self.renderer,
Flash2(
transform=command.transform,
attributes=command.attributes,
aperture=command.aperture,
flash_point=command.end_point,
),
)

Expand Down
19 changes: 19 additions & 0 deletions test/assets/gerberx3/arc/clockwise/cw_full.grb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
%FSLAX26Y26*%
%MOMM*%
%ADD100C,0.5*%
%ADD101C,0.1*%
G04 Draw orientation axes for reference.*
D101*
G01*
X0000000Y-2000000D02*
X0000000Y2000000D01*
X-2000000Y0000000D02*
X2000000Y0000000D01*
X0000000Y0000000D02*
G04 Draw an arc for testing purposes.*
D100*
G75*
G02*
X-2000000Y0D02*
X-2000000Y0I2000000J0D01*
M02*
Binary file added test/assets/gerberx3/arc/clockwise/cw_full.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions test/assets/gerberx3/arc/clockwise/half/cw_bot_half.grb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
%FSLAX26Y26*%
%MOMM*%
%ADD100C,0.5*%
%ADD101C,0.1*%
G04 Draw orientation axes for reference.*
D101*
G01*
X0000000Y-2000000D02*
X0000000Y2000000D01*
X-2000000Y0000000D02*
X2000000Y0000000D01*
X0000000Y0000000D02*
G04 Draw an arc for testing purposes.*
D100*
G75*
G02*
X2000000Y0000000D02*
X-2000000Y0000000I-2000000J0000000D01*
M02*
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions test/assets/gerberx3/arc/clockwise/half/cw_left_half.grb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
%FSLAX26Y26*%
%MOMM*%
%ADD100C,0.5*%
%ADD101C,0.1*%
G04 Draw orientation axes for reference.*
D101*
G01*
X0000000Y-2000000D02*
X0000000Y2000000D01*
X-2000000Y0000000D02*
X2000000Y0000000D01*
X0000000Y0000000D02*
G04 Draw an arc for testing purposes.*
D100*
G75*
G02*
X0Y-2000000D02*
X0Y2000000I0J2000000D01*
M02*
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions test/assets/gerberx3/arc/clockwise/half/cw_right_half.grb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
%FSLAX26Y26*%
%MOMM*%
%ADD100C,0.5*%
%ADD101C,0.1*%
G04 Draw orientation axes for reference.*
D101*
G01*
X0000000Y-2000000D02*
X0000000Y2000000D01*
X-2000000Y0000000D02*
X2000000Y0000000D01*
X0000000Y0000000D02*
G04 Draw an arc for testing purposes.*
D100*
G75*
G02*
X0Y2000000D02*
X0Y-2000000I0J-2000000D01*
M02*
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions test/assets/gerberx3/arc/clockwise/half/cw_top_half.grb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
%FSLAX26Y26*%
%MOMM*%
%ADD100C,0.5*%
%ADD101C,0.1*%
G04 Draw orientation axes for reference.*
D101*
G01*
X0000000Y-2000000D02*
X0000000Y2000000D01*
X-2000000Y0000000D02*
X2000000Y0000000D01*
X0000000Y0000000D02*
G04 Draw an arc for testing purposes.*
D100*
G75*
G02*
X-2000000Y0000000D02*
X2000000Y0000000I2000000J0000000D01*
M02*
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions test/assets/gerberx3/arc/clockwise/quarter/cw_bot_left_q.grb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
%FSLAX26Y26*%
%MOMM*%
%ADD100C,0.5*%
%ADD101C,0.1*%
G04 Draw orientation axes for reference.*
D101*
G01*
X0000000Y-2000000D02*
X0000000Y2000000D01*
X-2000000Y0000000D02*
X2000000Y0000000D01*
X0000000Y0000000D02*
G04 Draw an arc for testing purposes.*
D100*
G75*
G02*
X0Y-2000000D02*
X-2000000Y0I0J2000000D01*
M02*
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions test/assets/gerberx3/arc/clockwise/quarter/cw_bot_right_q.grb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
%FSLAX26Y26*%
%MOMM*%
%ADD100C,0.5*%
%ADD101C,0.1*%
G04 Draw orientation axes for reference.*
D101*
G01*
X0000000Y-2000000D02*
X0000000Y2000000D01*
X-2000000Y0000000D02*
X2000000Y0000000D01*
X0000000Y0000000D02*
G04 Draw an arc for testing purposes.*
D100*
G75*
G02*
X2000000Y0000000D02*
X0000000Y-2000000I-2000000J0D01*
M02*
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions test/assets/gerberx3/arc/clockwise/quarter/cw_top_left_q.grb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
%FSLAX26Y26*%
%MOMM*%
%ADD100C,0.5*%
%ADD101C,0.1*%
G04 Draw orientation axes for reference.*
D101*
G01*
X0000000Y-2000000D02*
X0000000Y2000000D01*
X-2000000Y0000000D02*
X2000000Y0000000D01*
X0000000Y0000000D02*
G04 Draw an arc for testing purposes.*
D100*
G75*
G02*
X-2000000Y0D02*
X0000000Y2000000I2000000J0D01*
M02*
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions test/assets/gerberx3/arc/clockwise/quarter/cw_top_right_q.grb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
%FSLAX26Y26*%
%MOMM*%
%ADD100C,0.5*%
%ADD101C,0.1*%
G04 Draw orientation axes for reference.*
D101*
G01*
X0000000Y-2000000D02*
X0000000Y2000000D01*
X-2000000Y0000000D02*
X2000000Y0000000D01*
X0000000Y0000000D02*
G04 Draw an arc for testing purposes.*
D100*
G75*
G02*
X0Y2000000D02*
X2000000Y0000000I0J-2000000D01*
M02*
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions test/assets/gerberx3/arc/clockwise/three_fourth/cw_bot_left_tf.grb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
%FSLAX26Y26*%
%MOMM*%
%ADD100C,0.5*%
%ADD101C,0.1*%
G04 Draw orientation axes for reference.*
D101*
G01*
X0000000Y-2000000D02*
X0000000Y2000000D01*
X-2000000Y0000000D02*
X2000000Y0000000D01*
X0000000Y0000000D02*
G04 Draw an arc for testing purposes.*
D100*
G75*
G02*
X-2000000Y0D02*
X0000000Y-2000000I2000000J0D01*
M02*
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
%FSLAX26Y26*%
%MOMM*%
%ADD100C,0.5*%
%ADD101C,0.1*%
G04 Draw orientation axes for reference.*
D101*
G01*
X0000000Y-2000000D02*
X0000000Y2000000D01*
X-2000000Y0000000D02*
X2000000Y0000000D01*
X0000000Y0000000D02*
G04 Draw an arc for testing purposes.*
D100*
G75*
G02*
X0Y-2000000D02*
X2000000Y0I0J2000000D01*
M02*
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions test/assets/gerberx3/arc/clockwise/three_fourth/cw_top_left_tf.grb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
%FSLAX26Y26*%
%MOMM*%
%ADD100C,0.5*%
%ADD101C,0.1*%
G04 Draw orientation axes for reference.*
D101*
G01*
X0000000Y-2000000D02*
X0000000Y2000000D01*
X-2000000Y0000000D02*
X2000000Y0000000D01*
X0000000Y0000000D02*
G04 Draw an arc for testing purposes.*
D100*
G75*
G02*
X0Y2000000D02*
X-2000000Y0000000I0J-2000000D01*
M02*
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
%FSLAX26Y26*%
%MOMM*%
%ADD100C,0.5*%
%ADD101C,0.1*%
G04 Draw orientation axes for reference.*
D101*
G01*
X0000000Y-2000000D02*
X0000000Y2000000D01*
X-2000000Y0000000D02*
X2000000Y0000000D01*
X0000000Y0000000D02*
G04 Draw an arc for testing purposes.*
D100*
G75*
G02*
X2000000Y0000000D02*
X0000000Y2000000I-2000000J0D01*
M02*
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions test/assets/gerberx3/arc/counterclockwise/ccw_full.grb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
%FSLAX26Y26*%
%MOMM*%
%ADD100C,0.5*%
%ADD101C,0.1*%
G04 Draw orientation axes for reference.*
D101*
G01*
X0000000Y-2000000D02*
X0000000Y2000000D01*
X-2000000Y0000000D02*
X2000000Y0000000D01*
X0000000Y0000000D02*
G04 Draw an arc for testing purposes.*
D100*
G75*
G02*
X-2000000Y0D02*
X-2000000Y0I2000000J0D01*
M02*
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions test/assets/gerberx3/arc/counterclockwise/half/ccw_bot_half.grb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
%FSLAX26Y26*%
%MOMM*%
%ADD100C,0.5*%
%ADD101C,0.1*%
G04 Draw orientation axes for reference.*
D101*
G01*
X0000000Y-2000000D02*
X0000000Y2000000D01*
X-2000000Y0000000D02*
X2000000Y0000000D01*
X0000000Y0000000D02*
G04 Draw an arc for testing purposes.*
D100*
G75*
G03*
X-2000000Y0000000D02*
X2000000Y0000000I2000000J0000000D01*
M02*
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions test/assets/gerberx3/arc/counterclockwise/half/ccw_left_half.grb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
%FSLAX26Y26*%
%MOMM*%
%ADD100C,0.5*%
%ADD101C,0.1*%
G04 Draw orientation axes for reference.*
D101*
G01*
X0000000Y-2000000D02*
X0000000Y2000000D01*
X-2000000Y0000000D02*
X2000000Y0000000D01*
X0000000Y0000000D02*
G04 Draw an arc for testing purposes.*
D100*
G75*
G03*
X0Y2000000D02*
X0Y-2000000I0J-2000000D01*
M02*
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit ccc4813

Please sign in to comment.