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

Da/unit test demo #2214

Draft
wants to merge 2 commits into
base: branch-1.2
Choose a base branch
from
Draft
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
16 changes: 10 additions & 6 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))
(r1 (points-distance c q))
(x (if (equal? r 0.0)
c
(points-add (point-times (point-get-unit (points-sub q c)) r) c)))
(if (equal? r1 0.0)
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 (equal? r 0.0) (equal? r1 0.0))
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 >))

Expand Down
21 changes: 21 additions & 0 deletions TeXmacs/tests/23_27.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
(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)
(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)))
Loading