-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshapes.lisp
177 lines (155 loc) · 6.21 KB
/
shapes.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
(in-package :gcode)
(defun rectangle (width height &key ccw)
"Draws a rectangle of width WIDTH and height HEIGHT starting from current position."
(let ((right (> width 0))
(up (> height 0)))
;; check if we are clockwise or not
(unless (eql right up)
(setf ccw (not ccw))))
(if ccw
(progn (mill-rel :x width :y 0)
(mill-rel :x 0 :y height)
(mill-rel :x (- width) :y 0)
(mill-rel :x 0 :y (- height)))
(progn (mill-rel :x 0 :y height)
(mill-rel :x width :y 0)
(mill-rel :x 0 :y (- height))
(mill-rel :x (- width) :y 0))))
(defun rectangle-fill (width height offset &key ccw)
(when (or (> offset width)
(> offset height))
(error "can't rectangle fill ~A x ~A with offset ~A" width height offset))
(let ((right (> width 0))
(up (> height 0)))
(unless (eql right up)
(setf ccw (not ccw))))
(with-rel-back-xy ()
(if ccw
(spiral-width width height offset)
(spiral-height width height offset))))
(defun spiral-width (width height offset)
(loop until (or (= width 0)
(= height 0))
do
;; (format t "x: ~A, y : ~A~%" (current-x) (current-x))
(mill-rel :x width :y 0)
(mill-rel :x 0 :y height)
(setf width (max 0 (- width offset)))
(setf height (max 0 (- height offset)))
(mill-rel :x (- width) :y 0)
(mill-rel :x 0 :y (- height))
(setf width (max 0 (- width offset)))
(setf height (max 0 (- height offset)))))
(defun spiral-height (width height offset)
(loop until (or (= width 0)
(= height 0))
do
;;(format t "x: ~A, y : ~A~%" (current-x) (current-x))
(mill-rel :x 0 :y height)
(mill-rel :x width :y 0)
(setf height (max 0 (- height offset)))
(setf width (max 0 (- width offset)))
(mill-rel :x 0 :y (- height))
(mill-rel :x (- width) :y 0)
(setf height (max 0 (- height offset)))
(setf width (max 0 (- width offset)))))
;; mills with going into object
(defun rectangle-outline (width height &key (depth (tool-depth *current-tool*))
ccw)
(let ((offset (/ (tool-diameter *current-tool*) 2.0)))
(goto-rel :x (* -1 (sign width) offset)
:y (* -1 (sign height) offset))
(repeat-for-depth (depth)
(rectangle (+ width offset) (+ height offset) :ccw ccw))))
(defun rectangle-inline (width height &key (depth (tool-depth *current-tool*)) ccw)
(let ((offset (/ (tool-diameter *current-tool*) 2.0)))
(goto-rel :x (* 1 (sign width) offset)
:y (* 1 (sign height) offset))
(repeat-for-depth (depth)
(rectangle (- width (tool-diameter *current-tool*))
(- height (tool-diameter *current-tool*))
:ccw ccw))))
(defun rectangle-mill (width height &key depth ccw)
(let ((offset (/ (tool-diameter *current-tool*) 2.0)))
(goto-rel :x (* 1 (sign width) offset)
:y (* 1 (sign height) offset))
(repeat-for-depth (depth)
(rectangle-fill (- width (tool-diameter *current-tool*))
(- height (tool-diameter *current-tool*))
(tool-diameter *current-tool*) :ccw ccw))))
;; assume head is at 0, x = cx, y = cy - radius/2 (bottom tangent point)
(defun circle (radius &key ccw)
(if ccw
(progn
(arc-ccw-rel :x radius :y radius :i 0 :j radius :f (tool-feed-z *current-tool*))
(arc-ccw-rel :x (- radius) :y radius :i (- radius) :j 0)
(arc-ccw-rel :x (- radius) :y (- radius) :i 0 :j (- radius))
(arc-ccw-rel :x radius :y (- radius) :i radius :j 0))
(progn
(arc-cw-rel :x (- radius) :y radius :i 0 :j radius :f (tool-feed-z *current-tool*))
(arc-cw-rel :x radius :y radius :i radius :j 0)
(arc-cw-rel :x radius :y (- radius) :i 0 :j (- radius))
(arc-cw-rel :x (- radius) :y (- radius) :i (- radius) :j 0))))
#+nil(defun make-circle (radius &key ccw)
(if ccw
(progn
(arc-ccw-rel :x radius :y radius :i 0 :j radius :f (tool-feed-z *current-tool*))
(arc-ccw-rel :x (- radius) :y radius :i (- radius) :j 0)
(arc-ccw-rel :x (- radius) :y (- radius) :i 0 :j (- radius))
(arc-ccw-rel :x radius :y (- radius) :i radius :j 0))
(progn
(arc-cw-rel :x (- radius) :y radius :i 0 :j radius :f (tool-feed-z *current-tool*))
(arc-cw-rel :x radius :y radius :i radius :j 0)
(arc-cw-rel :x radius :y (- radius) :i 0 :j (- radius))
(arc-cw-rel :x (- radius) :y (- radius) :i (- radius) :j 0))))
(defun p5-circle (x y width)
(decf width (+ (tool-diameter *current-tool*) 5))
(goto-abs :x x :y (- y (/ width 2)))
(with-tool-down ()
(circle (/ width 2))))
(defun drill (&key x y diameter (depth (tool-depth *current-tool*)))
(when (< diameter (tool-diameter *current-tool*))
(warn "Can not drill hole that is ~A big, resorting to ~A~%"
diameter (tool-diameter *current-tool*))
(setf diameter (tool-diameter *current-tool*)))
#+nil(format t "depth: ~A~%" depth)
(let ((d (/ (- diameter (tool-diameter *current-tool*)) 2)))
(goto-abs :x x :y (- y d))
(if (= d 0)
(progn
(tool-down :depth depth)
(tool-up))
(repeat-for-depth (depth)
(circle d)))))
(defun circle-fill (radius offset &key ccw)
(when (> offset radius)
(error "Can't circle-fill radius ~A with offset ~A" radius offset))
(with-rel-back-xy ()
(circle-spiral radius offset :ccw ccw)))
(defun circle-spiral (radius offset &key ccw)
(let* ((cur-y 0)
(cur-r radius))
(loop for next-y = (min (- radius (/ offset 2))
(+ cur-y offset))
for next-r = (max (/ offset 2)
(- cur-r offset))
do (progn (circle cur-r :ccw ccw)
(mill-rel :y (- next-y cur-y)))
until (= cur-r (/ offset 2))
do (setf cur-y next-y cur-r next-r))))
(defun circle-inline (radius &key ccw depth)
(let ((offset (/ (tool-diameter *current-tool*) 2.0)))
(goto-rel :y offset)
(repeat-for-depth (depth)
(circle (- radius offset) :ccw ccw))))
(defun circle-outline (radius &key ccw depth)
(let ((offset (/ (tool-diameter *current-tool*) 2.0)))
(goto-rel :y (- offset))
(repeat-for-depth (depth)
(circle (+ radius offset) :ccw ccw))))
(defun circle-mill (radius &key (depth (tool-depth *current-tool*)) ccw)
(let ((offset (/ (tool-diameter *current-tool*) 2.0)))
(goto-rel :y offset)
(repeat-for-depth (depth)
(circle-fill (- radius offset)
(tool-diameter *current-tool*) :ccw ccw))))