Works again.
[uxul-world.git] / xy-coordinates.lisp
1 ;;; Copyright 2009-2011 Christoph Senjak
2
3 (in-package :uxul-world)
4
5 (declaim (inline make-xy coordinate-distance))
6
7 (defstruct xy-struct (x 0 :type fixnum) (y 0 :type fixnum))
8
9 (defmethod x ((obj xy-struct)) (slot-value obj 'x))
10 (defmethod (setf x) (new-value (obj xy-struct))
11   (setf (slot-value obj 'x) (the number new-value)))
12 (defmethod y ((obj xy-struct)) (slot-value obj 'y))
13 (defmethod (setf y) (new-value (obj xy-struct))
14   (setf (slot-value obj 'y) (the number new-value)))
15
16 (defclass xy-coordinates ()
17   ((x :accessor x :initarg :x :initform 0 :type fixnum)
18    (y :accessor y :initarg :y :initform 0 :type fixnum)))
19
20 (defun coordinate-distance (a b)
21   "Calculate the euklidian distance of two points. They must have x-
22 and y-accessors."
23   (sqrt (+ (expt (- (x a) (x b)) 2) (expt (- (y a) (y b)) 2))))
24
25 (defun make-xy (x y)
26   (declare (type fixnum x y))
27   "Guess what this function does..."
28   (make-xy-struct :x x :y y))