From 9959f0ba72e3e87fc257272668329c7235530950 Mon Sep 17 00:00:00 2001 From: Colin Okay Date: Tue, 16 Apr 2019 18:40:01 -0500 Subject: improved intersection check --- imbricate.ros | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/imbricate.ros b/imbricate.ros index ab32984..c5eba0c 100755 --- a/imbricate.ros +++ b/imbricate.ros @@ -134,9 +134,15 @@ exec ros -Q -- $0 "$@" (inside-rect r2 (tr r1)) (inside-rect r2 (br r1)) (inside-rect r2 (bl r1)) - )) ;; TODO add the case checks for edge intersections - - + ;; if no corner of one is inside the other, then + ;; any edge of one intersects at least one edge of the other + ;; so we check one arbitrarily + (destructuring-bind (left1 right1 top1 bottom1) (xy-bounds r1) + (destructuring-bind (left2 right2 top2 bottom2) (xy-bounds r2) + (and (<= left1 left2) + (< left2 right1) + (<= top2 top1) + (< top1 bottom2)))))) (defun make-corner-keeper () (list 0 0 '() (make-hash-table :test 'equal) '())) @@ -212,7 +218,6 @@ exec ros -Q -- $0 "$@" (let ((tw (getf stats :width)) (th (getf stats :height))) (destructuring-bind (x y) (find-space-for ck tw th) - (format t "found space: ~a,~a~%" x y) (add-rect ck (rect x y tw th)) (push (nconc (list :x x :y y) stats) packlist)))) packlist)) -- cgit v1.2.3