Skip to content

Commit 4b6d274

Browse files
committed
Round out the float changes
1 parent e8fd2a8 commit 4b6d274

32 files changed

Lines changed: 471 additions & 259 deletions

File tree

STATUS.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ Consildated all `sin` operations to use `r_sin`.
3737

3838
Consildated all `sqrt` operations to use `vp-sqrt-ff`.
3939

40+
`list-bind-args` now take optional destination reg list. To better fit with
41+
extracting `real` register values from objects.
42+
43+
Renamed application level `vec-xxx` functions to `vector-xxx` to avoid clashing
44+
with the `sys_math` class.
45+
46+
`:quant` method added to real and reals classes. `(quant real tol) -> real` and
47+
`(reals-quant reals tol [reals]) -> reals)` added to `root.inc`.
48+
4049
------
4150

4251
New `class/mstream/class.inc` VP class for in memory stream buffers. A seekable

apps/bubbles/app.inc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,22 @@
1010

1111
(cond ;pick number format :t/:nil
1212
(:t ;reals
13-
(defmacro vec (&rest _) `(reals ~_))
13+
(defmacro vector (&rest _) `(reals ~_))
1414
(defmacro i2n (_) `(n2r ,_))
1515
(defmacro f2n (_) `(n2r ,_)))
1616
(:t ;fixed point
17-
(defmacro vec (&rest _) `(fixeds ~_))
17+
(defmacro vector (&rest _) `(fixeds ~_))
1818
(defmacro i2n (_) `(n2f ,_))
1919
(defmacro f2n (_) _)))
2020

21-
(defmacro vec-n2f (&rest _)
21+
(defmacro vector-n2f (&rest _)
2222
(static-qq (fixeds ~(map (lambda (_) (list 'n2f _)) _))))
2323
24-
(defmacro vec-i2n (&rest _)
25-
(static-qq (vec ~(map (lambda (_) (list 'i2n _)) _))))
24+
(defmacro vector-i2n (&rest _)
25+
(static-qq (vector ~(map (lambda (_) (list 'i2n _)) _))))
2626

27-
(defmacro vec-f2n (&rest _)
28-
(static-qq (vec ~(map (lambda (_) (list 'f2n _)) _))))
27+
(defmacro vector-f2n (&rest _)
28+
(static-qq (vector ~(map (lambda (_) (list 'f2n _)) _))))
2929
3030
(enums +dlist 0
3131
(enum mask light_pos layer1_canvas layer1_verts))
@@ -37,4 +37,4 @@
3737
(enum p v r c))
3838
3939
(defq box_size 500 focal_len 1 max_vel 5 num_bubbles 50 bubble_radius 70
40-
light_pos (vec-i2n (neg box_size) (neg box_size) (neg (* box_size 4))))
40+
light_pos (vector-i2n (neg box_size) (neg box_size) (neg (* box_size 4))))

apps/bubbles/app.lisp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
(defq +width 600 +height 600 +min_width 300 +min_height 300
1313
+rate (/ 1000000 60) +base 0.3
14-
+palette (push `(,quote) (map (lambda (_) (vec-i2n
14+
+palette (push `(,quote) (map (lambda (_) (vector-i2n
1515
(/ (logand (>> _ 16) 0xff) 0xff)
1616
(/ (logand (>> _ 8) 0xff) 0xff)
1717
(/ (logand _ 0xff) 0xff)))
@@ -39,21 +39,21 @@
3939
(defq out (cap num (list)))
4040
(while (> (-- num) -1)
4141
(push out (list
42-
(vec-i2n (- (random (const (* box_size 2))) box_size)
42+
(vector-i2n (- (random (const (* box_size 2))) box_size)
4343
(- (random (const (* box_size 2))) box_size)
4444
(- (random (const (* box_size 2))) box_size))
45-
(vec-i2n (- (random (const (inc (* max_vel 2)))) (const max_vel))
45+
(vector-i2n (- (random (const (inc (* max_vel 2)))) (const max_vel))
4646
(- (random (const (inc (* max_vel 2)))) (const max_vel))
4747
(- (random (const (inc (* max_vel 2)))) (const max_vel)))
4848
(i2n (const bubble_radius))
49-
(vec-add (const (vec-f2n +base +base +base))
50-
(vec-scale (elem-get +palette (random (length +palette)))
49+
(vector-add (const (vector-f2n +base +base +base))
50+
(vector-scale (elem-get +palette (random (length +palette)))
5151
(f2n (random (const (- 1.0 +base))))))))) out)
5252

5353
(defun vertex-update (verts)
5454
(each (lambda (vert)
5555
(bind '(p v _ _) vert)
56-
(vec-add p v p)
56+
(vector-add p v p)
5757
(bind '(x y z) p)
5858
(bind '(vx vy vz) v)
5959
(if (or (> x (const (i2n box_size))) (< x (const (i2n (neg box_size)))))
@@ -62,7 +62,7 @@
6262
(setq vy (neg vy)))
6363
(if (or (> z (const (i2n box_size))) (< z (const (i2n (neg box_size)))))
6464
(setq vz (neg vz)))
65-
(elem-set vert +vertex_v (vec vx vy vz))) verts))
65+
(elem-set vert +vertex_v (vector vx vy vz))) verts))
6666

6767
(defun fpoly (canvas col x y _)
6868
;draw a polygon on a canvas
@@ -86,13 +86,13 @@
8686
(reduce (lambda (out ((x y z) _ r c))
8787
(setq z (+ z (const (i2n (+ (* box_size 2) max_vel)))))
8888
(when (> z (const (i2n focal_len)))
89-
(defq v (vec x y z) w (/ hsw z) h (/ hsh z))
90-
(bind '(sx sy sz) (vec-add v (vec-scale (vec-norm
91-
(vec-add v (vec-sub (elem-get dlist +dlist_light_pos) v))) r)))
89+
(defq v (vector x y z) w (/ hsw z) h (/ hsh z))
90+
(bind '(sx sy sz) (vector-add v (vector-scale (vector-norm
91+
(vector-add v (vector-sub (elem-get dlist +dlist_light_pos) v))) r)))
9292
(defq x (+ (* x h) hsw) y (+ (* y h) hsh) r (* r h)
9393
sx (+ (* sx h) hsw) sy (+ (* sy h) hsh))
94-
(push out (list (vec-n2f x y z) (vec-n2f sx sy) (n2f r)
95-
(lighting c z) (lighting (const (vec-i2n 1 1 1)) z)))) out)
94+
(push out (list (vector-n2f x y z) (vector-n2f sx sy) (n2f r)
95+
(lighting c z) (lighting (const (vector-i2n 1 1 1)) z)))) out)
9696
verts (cap (length verts) (list))))
9797

9898
(defun render-verts (canvas verts)
@@ -187,7 +187,7 @@
187187
(setq last_state :d)))
188188
;set light pos
189189
(elem-set dlist +dlist_light_pos
190-
(vec-i2n (* rx 4) (* ry 4) (neg (* box_size 4)))))
190+
(vector-i2n (* rx 4) (* ry 4) (neg (* box_size 4)))))
191191
(:t ;mouse button is up
192192
(case last_state
193193
(:d ;was down last time

apps/eyes/app.lisp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,11 @@
9999

100100
; --- Left Eye ---
101101
(defq vec_to_mouse (Vec2-f (- rel_mx left_eye_cx) (- rel_my eye_cy))
102-
dist_to_mouse (vec-length vec_to_mouse)
102+
dist_to_mouse (vector-length vec_to_mouse)
103103
iris_offset (if (> dist_to_mouse 0.0)
104-
(vec-scale (vec-norm vec_to_mouse) (min dist_to_mouse max_iris_dist))
104+
(vector-scale (vector-norm vec_to_mouse) (min dist_to_mouse max_iris_dist))
105105
(Vec2-f 0.0 0.0)))
106-
(bind '(l_iris_px l_iris_py) (vec-add (Vec2-f left_eye_cx eye_cy) iris_offset))
106+
(bind '(l_iris_px l_iris_py) (vector-add (Vec2-f left_eye_cx eye_cy) iris_offset))
107107

108108
; Draw left eye
109109
(.-> *canvas*
@@ -118,11 +118,11 @@
118118

119119
; --- Right Eye ---
120120
(defq vec_to_mouse (Vec2-f (- rel_mx right_eye_cx) (- rel_my eye_cy))
121-
dist_to_mouse (vec-length vec_to_mouse)
121+
dist_to_mouse (vector-length vec_to_mouse)
122122
iris_offset (if (> dist_to_mouse 0.0)
123-
(vec-scale (vec-norm vec_to_mouse) (min dist_to_mouse max_iris_dist))
123+
(vector-scale (vector-norm vec_to_mouse) (min dist_to_mouse max_iris_dist))
124124
(Vec2-f 0.0 0.0)))
125-
(bind '(r_iris_px r_iris_py) (vec-add (Vec2-f right_eye_cx eye_cy) iris_offset))
125+
(bind '(r_iris_px r_iris_py) (vector-add (Vec2-f right_eye_cx eye_cy) iris_offset))
126126

127127
; Draw right eye
128128
(.-> *canvas*

apps/mandelbrot/lisp.vp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,10 @@
2424
(errorif-lisp-args-sig 'error :r1 2)
2525

2626
(vp-push :r0)
27-
(array-bind-args :r1 `(,ox0 ,oy0))
28-
(assign `((,ox0 num_value) (,oy0 num_value)) `(,x0 ,y0))
27+
(list-bind-args :r1 `(,ox0 ,oy0) '(:real :real) `(,x0 ,y0))
2928

3029
(vp-lea-p 'fn_consts cnt)
31-
(load-fields cnt `(,(fn-const (n2r 4.0)) ,(fn-const (n2r 2.0))) `(,four ,two))
30+
(load-fields cnt '((fn-const (n2r 4.0)) (fn-const (n2r 2.0))) `(,four ,two))
3231

3332
;init i=0, xc=0.0, yc=0.0, x2=0.0, y2=0.0
3433
(vp-xor-rr cnt cnt)

apps/molecule/app.lisp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181

8282
(defun lighting (col at)
8383
;very basic attenuation and diffuse
84-
(bind '(r g b) (vec-min (vec-add (vec-scale col (* (n2f at) 255.0) +fixeds_tmp3)
84+
(bind '(r g b) (vector-min (vector-add (vector-scale col (* (n2f at) 255.0) +fixeds_tmp3)
8585
(const (Vec3-f 32.0 32.0 32.0)) +fixeds_tmp3)
8686
(const (Vec3-f 255.0 255.0 255.0)) +fixeds_tmp3))
8787
(+ 0xff000000 (<< (n2i r) 16) (<< (n2i g) 8) (n2i b)))
@@ -143,7 +143,7 @@
143143
(defq scale_p (/ (const (n2r 2.0)) radius) scale_r (/ (const (n2r 0.0625)) radius))
144144
(each (lambda (ball)
145145
(bind '(v r _) ball)
146-
(push (vec-scale (vec-sub v center v) scale_p v) +real_1)
146+
(push (vector-scale (vector-sub v center v) scale_p v) +real_1)
147147
(elem-set ball +ball_radius (* scale_r r))) balls)))
148148

149149
(defun reset ()

apps/pcb/layer.inc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@
2525
(defun Record (id layer_line)
2626
(defq p1 (slice layer_line +layer_line_x1 +layer_line_x2)
2727
p2 (slice layer_line +layer_line_x2 +layer_line_radius)
28-
pv (apply fixeds (vec-perp-2d (vec-sub p2 p1)))
29-
l (vec-length pv))
28+
pv (apply fixeds (vector-perp-2d (vector-sub p2 p1)))
29+
l (vector-length pv))
3030
(if (= l 0.0)
3131
(defq norm +fixeds_zero2 dist 0.0)
32-
(defq norm (vec-scale pv (recip l)) dist (vec-dot norm p1)))
32+
(defq norm (vector-scale pv (recip l)) dist (vector-dot norm p1)))
3333
(list id layer_line p1 p2 norm dist))
3434

3535
(defun hit-line? (record layer_line)
@@ -39,12 +39,12 @@
3939
(elem-get (elem-get record +record_layer_line) +layer_line_gap)))
4040
p1 (slice layer_line +layer_line_x1 +layer_line_x2)
4141
p2 (slice layer_line +layer_line_x2 +layer_line_radius)
42-
dp1 (- (vec-dot (elem-get record +record_norm) p1) (elem-get record +record_dist))
43-
dp2 (- (vec-dot (elem-get record +record_norm) p2) (elem-get record +record_dist)))
42+
dp1 (- (vector-dot (elem-get record +record_norm) p1) (elem-get record +record_dist))
43+
dp2 (- (vector-dot (elem-get record +record_norm) p2) (elem-get record +record_dist)))
4444
(cond
4545
((and (> dp1 d) (> dp2 d)) :nil)
4646
((and (< dp1 (neg d)) (< dp2 (neg d))) :nil)
47-
((vec-collide-thick-lines-2d p1 p2 (elem-get record +record_p1) (elem-get record +record_p2) d))))
47+
((vector-collide-thick-lines-2d p1 p2 (elem-get record +record_p1) (elem-get record +record_p2) d))))
4848

4949
(defun hit-line (buckets minx miny maxx maxy width id func line)
5050
(defq miny (* (dec miny) width) maxy (* maxy width))

apps/pcb/router.inc

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
(while (<= y y_range)
2121
(defq x (neg x_range))
2222
(while (<= x x_range)
23-
(defq l (vec-length (Vec2-f (n2f x) (n2f y))))
23+
(defq l (vector-length (Vec2-f (n2f x) (n2f y))))
2424
(and (> l 0.1) (<= l vec_range)
2525
(push out (nums x y 0)))
2626
(++ x))
@@ -33,8 +33,8 @@
3333
maxxyz (Vec2-f -1000000.0 -1000000.0)
3434
quant (n2f quant))
3535
(each (lambda (p)
36-
(vec-min minxyz (setq p (. p :get_pos)) minxyz)
37-
(vec-max maxxyz p maxxyz)) pads)
36+
(vector-min minxyz (setq p (. p :get_pos)) minxyz)
37+
(vector-max maxxyz p maxxyz)) pads)
3838
(bind '(minx miny) minxyz)
3939
(bind '(maxx maxy) maxxyz)
4040
(list (n2f (n2i (/ (* (- maxx minx) (- maxy miny)) quant)))
@@ -90,7 +90,7 @@
9090
(bind '(x y z) (. p :get_pos))
9191
(. p :set_pos (Vec3-f (* x grid_res) (* y grid_res) z))
9292
(each (lambda (p)
93-
(vec-scale p grid_res p)) (. p :get_shape))) pads)
93+
(vector-scale p grid_res p)) (. p :get_shape))) pads)
9494
(each (lambda (wire)
9595
(each (lambda (p)
9696
(bind '(x y z) p)
@@ -164,11 +164,11 @@
164164
(bind '(x0 y0 z0) p0)
165165
(bind '(x1 y1 z1) p1)
166166
(push wire_lines (Layers-line x0 y0 z0 x1 y1 z1 radius gap))
167-
(defq p (Vec2-f x0 y0) v (vec-sub p (Vec2-f x1 y1))
168-
l (vec-length v) norm (vec-scale v (recip l))
167+
(defq p (Vec2-f x0 y0) v (vector-sub p (Vec2-f x1 y1))
168+
l (vector-length v) norm (vector-scale v (recip l))
169169
i 0.0)
170170
(while (< i l)
171-
(bind '(x y) (vec-add p (vec-scale norm i)))
171+
(bind '(x y) (vector-add p (vector-scale norm i)))
172172
(. wire_nodes :insert (. pcb :pad_point_to_node (Vec3-f x y z0)))
173173
(setq i (+ i 0.25)))
174174
(. wire_nodes :insert (. pcb :pad_point_to_node p1))))) (list wire) 1)) wires)
@@ -277,7 +277,7 @@
277277
p0 :nil p1 (. pcb :node_to_pad_point (first pth)))
278278
(each! (lambda (p)
279279
(setq p0 p1 p1 (. pcb :node_to_pad_point p)
280-
d1 (vec-norm (vec-sub p1 p0)))
280+
d1 (vector-norm (vector-sub p1 p0)))
281281
(unless (eql d0 d1)
282282
(push opt_path (elem-get pth (dec (!))))
283283
(setq d0 d1))) (list pth) 1)
@@ -311,7 +311,7 @@
311311
(:t ;sort nodes and take the first
312312
(setq path_node (second (elem-get
313313
(sort
314-
(map (# (list (vec-squared-euclidean-distance path_node %0) %0))
314+
(map (# (list (vector-squared-euclidean-distance path_node %0) %0))
315315
(filter (# (= (. pcb :get_node %0) (. pcb :get_node (first nearer_nodes))))
316316
(sort nearer_nodes (# (- (. pcb :get_node %0) (. pcb :get_node %1))))))
317317
(# (- (first %0) (first %1)))) 0))))))
@@ -376,7 +376,7 @@
376376
(if (>= verbosity 2) (write-line stream " ;shape"))
377377
(write-blk stream " (")
378378
(each (lambda (p)
379-
(write-blk stream (str (vec-scale p scale))))
379+
(write-blk stream (str (vector-scale p scale))))
380380
(. p :get_shape))
381381
(write-line stream ")")
382382
(write-line stream " )"))
@@ -481,7 +481,7 @@
481481
(defq out (clear '())
482482
vecm (nums (dec (get :width this)) (dec (get :height this)) (dec (get :depth this))))
483483
(each (lambda (v)
484-
(and (eql (vec-min vecm (vec-max (defq n (vec-add node v)) +nums_zero3 +nums_tmp3) +nums_tmp3) n)
484+
(and (eql (vector-min vecm (vector-max (defq n (vector-add node v)) +nums_zero3 +nums_tmp3) +nums_tmp3) n)
485485
(= (. this :get_node n) 0)
486486
(push out n))) (elem-get vec (% (elem-get node +vec3_z) 2)))
487487
out)
@@ -492,7 +492,7 @@
492492
(defq out (clear '()) d (. this :get_node node)
493493
vecm (nums (dec (get :width this)) (dec (get :height this)) (dec (get :depth this))))
494494
(each (lambda (v)
495-
(and (eql (vec-min vecm (vec-max (defq n (vec-add node v)) +nums_zero3 +nums_tmp3) +nums_tmp3) n)
495+
(and (eql (vector-min vecm (vector-max (defq n (vector-add node v)) +nums_zero3 +nums_tmp3) +nums_tmp3) n)
496496
(< 0 (. this :get_node n) d)
497497
(push out n))) (elem-get vec (% (elem-get node +vec3_z) 2)))
498498
out)
@@ -552,7 +552,7 @@
552552
; (. pcb :unmark_distances) -> pcb
553553
;set all grid values back to 0
554554
(raise :nodes)
555-
(vec-sub nodes nodes nodes)
555+
(vector-sub nodes nodes nodes)
556556
this)
557557
558558
(defmethod :reset_areas ()

0 commit comments

Comments
 (0)