mailman3.common-lisp.net
Sign In
Sign Up
Sign In
Sign Up
Manage this list
×
Keyboard Shortcuts
Thread View
j
: Next unread message
k
: Previous unread message
j a
: Jump to all threads
j l
: Jump to MailingList overview
2024
November
October
September
August
July
June
May
April
March
February
January
2023
December
November
October
September
August
July
June
May
April
March
February
January
2022
December
November
October
September
August
July
June
May
April
March
February
January
2021
December
November
October
September
August
July
June
May
April
March
February
January
2020
December
November
October
September
August
July
June
May
April
March
February
January
2019
December
November
October
September
August
July
June
May
April
March
February
January
2018
December
November
October
September
August
July
June
May
April
March
February
January
2017
December
November
October
September
August
July
June
May
April
March
February
January
2016
December
November
October
September
August
July
June
May
April
March
February
January
2015
December
November
October
September
August
July
June
May
April
March
February
January
2014
December
November
October
September
August
July
June
May
April
March
February
January
2013
December
November
October
September
August
July
June
May
April
March
February
January
2012
December
November
October
September
August
July
June
May
April
March
February
January
2011
December
November
October
September
August
July
June
May
April
March
February
January
2010
December
November
October
September
August
July
June
May
April
March
February
January
2009
December
November
October
September
August
July
June
May
April
March
February
January
2008
December
November
October
September
August
July
June
May
April
March
February
January
2007
December
November
October
September
August
July
June
May
April
March
February
January
2006
December
November
October
September
August
July
June
May
April
March
February
January
List overview
Download
bknr-cvs
December 2008
----- 2024 -----
November 2024
October 2024
September 2024
August 2024
July 2024
June 2024
May 2024
April 2024
March 2024
February 2024
January 2024
----- 2023 -----
December 2023
November 2023
October 2023
September 2023
August 2023
July 2023
June 2023
May 2023
April 2023
March 2023
February 2023
January 2023
----- 2022 -----
December 2022
November 2022
October 2022
September 2022
August 2022
July 2022
June 2022
May 2022
April 2022
March 2022
February 2022
January 2022
----- 2021 -----
December 2021
November 2021
October 2021
September 2021
August 2021
July 2021
June 2021
May 2021
April 2021
March 2021
February 2021
January 2021
----- 2020 -----
December 2020
November 2020
October 2020
September 2020
August 2020
July 2020
June 2020
May 2020
April 2020
March 2020
February 2020
January 2020
----- 2019 -----
December 2019
November 2019
October 2019
September 2019
August 2019
July 2019
June 2019
May 2019
April 2019
March 2019
February 2019
January 2019
----- 2018 -----
December 2018
November 2018
October 2018
September 2018
August 2018
July 2018
June 2018
May 2018
April 2018
March 2018
February 2018
January 2018
----- 2017 -----
December 2017
November 2017
October 2017
September 2017
August 2017
July 2017
June 2017
May 2017
April 2017
March 2017
February 2017
January 2017
----- 2016 -----
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
----- 2015 -----
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
----- 2014 -----
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
----- 2013 -----
December 2013
November 2013
October 2013
September 2013
August 2013
July 2013
June 2013
May 2013
April 2013
March 2013
February 2013
January 2013
----- 2012 -----
December 2012
November 2012
October 2012
September 2012
August 2012
July 2012
June 2012
May 2012
April 2012
March 2012
February 2012
January 2012
----- 2011 -----
December 2011
November 2011
October 2011
September 2011
August 2011
July 2011
June 2011
May 2011
April 2011
March 2011
February 2011
January 2011
----- 2010 -----
December 2010
November 2010
October 2010
September 2010
August 2010
July 2010
June 2010
May 2010
April 2010
March 2010
February 2010
January 2010
----- 2009 -----
December 2009
November 2009
October 2009
September 2009
August 2009
July 2009
June 2009
May 2009
April 2009
March 2009
February 2009
January 2009
----- 2008 -----
December 2008
November 2008
October 2008
September 2008
August 2008
July 2008
June 2008
May 2008
April 2008
March 2008
February 2008
January 2008
----- 2007 -----
December 2007
November 2007
October 2007
September 2007
August 2007
July 2007
June 2007
May 2007
April 2007
March 2007
February 2007
January 2007
----- 2006 -----
December 2006
November 2006
October 2006
September 2006
August 2006
July 2006
June 2006
May 2006
April 2006
March 2006
February 2006
January 2006
bknr-cvs@common-lisp.net
1 participants
48 discussions
Start a n
N
ew thread
[bknr-cvs] hans changed trunk/projects/quickhoney/src/pixel-pdf.lisp
by BKNR Commits
18 Dec '08
18 Dec '08
Revision: 4140 Author: hans URL:
http://bknr.net/trac/changeset/4140
progress! U trunk/projects/quickhoney/src/pixel-pdf.lisp Modified: trunk/projects/quickhoney/src/pixel-pdf.lisp =================================================================== --- trunk/projects/quickhoney/src/pixel-pdf.lisp 2008-12-18 00:09:18 UTC (rev 4139) +++ trunk/projects/quickhoney/src/pixel-pdf.lisp 2008-12-18 06:39:24 UTC (rev 4140) @@ -107,16 +107,16 @@ (:right :east)))))) (defun forward () - (turtle:forward) - - (look :forward (lambda (x y) - (setf (x *converter*) x - (y *converter*) y - (aref (seen *converter*) x y) t)))) + (turtle:forward)) (defun set-color (color) (format t "can't set PDF color ~A yet~%" color)) +(defun move-to-pixel (x y) + (setf (x *converter*) x + (y *converter*) y + (aref (seen *converter*) x y) t)) + (defun fill-from (from-x from-y) ;; XXX true-color-behandlung fehlt. (format t "filling at ~A/~A~%" from-x from-y) @@ -126,6 +126,7 @@ (y *converter*) from-y (color *converter*) (aref (pixels *converter*) from-x from-y)) (set-color (color *converter*)) + (turtle:reset) (turtle:move-to from-x from-y) (turtle:pen-down) (turtle:forward) @@ -135,19 +136,26 @@ (eql from-y (turtle:y)))) (cond ((can-turn-right) - (format t " RIGHT~%") + #+(or) (format t " RIGHT~%") + (look :right #'move-to-pixel) (turn :right) - (forward)) + (turtle:forward)) ((can-go-forward) - (format t " FORWARD~%") - (forward)) + #+(or) (format t " FORWARD~%") + (look :forward #'move-to-pixel) + (turtle:forward)) (t - (format t " LEFT~%") + #+(or) (format t " LEFT~%") (turn :left) (turtle:forward))) - (princ turtle::*turtle*) - (terpri)) - (turtle:pen-up)) + #+(or) (format t "at ~A/~A looking ~A ~A~%" + (x *converter*) (y *converter*) + (looking-in-direction *converter*) + turtle::*turtle*) + (assert (and (<= (abs (- (x *converter*) (turtle:x))) 1) + (<= (abs (- (y *converter*) (turtle:y))) 1)))) + (turtle:pen-up) + (print-seen)) (defun pixels-pdf (image-pathname) (let ((*converter* (make-instance 'converter :image-pathname image-pathname))) @@ -162,4 +170,12 @@ (dotimes (x (width *converter*)) (unless (aref (seen *converter*) x y) (fill-from x y)))))) - (pdf:write-document (make-pathname :type "pdf" :defaults image-pathname))))) \ No newline at end of file + (pdf:write-document (make-pathname :type "pdf" :defaults image-pathname))))) + +(defun print-seen () + (dotimes (y (height *converter*)) + (dotimes (x (width *converter*)) + (write-char (if (aref (seen *converter*) x (- (height *converter*) y 1)) + #\* #\.) + *error-output*)) + (terpri *error-output*))) \ No newline at end of file
1
0
0
0
[bknr-cvs] hans changed trunk/projects/quickhoney/src/pixel-pdf.lisp
by BKNR Commits
18 Dec '08
18 Dec '08
Revision: 4139 Author: hans URL:
http://bknr.net/trac/changeset/4139
checkpoint again. will i ever make this work? U trunk/projects/quickhoney/src/pixel-pdf.lisp Modified: trunk/projects/quickhoney/src/pixel-pdf.lisp =================================================================== --- trunk/projects/quickhoney/src/pixel-pdf.lisp 2008-12-17 23:46:09 UTC (rev 4138) +++ trunk/projects/quickhoney/src/pixel-pdf.lisp 2008-12-18 00:09:18 UTC (rev 4139) @@ -39,8 +39,7 @@ (< -1 y (height *converter*)))) (defun same-color (x y) - (when (and (in-range x y) - (not (aref (seen *converter*) x y))) + (when (in-range x y) (eql (color *converter*) (aref (pixels *converter*) x y)))) (defun look (direction fn) @@ -109,36 +108,45 @@ (defun forward () (turtle:forward) - (setf (aref (seen *converter*) (x *converter*) (y *converter*)) t) + (look :forward (lambda (x y) (setf (x *converter*) x - (y *converter*) y)))) + (y *converter*) y + (aref (seen *converter*) x y) t)))) (defun set-color (color) - (setf (color *converter*) color) (format t "can't set PDF color ~A yet~%" color)) (defun fill-from (from-x from-y) ;; XXX true-color-behandlung fehlt. (format t "filling at ~A/~A~%" from-x from-y) - (setf (aref (seen *converter*) from-x from-y) t) - (set-color (aref (pixels *converter*) from-x from-y)) + (setf (aref (seen *converter*) from-x from-y) t + (looking-in-direction *converter*) :east + (x *converter*) from-x + (y *converter*) from-y + (color *converter*) (aref (pixels *converter*) from-x from-y)) + (set-color (color *converter*)) (turtle:move-to from-x from-y) (turtle:pen-down) + (turtle:forward) (do ((moved nil t)) ((and moved (eql from-x (turtle:x)) (eql from-y (turtle:y)))) (cond ((can-turn-right) + (format t " RIGHT~%") (turn :right) (forward)) ((can-go-forward) + (format t " FORWARD~%") (forward)) (t + (format t " LEFT~%") (turn :left) (turtle:forward))) - (princ turtle::*turtle*)) + (princ turtle::*turtle*) + (terpri)) (turtle:pen-up)) (defun pixels-pdf (image-pathname)
1
0
0
0
[bknr-cvs] hans changed trunk/projects/quickhoney/src/
by BKNR Commits
18 Dec '08
18 Dec '08
Revision: 4138 Author: hans URL:
http://bknr.net/trac/changeset/4138
checkpoint U trunk/projects/quickhoney/src/pixel-pdf.lisp U trunk/projects/quickhoney/src/quickhoney.asd Modified: trunk/projects/quickhoney/src/pixel-pdf.lisp =================================================================== --- trunk/projects/quickhoney/src/pixel-pdf.lisp 2008-12-17 20:36:21 UTC (rev 4137) +++ trunk/projects/quickhoney/src/pixel-pdf.lisp 2008-12-17 23:46:09 UTC (rev 4138) @@ -3,88 +3,155 @@ (defvar *colors* nil) (defconstant +paper-width+ 800) +(defclass converter () + ((x :initform 0 + :accessor x) + (y :initform 0 + :accessor y) + (pixels :reader pixels) + (seen :reader seen) + (color :accessor color) + (looking-in-direction :initform :east + :accessor looking-in-direction))) + +(defun width (converter) + (array-dimension (pixels converter) 0)) + +(defun height (converter) + (array-dimension (pixels converter) 1)) + +(defmethod initialize-instance :after ((converter converter) &key image-pathname) + (cl-gd:with-image-from-file* (image-pathname) + (let ((width (cl-gd:image-width)) + (height (cl-gd:image-height))) + (with-slots (seen pixels) converter + (setf seen (make-array (list width height) + :element-type 'boolean :initial-element nil) + pixels (make-array (list width height))) + (cl-gd:do-rows (y) + (cl-gd:do-pixels-in-row (x) + (setf (aref pixels x y) (cl-gd:raw-pixel)))))))) + +(defvar *converter*) + +(defun in-range (x y) + (and (< -1 x (width *converter*)) + (< -1 y (height *converter*)))) + (defun same-color (x y) - (format t "same-color ~A/~A~%" x y) - (unless (or (>= x width) - (>= y height) - (< x 0) - (< y 0)) - (eql color (aref pixels x y)))) + (when (and (in-range x y) + (not (aref (seen *converter*) x y))) + (eql (color *converter*) (aref (pixels *converter*) x y)))) -(defun can-turn-left (x y) - (same-color (+ x (car dirs)) - (+ y (cadr dirs)))) +(defun look (direction fn) + (let ((x (x *converter*)) + (y (y *converter*))) + (ecase (looking-in-direction *converter*) + (:east + (ecase direction + (:left + (funcall fn (1+ x) (1+ y))) + (:forward + (funcall fn (1+ x) y)) + (:right + (funcall fn (1+ x) (1- y))))) + (:south + (ecase direction + (:left + (funcall fn (1+ x) (1- y))) + (:forward + (funcall fn x (1- y))) + (:right + (funcall fn (1- x) (1- y))))) + (:west + (ecase direction + (:left + (funcall fn (1- x) (1- y))) + (:forward + (funcall fn (1- x) y)) + (:right + (funcall fn (1- x) (1+ y))))) + (:north + (ecase direction + (:left + (funcall fn (1- x) (1+ y))) + (:forward + (funcall fn x (1+ y))) + (:right + (funcall fn (1+ x) (1+ y)))))))) -(defun next-step (x y) - (dotimes (i 3) - (let ((x (+ x (car dirs))) - (y (+ y (cadr dirs)))) - (format t "checking ~A/~A~%" x y) - (cond - ((and (= x from-x) - (= y from-y)) - (turtle:pen-up) - (return-from fill-from (values x y))) - ((same-color x y) - (setf (aref seen x y) t) - (pdf:line-to x y) - (format t "same here ~A/~A~%" x y) - (return-from next-step (values x y))) - (t - (setf dirs (cddr dirs))))))) +(defun can-turn-right () + (look :right #'same-color)) +(defun can-go-forward () + (look :forward #'same-color)) + (defun turn (direction) (turtle:turn direction) - (setf dirs - (ecase direction - (:left (cdddr dirs)) - (:right (cdr dirs))))) + (setf (looking-in-direction *converter*) + (ecase (looking-in-direction *converter*) + (:east + (ecase direction + (:left :north) + (:right :south))) + (:south + (ecase direction + (:left :east) + (:right :west))) + (:west + (ecase direction + (:left :south) + (:right :north))) + (:north + (ecase direction + (:left :west) + (:right :east)))))) (defun forward () - (mark-right-ahead) - (turtle:forward)) + (turtle:forward) + (setf (aref (seen *converter*) (x *converter*) (y *converter*)) t) + (look :forward (lambda (x y) + (setf (x *converter*) x + (y *converter*) y)))) -(defun fill-from (from-x from-y color) +(defun set-color (color) + (setf (color *converter*) color) + (format t "can't set PDF color ~A yet~%" color)) + +(defun fill-from (from-x from-y) ;; XXX true-color-behandlung fehlt. - (pdf:set-rgb-fill (float (/ (cl-gd::gd-image-get-red img color) 256)) - (float (/ (cl-gd::gd-image-get-green img color) 256)) - (float (/ (cl-gd::gd-image-get-blue img color) 256))) + (format t "filling at ~A/~A~%" from-x from-y) + (setf (aref (seen *converter*) from-x from-y) t) + (set-color (aref (pixels *converter*) from-x from-y)) (turtle:move-to from-x from-y) (turtle:pen-down) - (turtle:forward) - (do ((x 0) - (y 0)) - ((and (eql from-x (turtle:x)) - (eql from-y (turlle:y)))) + (do ((moved nil t)) + ((and moved + (eql from-x (turtle:x)) + (eql from-y (turtle:y)))) (cond - ((can-turn-left) - (turn :left)) - ((can-go-straight)) - ((can-go-right) - (turn :right))) - (forward)) + ((can-turn-right) + (turn :right) + (forward)) + ((can-go-forward) + (forward)) + (t + (turn :left) + (turtle:forward))) + (princ turtle::*turtle*)) (turtle:pen-up)) -(defun pixels-pdf (pixel-pathname) - (cl-gd:with-image-from-file* (pixel-pathname) +(defun pixels-pdf (image-pathname) + (let ((*converter* (make-instance 'converter :image-pathname image-pathname))) + (turtle:reset) (pdf:with-document () (pdf:with-page () - (let* ((width (cl-gd:image-width)) - (height (cl-gd:image-height)) - (scale (float (/ +paper-width+ (max width height)))) - (seen (make-array (list width height) - :element-type 'boolean :initial-element nil)) - (pixels (make-array (list width height))) - (img (cl-gd::img cl-gd::*default-image*))) - (labels - (cl-gd:do-rows (y) - (cl-gd:do-pixels-in-row (x) - (setf (aref pixels x y) (cl-gd:raw-pixel)))) + (let ((scale (float (/ +paper-width+ (max (width *converter*) + (height *converter*)))))) (pdf:translate 30.0 80.0) (pdf:scale scale scale) - (dotimes (y height) - (dotimes (x width) - (unless (aref seen x y) - (fill-from x y (aref pixels x y)) - (format t "filled at ~A/~A~%" x y))))))) - (pdf:write-document (make-pathname :type "pdf" :defaults pixel-pathname))))) \ No newline at end of file + (dotimes (y (height *converter*)) + (dotimes (x (width *converter*)) + (unless (aref (seen *converter*) x y) + (fill-from x y)))))) + (pdf:write-document (make-pathname :type "pdf" :defaults image-pathname))))) \ No newline at end of file Modified: trunk/projects/quickhoney/src/quickhoney.asd =================================================================== --- trunk/projects/quickhoney/src/quickhoney.asd 2008-12-17 20:36:21 UTC (rev 4137) +++ trunk/projects/quickhoney/src/quickhoney.asd 2008-12-17 23:46:09 UTC (rev 4138) @@ -41,7 +41,8 @@ (:file "webserver" :depends-on ("handlers")) (:file "daily" :depends-on ("config")) - (:file "pixel-pdf" :depends-on ("packages")) + (:file "turtle" :depends-on ("packages")) + (:file "pixel-pdf" :depends-on ("turtle")) (:file "money" :depends-on ("packages")) (:file "shop" :depends-on ("money"))
1
0
0
0
[bknr-cvs] hans changed trunk/projects/quickhoney/src/
by BKNR Commits
17 Dec '08
17 Dec '08
Revision: 4137 Author: hans URL:
http://bknr.net/trac/changeset/4137
checkpoint vectorizer work U trunk/projects/quickhoney/src/packages.lisp U trunk/projects/quickhoney/src/pixel-pdf.lisp U trunk/projects/quickhoney/src/quickhoney.asd A trunk/projects/quickhoney/src/turtle.lisp Modified: trunk/projects/quickhoney/src/packages.lisp =================================================================== --- trunk/projects/quickhoney/src/packages.lisp 2008-12-15 17:10:09 UTC (rev 4136) +++ trunk/projects/quickhoney/src/packages.lisp 2008-12-17 20:36:21 UTC (rev 4137) @@ -89,3 +89,17 @@ (:use :cl :bknr.datastore) (:export #:update-status)) +(defpackage :pixel-pdf + (:use :cl) + (:export #:convert)) + +(defpackage :turtle + (:use :cl) + (:export #:pen-down + #:pen-up + #:move-to + #:turn + #:forward + #:reset + #:x + #:y)) \ No newline at end of file Modified: trunk/projects/quickhoney/src/pixel-pdf.lisp =================================================================== --- trunk/projects/quickhoney/src/pixel-pdf.lisp 2008-12-15 17:10:09 UTC (rev 4136) +++ trunk/projects/quickhoney/src/pixel-pdf.lisp 2008-12-17 20:36:21 UTC (rev 4137) @@ -1,8 +1,70 @@ -(in-package :quickhoney) +(in-package :pixel-pdf) (defvar *colors* nil) (defconstant +paper-width+ 800) +(defun same-color (x y) + (format t "same-color ~A/~A~%" x y) + (unless (or (>= x width) + (>= y height) + (< x 0) + (< y 0)) + (eql color (aref pixels x y)))) + +(defun can-turn-left (x y) + (same-color (+ x (car dirs)) + (+ y (cadr dirs)))) + +(defun next-step (x y) + (dotimes (i 3) + (let ((x (+ x (car dirs))) + (y (+ y (cadr dirs)))) + (format t "checking ~A/~A~%" x y) + (cond + ((and (= x from-x) + (= y from-y)) + (turtle:pen-up) + (return-from fill-from (values x y))) + ((same-color x y) + (setf (aref seen x y) t) + (pdf:line-to x y) + (format t "same here ~A/~A~%" x y) + (return-from next-step (values x y))) + (t + (setf dirs (cddr dirs))))))) + +(defun turn (direction) + (turtle:turn direction) + (setf dirs + (ecase direction + (:left (cdddr dirs)) + (:right (cdr dirs))))) + +(defun forward () + (mark-right-ahead) + (turtle:forward)) + +(defun fill-from (from-x from-y color) + ;; XXX true-color-behandlung fehlt. + (pdf:set-rgb-fill (float (/ (cl-gd::gd-image-get-red img color) 256)) + (float (/ (cl-gd::gd-image-get-green img color) 256)) + (float (/ (cl-gd::gd-image-get-blue img color) 256))) + (turtle:move-to from-x from-y) + (turtle:pen-down) + (turtle:forward) + (do ((x 0) + (y 0)) + ((and (eql from-x (turtle:x)) + (eql from-y (turlle:y)))) + (cond + ((can-turn-left) + (turn :left)) + ((can-go-straight)) + ((can-go-right) + (turn :right))) + (forward)) + (turtle:pen-up)) + (defun pixels-pdf (pixel-pathname) (cl-gd:with-image-from-file* (pixel-pathname) (pdf:with-document () @@ -13,44 +75,8 @@ (seen (make-array (list width height) :element-type 'boolean :initial-element nil)) (pixels (make-array (list width height))) - (img (cl-gd::img cl-gd::*default-image*)) - (dirs #1=(0 -1 1 0 0 1 -1 0 . #1#))) + (img (cl-gd::img cl-gd::*default-image*))) (labels - ((fill-from (from-x from-y color) - (labels ((same-color (x y) - (format t "same-color ~A/~A~%" x y) - (unless (or (>= x width) - (>= y height) - (< x 0) - (< y 0)) - (eql color (aref pixels x y)))) - (next-step (x y) - (dotimes (i 4) - (let ((x (+ x (car dirs))) - (y (+ y (cadr dirs)))) - (format t "checking ~A/~A~%" x y) - (cond - ((and (= x from-x) - (= y from-y)) - (pdf:line-to x y) - (pdf:close-and-fill) - (return-from fill-from (values x y))) - ((same-color x y) - (setf (aref seen x y) t) - (pdf:line-to x y) - (format t "same here ~A/~A~%" x y) - (return-from next-step (values x y))) - (t - (setf dirs (cddr dirs)))))) - (error 'did-not-terminate))) - ;; XXX true-color-behandlung fehlt. - (pdf:set-rgb-fill (float (/ (cl-gd::gd-image-get-red img color) 256)) - (float (/ (cl-gd::gd-image-get-green img color) 256)) - (float (/ (cl-gd::gd-image-get-blue img color) 256))) - (format t "fill from ~A/~A~%" from-x from-y) - (pdf:move-to from-x from-y) - (loop (multiple-value-setq (from-x from-y) - (next-step from-x from-y)))))) (cl-gd:do-rows (y) (cl-gd:do-pixels-in-row (x) (setf (aref pixels x y) (cl-gd:raw-pixel)))) Modified: trunk/projects/quickhoney/src/quickhoney.asd =================================================================== --- trunk/projects/quickhoney/src/quickhoney.asd 2008-12-15 17:10:09 UTC (rev 4136) +++ trunk/projects/quickhoney/src/quickhoney.asd 2008-12-17 20:36:21 UTC (rev 4137) @@ -26,7 +26,8 @@ :bknr.modules :cl-gd :unit-test - :yason) + :yason + :cl-pdf) :components ((:file "packages") (:file "config" :depends-on ("packages")) @@ -40,6 +41,8 @@ (:file "webserver" :depends-on ("handlers")) (:file "daily" :depends-on ("config")) + (:file "pixel-pdf" :depends-on ("packages")) + (:file "money" :depends-on ("packages")) (:file "shop" :depends-on ("money")) (:file "quickhoney-shop" :depends-on ("shop")) Added: trunk/projects/quickhoney/src/turtle.lisp =================================================================== --- trunk/projects/quickhoney/src/turtle.lisp (rev 0) +++ trunk/projects/quickhoney/src/turtle.lisp 2008-12-17 20:36:21 UTC (rev 4137) @@ -0,0 +1,79 @@ +(in-package :turtle) + +(defclass turtle () + ((x :initform 0 + :accessor turtle-x) + (y :initform 0 + :accessor turtle-y) + (directions :initform '#1=(:east :south :west :north . #1#) + :accessor turtle-directions) + (drawing :accessor turtle-drawing + :initform nil) + (turned :accessor turtle-turned + :initform nil))) + +(defmethod print-object ((turtle turtle) stream) + (print-unreadable-object (turtle stream :type t) + (format stream "at ~A/~A looking ~A pen ~:[UP~;DOWN~]~:[~;TURNED~]" + (turtle-x turtle) + (turtle-y turtle) + (turtle-direction turtle) + (turtle-drawing turtle) + (turtle-turned turtle)))) + +(defvar *turtle* (make-instance 'turtle)) + +(defun turtle-direction (turtle) + (car (turtle-directions turtle))) + +(defun x () + (turtle-x *turtle*)) + +(defun y () + (turtle-y *turtle*)) + +(defun pen-up () + (pdf:line-to (turtle-x *turtle*) (turtle-y *turtle*)) + (pdf:close-and-fill) + (setf (turtle-drawing *turtle*) nil + (turtle-turned *turtle*) nil) + *turtle*) + +(defun pen-down () + (setf (turtle-drawing *turtle*) t) + *turtle*) + +(defun move-to (x y) + (when (turtle-drawing *turtle*) + (error "turtle can't move while drawing")) + (setf (turtle-x *turtle*) x + (turtle-y *turtle*) y) + *turtle*) + +(defun forward () + (when (turtle-turned *turtle*) + (pdf:line-to (turtle-x *turtle*) (turtle-y *turtle*)) + (setf (turtle-turned *turtle*) nil)) + (ecase (turtle-direction *turtle*) + (:east + (incf (turtle-x *turtle*))) + (:south + (decf (turtle-y *turtle*))) + (:west + (decf (turtle-x *turtle*))) + (:north + (incf (turtle-y *turtle*)))) + *turtle*) + +(defun turn (direction) + (ecase direction + (:left + (setf (turtle-directions *turtle*) (cdddr (turtle-directions *turtle*)))) + (:right + (setf (turtle-directions *turtle*) (cdr (turtle-directions *turtle*))))) + (setf (turtle-turned *turtle*) t) + *turtle*) + +(defun reset () + (setf *turtle* (make-instance 'turtle)) + *turtle*)
1
0
0
0
[bknr-cvs] hans changed trunk/projects/quickhoney/src/pixel-pdf.lisp
by BKNR Commits
15 Dec '08
15 Dec '08
Revision: 4136 Author: hans URL:
http://bknr.net/trac/changeset/4136
Checkpoint U trunk/projects/quickhoney/src/pixel-pdf.lisp Modified: trunk/projects/quickhoney/src/pixel-pdf.lisp =================================================================== --- trunk/projects/quickhoney/src/pixel-pdf.lisp 2008-12-14 23:17:22 UTC (rev 4135) +++ trunk/projects/quickhoney/src/pixel-pdf.lisp 2008-12-15 17:10:09 UTC (rev 4136) @@ -7,21 +7,58 @@ (cl-gd:with-image-from-file* (pixel-pathname) (pdf:with-document () (pdf:with-page () - (pdf:translate 30.0 80.0) - (let ((scale (float (/ +paper-width+ (max (cl-gd:image-width) (cl-gd:image-height)))))) - (pdf:scale scale scale)) - (cl-gd:do-rows (y) - (cl-gd:do-pixels-in-row (x) - ;; XXX true-color-behandlung fehlt. - (let ((color (cl-gd:raw-pixel)) - (img (cl-gd::img cl-gd::*default-image*))) - (pdf:set-rgb-fill (float (/ (cl-gd::gd-image-get-red img color) 256)) - (float (/ (cl-gd::gd-image-get-green img color) 256)) - (float (/ (cl-gd::gd-image-get-blue img color) 256)))) - (let ((y (- (cl-gd:image-height) y))) - (pdf:move-to x y) - (pdf:line-to x (1+ y)) - (pdf:line-to (1+ x) (1+ y)) - (pdf:line-to (1+ x) y)) - (pdf:close-and-fill)))) + (let* ((width (cl-gd:image-width)) + (height (cl-gd:image-height)) + (scale (float (/ +paper-width+ (max width height)))) + (seen (make-array (list width height) + :element-type 'boolean :initial-element nil)) + (pixels (make-array (list width height))) + (img (cl-gd::img cl-gd::*default-image*)) + (dirs #1=(0 -1 1 0 0 1 -1 0 . #1#))) + (labels + ((fill-from (from-x from-y color) + (labels ((same-color (x y) + (format t "same-color ~A/~A~%" x y) + (unless (or (>= x width) + (>= y height) + (< x 0) + (< y 0)) + (eql color (aref pixels x y)))) + (next-step (x y) + (dotimes (i 4) + (let ((x (+ x (car dirs))) + (y (+ y (cadr dirs)))) + (format t "checking ~A/~A~%" x y) + (cond + ((and (= x from-x) + (= y from-y)) + (pdf:line-to x y) + (pdf:close-and-fill) + (return-from fill-from (values x y))) + ((same-color x y) + (setf (aref seen x y) t) + (pdf:line-to x y) + (format t "same here ~A/~A~%" x y) + (return-from next-step (values x y))) + (t + (setf dirs (cddr dirs)))))) + (error 'did-not-terminate))) + ;; XXX true-color-behandlung fehlt. + (pdf:set-rgb-fill (float (/ (cl-gd::gd-image-get-red img color) 256)) + (float (/ (cl-gd::gd-image-get-green img color) 256)) + (float (/ (cl-gd::gd-image-get-blue img color) 256))) + (format t "fill from ~A/~A~%" from-x from-y) + (pdf:move-to from-x from-y) + (loop (multiple-value-setq (from-x from-y) + (next-step from-x from-y)))))) + (cl-gd:do-rows (y) + (cl-gd:do-pixels-in-row (x) + (setf (aref pixels x y) (cl-gd:raw-pixel)))) + (pdf:translate 30.0 80.0) + (pdf:scale scale scale) + (dotimes (y height) + (dotimes (x width) + (unless (aref seen x y) + (fill-from x y (aref pixels x y)) + (format t "filled at ~A/~A~%" x y))))))) (pdf:write-document (make-pathname :type "pdf" :defaults pixel-pathname))))) \ No newline at end of file
1
0
0
0
[bknr-cvs] hans changed trunk/projects/bos/
by BKNR Commits
15 Dec '08
15 Dec '08
Revision: 4135 Author: hans URL:
http://bknr.net/trac/changeset/4135
Better sponsor placemark loading, add "Sponsors" pseudo POI. U trunk/projects/bos/payment-website/static/poi-ms/poi-ms.html U trunk/projects/bos/payment-website/static/poi-ms/poi-ms.js U trunk/projects/bos/web/sponsor-handlers.lisp Modified: trunk/projects/bos/payment-website/static/poi-ms/poi-ms.html =================================================================== --- trunk/projects/bos/payment-website/static/poi-ms/poi-ms.html 2008-12-14 13:58:07 UTC (rev 4134) +++ trunk/projects/bos/payment-website/static/poi-ms/poi-ms.html 2008-12-14 23:17:22 UTC (rev 4135) @@ -24,7 +24,7 @@ </div> <div id="content"> <h1 id="title"></h1> - <div id="map"><img src="fake-map.jpg" width="505" height="505"/></div> + <div id="map" class="large"><img src="fake-map.jpg" width="505" height="505"/></div> <div id="content-body"> </div> </div> Modified: trunk/projects/bos/payment-website/static/poi-ms/poi-ms.js =================================================================== --- trunk/projects/bos/payment-website/static/poi-ms/poi-ms.js 2008-12-14 13:58:07 UTC (rev 4134) +++ trunk/projects/bos/payment-website/static/poi-ms/poi-ms.js 2008-12-14 23:17:22 UTC (rev 4135) @@ -178,6 +178,7 @@ } function showOverview() { + log('showOverview'); $('#back').css('visibility', 'hidden'); $('#title').text(NLS('Übersicht')); @@ -189,6 +190,13 @@ .empty() .append(UL({ id: 'poi-list' })); + $('#poi-list') + .append($(LI(null, + A({ href: '#' }, + IMG({ src: "
http://www.google.com/mapfiles/marker.png
" }), + B(NLS("Sponsoren"))))) + .bind('click', showSponsors)); + for (var i in pois) { var poi = pois[i]; $('#poi-list') @@ -269,8 +277,8 @@ } } -// this.map.enableContinuousZoom(); -// this.map.enableScrollWheelZoom(); + this.map.enableContinuousZoom(); + this.map.enableScrollWheelZoom(); this.mapClicked = function (overlay, latlng, overlaylatlng) { log('map clicked, overlay: ' + overlay + ' latlng: ' + latlng + ' overlaylatlng: ' + overlaylatlng); @@ -284,7 +292,7 @@ var bounds = this.map.getBounds(); var sw = latLngToPoint(bounds.getSouthWest()); var ne = latLngToPoint(bounds.getNorthEast()); - log('map has moved: ' + sw.x + ',' + ne.y + ',' + ne.x + ',' + sw.y); +// log('map has moved: ' + sw.x + ',' + ne.y + ',' + ne.x + ',' + sw.y); this.sponsorQuery = sw.x + ',' + ne.y + ',' + ne.x + ',' + sw.y; } @@ -292,10 +300,28 @@ GEvent.addListener(this.map, "click", bind(this.mapClicked, this)); GEvent.addListener(this.map, "moveend", bind(this.moveEnd, this)); + this.sponsorMarkers = []; + + this.removeSponsorMarkers = function (all) { + log('remove sponsor markers'); + var markers = []; + var gmap = this.map; + map(function(marker) { + if (!all && marker.opened) { + markers.push(marker); + } else { + gmap.removeOverlay(marker); + } + }, this.sponsorMarkers); + this.sponsorMarkers = markers; + log('done'); + } + this.overview = function () { this.show(); $('#map').removeClass('small'); $('#map').addClass('large'); + this.removeSponsorMarkers(true); this.addControls(); this.map.checkResize(); this.map.setCenter(projection.fromPixelToLatLng(new GPoint(6500, 6350), 6), 2, customMap); @@ -304,6 +330,7 @@ this.poiDetail = function (x, y) { $('#map').removeClass('large'); $('#map').addClass('small'); + this.removeSponsorMarkers(true); this.removeControls(); this.map.checkResize(); this.map.setCenter(projection.fromPixelToLatLng(new GPoint(x, y), 6), 6); @@ -349,8 +376,6 @@ this.map.addOverlay(marker); } - this.sponsorMarkers = []; - function makeTable(rows) { return TABLE({ 'class': 'sponsor-info-popup' }, TBODY(null, @@ -364,7 +389,6 @@ this.setSponsorMarker = function (sponsor) { var position = pointToLatLng(sponsor.contracts[0].centerX, sponsor.contracts[0].centerY); var sponsorMarker = new GMarker(position); - log('sponsor: ' + serializeJSON(sponsor)); var info = [ [ "Name", sponsor.name || NLS("[anonym]") ], [ "Country", sponsor.country ], @@ -374,20 +398,28 @@ info.push([ "Info", sponsor.infoText ]); } sponsorMarker.bindInfoWindow(makeTable(info)); + + function setMarkerOpened(marker, state) { + marker.opened = state; + } + + GEvent.addListener(this.map, "infowindowopen", partial(setMarkerOpened, sponsorMarker, true)); + GEvent.addListener(this.map, "infowindowclose", partial(setMarkerOpened, sponsorMarker, false)); + this.map.addOverlay(sponsorMarker); this.sponsorMarkers.push(sponsorMarker); } - this.removeSponsorMarkers = function () { - map(bind(this.map.removeOverlay, this.map), this.sponsorMarkers); - this.sponsorMarkers = []; - } - this.putSponsorPlacemarks = function(data) { - log('got ' + data.sponsors.length + ' sponsors to display'); - this.removeSponsorMarkers(); - map(bind(this.setSponsorMarker, this), data.sponsors); - this.checkMapMoved(); + try { + log('got ' + data.sponsors.length + ' sponsors to display'); + this.removeSponsorMarkers(); + map(bind(this.setSponsorMarker, this), data.sponsors); + this.checkMapMoved(); + } + catch (e) { + log('error ' + e + ' putting sponsor placemarks'); + } } this.checkMapMoved = function() { @@ -399,8 +431,6 @@ callLater(0.5, bind(this.checkMapMoved, this)); } } - - this.checkMapMoved(); } var pages = { @@ -427,17 +457,17 @@ mainMap.zoomTo(contract.left, contract.top, 8); mainMap.setSponsorMarker(sponsor); - - // Math.max(contract.width, contract.height) } function showSponsors() { $('#left-bar') .empty() - .append(H3(NLS("Letzte Sponsoren")), - UL({ id: 'sponsor-list' })); +// .append(H3(NLS("Letzte Sponsoren")), +// UL({ id: 'sponsor-list' })) + ; + $('#title').text(NLS('Sponsoren')); map(function (sponsor) { $('#sponsor-list') .append($(LI(null, @@ -451,15 +481,19 @@ }, sponsors.slice(0, 10)); mainMap.overview(); + mainMap.zoomTo(7100, 5400, 5); + mainMap.checkMapMoved(); } -function loadSponsors(data) { +function loadPOIs(data) { try { - for (var i in data.sponsors) { - var sponsor = data.sponsors[i]; - sponsors.push(sponsor); + for (var i in data.pois) { + var poi = data.pois[i]; + pois[poi.id] = poi; } + mainMap = new Map(); + var poi_id = document.location.hash.replace(/#/, ""); if (poi_id) { showPOI(pois[poi_id]); @@ -472,22 +506,6 @@ } } -function loadPOIs(data) { - try { - for (var i in data.pois) { - var poi = data.pois[i]; - pois[poi.id] = poi; - } - - mainMap = new Map(); - - loadJSONDoc('/sponsors-json').addCallback(loadSponsors); - } - catch (e) { - alert(e); - } -} - function init() { $('#small-map a').bind('click', showOverview); Modified: trunk/projects/bos/web/sponsor-handlers.lisp =================================================================== --- trunk/projects/bos/web/sponsor-handlers.lisp 2008-12-14 13:58:07 UTC (rev 4134) +++ trunk/projects/bos/web/sponsor-handlers.lisp 2008-12-14 23:17:22 UTC (rev 4135) @@ -361,8 +361,8 @@ (defun sponsors-at (query) (when (cl-ppcre:scan "^[0-9,]+$" query) (destructuring-bind (east north west south) (mapcar #'parse-integer (cl-ppcre:split "," query)) - (when (and (< (- west east) 1000) - (< (- south north) 1000)) + (when (and (< (- west east) 1500) + (< (- south north) 1500)) (labels ((x-y-to-lon-lat (x y) (geo-utm:utm-x-y-to-lon-lat (+ +nw-utm-x+ x) (- +nw-utm-y+ y) +utm-zone+ t)))
1
0
0
0
[bknr-cvs] hans changed trunk/projects/bos/payment-website/static/poi-ms/poi-ms.
by BKNR Commits
14 Dec '08
14 Dec '08
Revision: 4134 Author: hans URL:
http://bknr.net/trac/changeset/4134
Popups for sponsor markers. U trunk/projects/bos/payment-website/static/poi-ms/poi-ms.css U trunk/projects/bos/payment-website/static/poi-ms/poi-ms.js Modified: trunk/projects/bos/payment-website/static/poi-ms/poi-ms.css =================================================================== --- trunk/projects/bos/payment-website/static/poi-ms/poi-ms.css 2008-12-14 09:09:05 UTC (rev 4133) +++ trunk/projects/bos/payment-website/static/poi-ms/poi-ms.css 2008-12-14 13:58:07 UTC (rev 4134) @@ -146,3 +146,6 @@ width: 505px; height: 200px; } + +table.sponsor-info-popup th { text-align: left } +table.sponsor-info-popup td { max-width: 15em } \ No newline at end of file Modified: trunk/projects/bos/payment-website/static/poi-ms/poi-ms.js =================================================================== --- trunk/projects/bos/payment-website/static/poi-ms/poi-ms.js 2008-12-14 09:09:05 UTC (rev 4133) +++ trunk/projects/bos/payment-website/static/poi-ms/poi-ms.js 2008-12-14 13:58:07 UTC (rev 4134) @@ -351,36 +351,43 @@ this.sponsorMarkers = []; + function makeTable(rows) { + return TABLE({ 'class': 'sponsor-info-popup' }, + TBODY(null, + map(function (row) { + return TR(null, + TH(null, NLS(row[0])), + TD(null, row[1])); + }, rows))); + } + this.setSponsorMarker = function (sponsor) { var position = pointToLatLng(sponsor.contracts[0].centerX, sponsor.contracts[0].centerY); var sponsorMarker = new GMarker(position); + log('sponsor: ' + serializeJSON(sponsor)); + var info = [ + [ "Name", sponsor.name || NLS("[anonym]") ], + [ "Country", sponsor.country ], + [ "Anzahl m²", sponsor.contracts[0].count ] + ]; + if (sponsor.infoText && !sponsor.infoText.match(/^ *$/)) { + info.push([ "Info", sponsor.infoText ]); + } + sponsorMarker.bindInfoWindow(makeTable(info)); this.map.addOverlay(sponsorMarker); this.sponsorMarkers.push(sponsorMarker); } this.removeSponsorMarkers = function () { - try { - map(bind(this.map.removeOverlay, this.map), this.sponsorMarkers); - this.sponsorMarkers = []; - } - catch (e) { - log('error removing sponsor markers: ' + e); - } + map(bind(this.map.removeOverlay, this.map), this.sponsorMarkers); + this.sponsorMarkers = []; } - this.startMapMovedChecker = function () { - } - this.putSponsorPlacemarks = function(data) { log('got ' + data.sponsors.length + ' sponsors to display'); this.removeSponsorMarkers(); - try { - map(bind(this.setSponsorMarker, this), data.sponsors); - this.checkMapMoved(); - } - catch (e) { - log('error removing sponsor markers: ' + e); - } + map(bind(this.setSponsorMarker, this), data.sponsors); + this.checkMapMoved(); } this.checkMapMoved = function() {
1
0
0
0
[bknr-cvs] hans changed trunk/projects/bos/
by BKNR Commits
14 Dec '08
14 Dec '08
Revision: 4133 Author: hans URL:
http://bknr.net/trac/changeset/4133
Display sponsors in map. U trunk/projects/bos/payment-website/static/poi-ms/poi-ms.js U trunk/projects/bos/web/contract-tree.lisp U trunk/projects/bos/web/sponsor-handlers.lisp Modified: trunk/projects/bos/payment-website/static/poi-ms/poi-ms.js =================================================================== --- trunk/projects/bos/payment-website/static/poi-ms/poi-ms.js 2008-12-13 21:04:38 UTC (rev 4132) +++ trunk/projects/bos/payment-website/static/poi-ms/poi-ms.js 2008-12-14 09:09:05 UTC (rev 4133) @@ -276,8 +276,17 @@ log('map clicked, overlay: ' + overlay + ' latlng: ' + latlng + ' overlaylatlng: ' + overlaylatlng); } + function latLngToPoint(latLng) { + return projection.fromLatLngToPixel(latLng, 6); + } + this.moveEnd = function () { - log('map has moved'); + var bounds = this.map.getBounds(); + var sw = latLngToPoint(bounds.getSouthWest()); + var ne = latLngToPoint(bounds.getNorthEast()); + log('map has moved: ' + sw.x + ',' + ne.y + ',' + ne.x + ',' + sw.y); + + this.sponsorQuery = sw.x + ',' + ne.y + ',' + ne.x + ',' + sw.y; } GEvent.addListener(this.map, "click", bind(this.mapClicked, this)); @@ -340,15 +349,51 @@ this.map.addOverlay(marker); } + this.sponsorMarkers = []; + this.setSponsorMarker = function (sponsor) { var position = pointToLatLng(sponsor.contracts[0].centerX, sponsor.contracts[0].centerY); - if (this.sponsorMarker) { - this.sponsorMarker.setLatLng(position); + var sponsorMarker = new GMarker(position); + this.map.addOverlay(sponsorMarker); + this.sponsorMarkers.push(sponsorMarker); + } + + this.removeSponsorMarkers = function () { + try { + map(bind(this.map.removeOverlay, this.map), this.sponsorMarkers); + this.sponsorMarkers = []; + } + catch (e) { + log('error removing sponsor markers: ' + e); + } + } + + this.startMapMovedChecker = function () { + } + + this.putSponsorPlacemarks = function(data) { + log('got ' + data.sponsors.length + ' sponsors to display'); + this.removeSponsorMarkers(); + try { + map(bind(this.setSponsorMarker, this), data.sponsors); + this.checkMapMoved(); + } + catch (e) { + log('error removing sponsor markers: ' + e); + } + } + + this.checkMapMoved = function() { + if (this.sponsorQuery) { + loadJSONDoc('/sponsors-json?at=' + this.sponsorQuery) + .addCallback(bind(this.putSponsorPlacemarks, this)); + this.sponsorQuery = null; } else { - this.sponsorMarker = new GMarker(position); - this.map.addOverlay(this.sponsorMarker); + callLater(0.5, bind(this.checkMapMoved, this)); } } + + this.checkMapMoved(); } var pages = { Modified: trunk/projects/bos/web/contract-tree.lisp =================================================================== --- trunk/projects/bos/web/contract-tree.lisp 2008-12-13 21:04:38 UTC (rev 4132) +++ trunk/projects/bos/web/contract-tree.lisp 2008-12-14 09:09:05 UTC (rev 4133) @@ -443,18 +443,23 @@ #'contract-tree-changed)) (defun contract-size (contract) - (length (contract-m2s contract))) + (apply #'max (cddr (contract-bounding-box contract)))) +(defun geo-box-size (geo-box) + (apply #'max (multiple-value-list (width-height (geo-box-rectangle geo-box))))) + (defun contracts-in-geo-box (geo-box &key limit) "Return all contracts that intersect the given GEO-BOX. If LIMIT is specified, the LIMIT largest contracts are returned." (let ((return-count 0) - (contracts (list nil))) + (contracts (list nil)) + (min-size (floor (/ (geo-box-size geo-box) 10)))) (ensure-intersecting-children *contract-tree* geo-box (lambda (node) (dolist (contract (placemark-contracts node)) - (when (geo-box-encloses-p geo-box (contract-geo-box contract)) + (when (and (geo-box-encloses-p geo-box (contract-geo-box contract)) + (>= (geo-box-size (contract-geo-box contract)) min-size)) (when (and limit (>= return-count limit)) (if (<= (contract-size contract) @@ -468,11 +473,11 @@ (contract-size (cadr point)))) (setf (cdr point) (cons contract (cdr point)))))))) (lambda (node) - (or (and limit + (or (and nil limit (>= return-count limit)) (leaf-node-p node)))) (cdr contracts))) -y(register-transient-init-function 'make-contract-tree-from-m2 +(register-transient-init-function 'make-contract-tree-from-m2 'make-quad-tree 'geometry:make-rect-publisher) Modified: trunk/projects/bos/web/sponsor-handlers.lisp =================================================================== --- trunk/projects/bos/web/sponsor-handlers.lisp 2008-12-13 21:04:38 UTC (rev 4132) +++ trunk/projects/bos/web/sponsor-handlers.lisp 2008-12-14 09:09:05 UTC (rev 4133) @@ -361,14 +361,16 @@ (defun sponsors-at (query) (when (cl-ppcre:scan "^[0-9,]+$" query) (destructuring-bind (east north west south) (mapcar #'parse-integer (cl-ppcre:split "," query)) - (labels - ((x-y-to-lon-lat (x y) - (geo-utm:utm-x-y-to-lon-lat (+ +nw-utm-x+ x) (- +nw-utm-y+ y) +utm-zone+ t))) - (mapcar #'contract-sponsor - (contracts-in-geo-box (coerce (append (x-y-to-lon-lat east north) - (x-y-to-lon-lat west south)) - '(vector double-float)) - :limit 10)))))) + (when (and (< (- west east) 1000) + (< (- south north) 1000)) + (labels + ((x-y-to-lon-lat (x y) + (geo-utm:utm-x-y-to-lon-lat (+ +nw-utm-x+ x) (- +nw-utm-y+ y) +utm-zone+ t))) + (mapcar #'contract-sponsor + (contracts-in-geo-box (coerce (append (x-y-to-lon-lat east north) + (x-y-to-lon-lat west south)) + '(vector double-float)) + :limit 20))))))) (defun largest-sponsors () (mapcar #'contract-sponsor
1
0
0
0
[bknr-cvs] hans changed trunk/projects/bos/web/
by BKNR Commits
13 Dec '08
13 Dec '08
Revision: 4132 Author: hans URL:
http://bknr.net/trac/changeset/4132
Query sponsors by geo rectangle. U trunk/projects/bos/web/contract-tree.lisp U trunk/projects/bos/web/sponsor-handlers.lisp Modified: trunk/projects/bos/web/contract-tree.lisp =================================================================== --- trunk/projects/bos/web/contract-tree.lisp 2008-12-10 14:15:39 UTC (rev 4131) +++ trunk/projects/bos/web/contract-tree.lisp 2008-12-13 21:04:38 UTC (rev 4132) @@ -126,10 +126,10 @@ (insert-contract contract-tree contract) (remove-contract contract-tree contract))))) -(defmacro handle-if-node-modified (&body body) +(defmacro handle-if-node-modified ((node) &body body) `(let* ((path (parse-path path)) - (node (find-node-with-path *contract-tree* path))) - (hunchentoot:handle-if-modified-since (timestamp node)) + (,node (find-node-with-path *contract-tree* path))) + (hunchentoot:handle-if-modified-since (timestamp ,node)) ,@body)) ;;; contract-placemark-handler @@ -218,7 +218,7 @@ :root-element "kml") (with-query-params ((lang "en") (path) (rmcpath) (rmcid)) - (handle-if-node-modified + (handle-if-node-modified (node) (setf (hunchentoot:header-out :last-modified) (hunchentoot:rfc-1123-date (timestamp node))) (let* ((lod (node-lod node)) @@ -442,6 +442,37 @@ (list 0 0 +width+ +width+) #'contract-tree-changed)) -(register-transient-init-function 'make-contract-tree-from-m2 +(defun contract-size (contract) + (length (contract-m2s contract))) + +(defun contracts-in-geo-box (geo-box &key limit) + "Return all contracts that intersect the given GEO-BOX. If LIMIT is +specified, the LIMIT largest contracts are returned." + (let ((return-count 0) + (contracts (list nil))) + (ensure-intersecting-children *contract-tree* + geo-box + (lambda (node) + (dolist (contract (placemark-contracts node)) + (when (geo-box-encloses-p geo-box (contract-geo-box contract)) + (when (and limit + (>= return-count limit)) + (if (<= (contract-size contract) + (contract-size (cadr contracts))) + (return) + (setf contracts (cons nil (cddr contracts))))) + (incf return-count) + (do ((point contracts (cdr point))) + ((or (null (cddr point)) + (< (contract-size contract) + (contract-size (cadr point)))) + (setf (cdr point) (cons contract (cdr point)))))))) + (lambda (node) + (or (and limit + (>= return-count limit)) + (leaf-node-p node)))) + (cdr contracts))) + +y(register-transient-init-function 'make-contract-tree-from-m2 'make-quad-tree 'geometry:make-rect-publisher) Modified: trunk/projects/bos/web/sponsor-handlers.lisp =================================================================== --- trunk/projects/bos/web/sponsor-handlers.lisp 2008-12-10 14:15:39 UTC (rev 4131) +++ trunk/projects/bos/web/sponsor-handlers.lisp 2008-12-13 21:04:38 UTC (rev 4132) @@ -358,6 +358,18 @@ (class-instances 'sponsor) :key (compose #'string-downcase #'user-full-name)))) +(defun sponsors-at (query) + (when (cl-ppcre:scan "^[0-9,]+$" query) + (destructuring-bind (east north west south) (mapcar #'parse-integer (cl-ppcre:split "," query)) + (labels + ((x-y-to-lon-lat (x y) + (geo-utm:utm-x-y-to-lon-lat (+ +nw-utm-x+ x) (- +nw-utm-y+ y) +utm-zone+ t))) + (mapcar #'contract-sponsor + (contracts-in-geo-box (coerce (append (x-y-to-lon-lat east north) + (x-y-to-lon-lat west south)) + '(vector double-float)) + :limit 10)))))) + (defun largest-sponsors () (mapcar #'contract-sponsor (subseq (sort (copy-list (class-instances 'contract)) @@ -373,6 +385,8 @@ (cond ((query-param "q") (sponsors-matching (query-param "q"))) + ((query-param "at") + (sponsors-at (query-param "at"))) ((query-param "largest") (largest-sponsors)) (t
1
0
0
0
[bknr-cvs] hans changed deployed/bos/projects/bos/m2/m2-pdf.lisp
by BKNR Commits
10 Dec '08
10 Dec '08
Revision: 4131 Author: hans URL:
http://bknr.net/trac/changeset/4131
merge from trunk: new cert positioning U deployed/bos/projects/bos/m2/m2-pdf.lisp Modified: deployed/bos/projects/bos/m2/m2-pdf.lisp =================================================================== --- deployed/bos/projects/bos/m2/m2-pdf.lisp 2008-12-10 12:27:59 UTC (rev 4130) +++ deployed/bos/projects/bos/m2/m2-pdf.lisp 2008-12-10 14:15:39 UTC (rev 4131) @@ -21,14 +21,14 @@ (last-m2 (first (last m2s))) (scale (/ 80 (max bb-width bb-height)))) - (draw-coordinate 110 160 (m2-lon-lat first-m2)) + (draw-coordinate 140 240 (m2-lon-lat first-m2)) (unless (eq first-m2 last-m2) - (draw-coordinate 190 40 (m2-lon-lat last-m2))) + (draw-coordinate 220 120 (m2-lon-lat last-m2))) - (pdf:translate (+ 65.0 (if (>= bb-width bb-height) 0 + (pdf:translate (+ 95.0 (if (>= bb-width bb-height) 0 (* 0.5 (abs (- bb-width bb-height)) scale))) - (+ 65.0 (if (>= bb-height bb-width) 0 + (+ 145.0 (if (>= bb-height bb-width) 0 (* 0.5 (abs (- bb-width bb-height)) scale)))) (pdf:scale scale scale)
1
0
0
0
← Newer
1
2
3
4
5
Older →
Jump to page:
1
2
3
4
5
Results per page:
10
25
50
100
200