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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions TeXmacs/progs/graphics/graphics-markup.scm
Original file line number Diff line number Diff line change
Expand Up @@ -87,28 +87,32 @@
(p (if (tm-point? P) (tree->stree P) c))
(q (if (tm-point? Q) (tree->stree Q) p))
(r (points-distance c p))
(x (if (equal? r 0.0)
(r1 (points-distance c q))
(x (if (zero? r)
c
(points-add (point-times (point-get-unit (points-sub q c)) r) c)))
(if (zero? r1)
p
(points-add (point-times (point-get-unit (points-sub q c)) r) c))))
(mid-p-x (points-mid p x))
(vec-c-p (points-sub p c))
(vec-c-q (points-sub q c))
(m (if (equal? r 0.0)
c
(m (if (or (zero? r) (zero? r1))
x
(if (clockwise (points-cross-product-k vec-c-p vec-c-q) 0)
(points-add (point-times (point-get-unit (points-sub mid-p-x c)) (- r)) c)
(if (= (points-cross-product-k vec-c-p vec-c-q) 0)
da-liii marked this conversation as resolved.
Show resolved Hide resolved
;; If cross product == 0, then the angle between vec-c-p and vec-c-q is 0 or 180.
;; We should find out whether it's 0 or 180.
;; And we should determine whether it's clockwise or counterclockwise.
(if (equal? (point-get-unit vec-c-p) (point-get-unit vec-c-q))
x
(point-rotate-90 (point-rotate-90 (point-rotate-90 vec-c-p))))
(if (eq? clockwise >)
(points-add (point-rotate-90 (point-rotate-90 (point-rotate-90 vec-c-p))) c)
(points-add (point-rotate-90 vec-c-p) c)))
(points-add (point-times (point-get-unit (points-sub mid-p-x c)) r) c))))))
`(arc ,p ,m ,x)))




(define-graphics (std-arc C P Q)
(std-arc-helper C P Q >))

Expand Down
78 changes: 78 additions & 0 deletions TeXmacs/tests/23_27.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
(import (liii check)
(liii os))

; Because std-arc-helper is using define, it is not using tm-define
; We have to load the module directly
;
; (texmacs-module (tests 23_27)
; (:use (graphics graphics-markup)))
(load (string-append (getenv "TEXMACS_PATH") "/progs/graphics/graphics-markup.scm"))

(define (point x y)
(stree->tree `(point ,x ,y)))

(define (test-std-arc-helper)
;c==p==q
(check (std-arc-helper (point "0" "0") (point "0" "0") (point "0" "0") #f)
=> `(arc (point "0" "0")
(point "0" "0")
(point "0" "0")))
;c==p
(check (std-arc-helper (point "0" "0") (point "0" "0") (point "1" "1") #f)
=> `(arc (point "0" "0")
(point "0" "0")
(point "0" "0")))
;c==q
(check (std-arc-helper (point "0" "0") (point "1" "1") (point "0" "0") #f)
=> `(arc (point "1" "1")
(point "1" "1")
(point "1" "1")))
;p==q
(check (std-arc-helper (point "0" "0") (point "1" "0") (point "1" "0") >)
=> `(arc (point "1" "0")
(point "1.0" "0.0")
(point "1.0" "0.0")))
(check (std-arc-helper (point "0" "0") (point "1" "0") (point "1" "0") <)
=> `(arc (point "1" "0")
(point "1.0" "0.0")
(point "1.0" "0.0")))
;cross-product==0, angle is 0 degree
(check (std-arc-helper (point "0" "0") (point "1" "0") (point "2" "0") >)
=> `(arc (point "1" "0")
(point "1.0" "0.0")
(point "1.0" "0.0")))
(check (std-arc-helper (point "0" "0") (point "1" "0") (point "2" "0") <)
=> `(arc (point "1" "0")
(point "1.0" "0.0")
(point "1.0" "0.0")))
;cross-product==0, angle is 180 degree
(check (std-arc-helper (point "0" "0") (point "1" "0") (point "-2" "0") >)
=> `(arc (point "1" "0")
(point "0.0" "-1.0")
(point "-1.0" "0.0")))
(check (std-arc-helper (point "0" "0") (point "1" "0") (point "-2" "0") <)
=> `(arc (point "1" "0")
(point "0.0" "1.0")
(point "-1.0" "0.0")))
;cross-product!=0
(check (std-arc-helper (point "0" "0") (point "1" "0") (point "0" "1") >)
=> `(arc (point "1" "0")
(point "-0.7071067811865475" "-0.7071067811865475")
(point "0.0" "1.0")))
(check (std-arc-helper (point "0" "0") (point "1" "0") (point "0" "-1") >)
=> `(arc (point "1" "0")
(point "0.7071067811865475" "-0.7071067811865475")
(point "0.0" "-1.0")))
(check (std-arc-helper (point "0" "0") (point "1" "0") (point "0" "1") <)
=> `(arc (point "1" "0")
(point "0.7071067811865475" "0.7071067811865475")
(point "0.0" "1.0")))
(check (std-arc-helper (point "0" "0") (point "1" "0") (point "0" "-1") <)
=> `(arc (point "1" "0")
(point "-0.7071067811865475" "0.7071067811865475")
(point "0.0" "-1.0"))))

(define (test_23_27)
(test-std-arc-helper)
(check-report)
(if (check-failed?) (exit -1)))