Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[23_27] Fix bugs when drawing semicircle #2212

Merged
merged 3 commits into from
Jan 12, 2025

Conversation

wind1900
Copy link
Contributor

@wind1900 wind1900 commented Jan 4, 2025

What

Fix 2 little bugs.

  1. Can not draw the correct semicircle in current environment.
  2. There will be "division by zero" exception in console when you're choosing the third point and move mouse to center point (the first point).

Why

When drawing an arc, we first select the circle center c, then the start point p and end point x on the arc.
It will use these points to calculate a third point m on arc, and use p, m, x to draw the arc.
By default it's counterclockwise though it's called "Std-arc".
When we want to draw a semicircle, the angle between vec-c-p and vec-c-q is 180.
In the previous code, it uses vec-c-p as the third point m incorrectly.
We should still consider it's clockwise or counterclockwise here and then add the correct vector to the center point as the third point.
Before:
image

Fixed:
image

The distance of c and q as r1 is used to avoid the exception message in console, like

;/: division by zero, (/ 0.0 0.0)
;    (let ((n (length opts))) (cond ((= n...
;    D:\mogan\build\packages\app.mogan\data\progs\kernel\library\base.scm, line 270, position: 0
; (let ((n (length opts))) (cond ((= n 0) (... ; f: 0.0
; (f2s (/ (point-get-x pt) f))               ; pt: (point "0.0" "0.0")
; (list-values 'point (f2s (/ (point-get-x ...
; std-arc-helper: (equal? (point-get-unit v... ; vec-c-p: (point "2.0" "0.0")
;                                              vec-c-q: (point "0.0" "0.0")

How to test your changes?

Add a unit test so I can test it by xmake run 23_27

@da-liii da-liii changed the title Fix bugs when drawing semicircle [23_27] Fix bugs when drawing semicircle Jan 4, 2025
@da-liii da-liii requested a review from Oyyko January 4, 2025 09:21
@wind1900 wind1900 marked this pull request as ready for review January 9, 2025 11:35
@da-liii da-liii requested a review from JackYansongLi January 9, 2025 14:49
Copy link
Contributor

@Oyyko Oyyko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm.

@da-liii da-liii merged commit 21da23f into XmacsLabs:branch-1.2 Jan 12, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants