Changeset 3195

Show
Ignore:
Timestamp:
05/27/08 11:34:25 (8 months ago)
Author:
ksprotte
Message:

new quad-tree function: collect-nodes

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/projects/bos/web/quad-tree.lisp

    r3180 r3195  
    256256      (ensure-node-with-path (ensure-child node (first path)) (rest path)))) 
    257257 
    258 (defun ensure-intersecting-children (node geo-box &optional function) 
     258(defun ensure-intersecting-children (node geo-box &optional function (leaf-test #'leaf-node-p)) 
     259  "Maps FUNCTION over NODE and all children of NODE that intersect 
     260with GEO-BOX.  Children that dont exist yet are created on the fly. If 
     261LEAF-TEST returns true, the children of the current node are not 
     262further recursed into." 
    259263  (when function 
    260264    (funcall function node)) 
    261   (unless (leaf-node-p node) 
     265  (unless (funcall leaf-test node) 
    262266    (dolist (index (intersecting-children-indices node geo-box)) 
    263267      (ensure-intersecting-children (ensure-child node index) geo-box function)))) 
     
    279283    nil)) 
    280284 
     285(defun collect-nodes (test node &key (prune-test (constantly nil))) 
     286  (let (nodes) 
     287    (map-nodes (lambda (node) 
     288                 (when (funcall test node) 
     289                   (push node nodes))) 
     290               node 
     291               :prune-test prune-test) 
     292    (nreverse nodes))) 
     293 
    281294;;; *quad-tree* 
    282295(defvar *quad-tree*) 
     
    287300(register-store-transient-init-function 'make-quad-tree) 
    288301 
    289 (defmethod node-path (node) 
     302(defun node-path (node) 
    290303  (let (prev-n path) 
    291304    (map-nodes (lambda (n) 
     
    296309                 (setq prev-n n)) 
    297310               *quad-tree* 
    298                :prune-test (lambda (n) (not (geo-box-intersect-p (geo-box n) (geo-box node))))))) 
    299  
    300  
    301  
     311               :prune-test (lambda (n) (not (geo-box-intersect-p (geo-box n) 
     312                                                                 (geo-box node))))))) 
     313