1 ;;; Copyright 2009-2011 Christoph Senjak
3 (in-package :uxul-world)
5 (declaim (inline make-xy coordinate-distance))
7 (defstruct xy-struct (x 0 :type fixnum) (y 0 :type fixnum))
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)))
16 (defclass xy-coordinates ()
17 ((x :accessor x :initarg :x :initform 0 :type fixnum)
18 (y :accessor y :initarg :y :initform 0 :type fixnum)))
20 (defun coordinate-distance (a b)
21 "Calculate the euklidian distance of two points. They must have x-
23 (sqrt (+ (expt (- (x a) (x b)) 2) (expt (- (y a) (y b)) 2))))
26 (declare (type fixnum x y))
27 "Guess what this function does..."
28 (make-xy-struct :x x :y y))