diff --git a/TeXmacs/progs/graphics/graphics-markup.scm b/TeXmacs/progs/graphics/graphics-markup.scm index e8f2645d9b..b004b16877 100644 --- a/TeXmacs/progs/graphics/graphics-markup.scm +++ b/TeXmacs/progs/graphics/graphics-markup.scm @@ -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) ;; 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 >)) diff --git a/TeXmacs/tests/23_27.scm b/TeXmacs/tests/23_27.scm new file mode 100644 index 0000000000..4a22da8a87 --- /dev/null +++ b/TeXmacs/tests/23_27.scm @@ -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))) \ No newline at end of file