Changeset 27052 in project for release/4/kdtree/trunk/kdtree.scm
 Timestamp:
 07/12/12 05:10:43 (8 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

release/4/kdtree/trunk/kdtree.scm
r27050 r27052 19 19 kdtreefoldright* 20 20 kdtreesubtrees 21 kdtree points22 kdtree indices21 kdtreenodepoints 22 kdtreenodeindices 23 23 kdtreeminindex 24 24 kdtreemaxindex … … 180 180 (pp (lambda (lst) (every point? lst))) 181 181 (vv (lambda (v) (or (list? v) (not v)))) 182 (axis integer?) )182 (axis positiveorzerointeger?) ) 183 183 ) 184 184 … … 188 188 (KdLeaf (ii pp vv axis) (cis:empty? ii)) 189 189 (else #f))) 190 191 192 (define (kdtree>list t)193 (kdtreefoldright cons '() t))194 195 196 (define (kdtree>list* t)197 (kdtreefoldright*198 (lambda (i v x ax) (cons (if v (list i v x) (list i x)) ax))199 '() t))200 190 201 191 … … 226 216 (define (kdtreeforeach* f t) 227 217 (cases kdtree t 228 (KdLeaf (ii pp vv axis) (foreach f (reverse (cis:elements ii)) vv pp)) 218 (KdLeaf (ii pp vv axis) 219 (if vv (foreach f (zip (reverse (cis:elements ii)) vv) pp) 220 (foreach f (reverse (cis:elements ii)) pp))) 229 221 (KdNode (l x i v r axis ci) 230 222 (begin 231 223 (kdtreeforeach* f l) 232 ( f i v x)224 (if v (f (list i v) x) (f i x)) 233 225 (kdtreeforeach* f r) 234 226 )) … … 251 243 (KdLeaf (ii pp vv axis) 252 244 (if vv 253 (foldright f init ( zip (reverse (cis:elements ii)) vv)pp)245 (foldright f init (reverse (cis:elements ii)) vv pp) 254 246 (foldright f init (reverse (cis:elements ii)) pp))) 255 247 (KdNode (l x i v r axis ci) 256 248 (let* ((init2 (kdtreefoldright* f init r)) 257 (init3 ( f i v x init2)))249 (init3 (if v (f (list i v) x init2) (f i x init2)))) 258 250 (kdtreefoldright* f init3 l))) 259 251 )) 260 252 261 253 254 255 256 (define (kdtree>list t) 257 (kdtreefoldright cons '() t)) 258 259 260 (define (kdtree>list* t) 261 (kdtreefoldright* 262 (lambda (iv x ax) (cons (list iv x) ax)) 263 '() t)) 262 264 263 265 … … 275 277 276 278 277 (define (kdtree points t)279 (define (kdtreenodepoints t) 278 280 (cases kdtree t 279 281 (KdLeaf (ii pp vv axis) pp) … … 281 283 )) 282 284 283 (define (kdtree indices t)285 (define (kdtreenodeindices t) 284 286 (cases kdtree t 285 287 (KdLeaf (ii pp vv axis) (cis:elements ii)) … … 287 289 )) 288 290 289 (define (kdtree values t)291 (define (kdtreenodevalues t) 290 292 (cases kdtree t 291 293 (KdLeaf (ii pp vv axis) vv) … … 296 298 (cases kdtree t 297 299 (KdLeaf (ii pp vv axis) (cis:cardinal ii)) 298 (KdNode (l x i r axis ci) (cis:cardinal ci))))300 (KdNode (l x i v r axis ci) (cis:cardinal ci)))) 299 301 300 302 (define (kdtreeminindex t) 301 303 (cases kdtree t 302 304 (KdLeaf (ii pp vv axis) (cis:getmin ii)) 303 (KdNode (l x i r axis ci) (cis:getmin ci))))305 (KdNode (l x i v r axis ci) (cis:getmin ci)))) 304 306 305 307 (define (kdtreemaxindex t) 306 308 (cases kdtree t 307 309 (KdLeaf (ii pp vv axis) (cis:getmax ii)) 308 (KdNode (l x i r axis ci) (cis:getmax ci))))310 (KdNode (l x i v r axis ci) (cis:getmax ci)))) 309 311 310 312 … … 364 366 (i (+ m medianindex offset)) 365 367 (p (makepoint median)) 366 (v ( or (and makevalue (list i (makevalue i median))) i))368 (v (and makevalue (makevalue i median))) 367 369 (axis (modulo depth (dimension p)))) 368 370 … … 643 645 pp (map cadr ips))) 644 646 ) 645 647 (KdLeaf ii1 pp1 vv axis)) 646 648 )) 647 649 )) … … 654 656 (if (equal? p pkill) 655 657 656 (if (integer? i) 657 (let ((pts1 (append (kdtree>list l) (kdtree>list r)))) 658 (list>kdtree 0 (length pts1) pts1 axis)) 659 (let ((pts1 (append (kdtree>list* l) (kdtree>list* r)))) 660 (list>kdtree* 0 (length pts1) pts1 axis))) 658 (let ((offset (if (kdtreeempty? l) (+ i 1) (kdtreeminindex l)))) 659 (if v 660 (let ((pts1 (append (kdtree>list* l) (kdtree>list* r)))) 661 (list>kdtree* 0 (length pts1) pts1 axis offset: offset)) 662 (let ((pts1 (append (kdtree>list l) (kdtree>list r)))) 663 (list>kdtree 0 (length pts1) pts1 axis offset: offset)) 664 )) 661 665 662 666 (if (< (coord axis pkill) … … 828 832 829 833 (make<KdTree> 830 (lambda (points #!key (leaffactor 10) (pointref identity) (makevalue #f)) 831 ((list>kdtree/depth pointref makevalue) 0 (length points) points 0 leaffactor: leaffactor)) 834 (lambda (points #!key 835 (leaffactor 10) 836 (makepoint identity) 837 (makevalue #f) 838 (offset 0) 839 ) 840 ((list>kdtree/depth makepoint makevalue) 841 0 (length points) points 0 842 leaffactor: leaffactor offset: offset)) 832 843 833 844 (makekdtreenearestneighbor pointclass)
Note: See TracChangeset
for help on using the changeset viewer.