stoe/maths/types.lisp

87 lines
2.3 KiB
Common Lisp

#|
This file is a part of stoe project.
Copyright (c) 2015 Renaud Casenave-Péré (renaud@casenave-pere.fr)
|#
(uiop:define-package :stoe/maths/types
(:use :cl :stoe/core/utils)
(:export #:vect #:raw-data
#:int2 #:int3 #:int4
#:float2 #:float3 #:float4
#:quaternion
#:matrix #:dims
#:int22 #:int33 #:int44
#:float22 #:float33 #:float44
#:dimensions #:element-type))
(in-package :stoe/maths/types)
(defgeneric dimensions (x))
(defmethod dimensions ((x number)) 1)
(defgeneric element-type (x))
(defmethod element-type ((x float)) 'single-float)
(defmethod element-type ((x integer)) 'fixnum)
(defclass vect ()
((array :type (array * (*))
:initarg :array
:reader raw-data
:documentation "The internal representation of the vector")))
(defmethod print-object ((v vect) stream)
(with-slots (array) v
(print-unreadable-object (v stream :type t)
(format stream "~a" array))))
(defclass int2 (vect)
((array :type (array fixnum (2)))))
(defclass int3 (vect)
((array :type (array fixnum (3)))))
(defclass int4 (vect)
((array :type (array fixnum (4)))))
(defclass float2 (vect)
((array :type (array single-float (2)))))
(defclass float3 (vect)
((array :type (array single-float (3)))))
(defclass float4 (vect)
((array :type (array single-float (4)))))
(defclass quaternion (float4)
())
(defclass matrix ()
((dims :initarg :dims :reader dimensions
:documentation "The dimensions of the matrix")
(array :type (array * (*))
:initarg :array
:reader raw-data
:documentation "The internal representation of the matrix")))
(defmethod print-object ((m matrix) stream)
(with-slots (dims array) m
(print-unreadable-object (m stream :type t)
(format stream "~a ~a" dims array))))
(defclass int22 (matrix)
((array :type (array fixnum (4)))))
(defclass int33 (matrix)
((array :type (array fixnum (9)))))
(defclass int44 (matrix)
((array :type (array fixnum (16)))))
(defclass float22 (matrix)
((array :type (array single-float (4)))))
(defclass float33 (matrix)
((array :type (array single-float (9)))))
(defclass float44 (matrix)
((array :type (array single-float (16)))))