(in-package :clf)

;; размер ячейки

(defclass cell-size ()
  ((size-vector :initarg :size-vector
		:accessor size-vector)
   (dimensions :initarg :dimensions
	       :accessor dimensions)
   (headers/cell-size :initform '(x-size y-size z-size)
		      :allocation :class)))

(make-header-for-class/dimensions cell-size)

(defmethod initialize-instance :after ((obj cell-size) &key dimensions size-vector)
  (let ((dimensions (or dimensions
			(dimensions obj)
			;; надо учитывать, что dimensions может быть почерпнут из вышестоящего класса
			(error "необходимо задать количество измерений флагом :dimensions"))))
			
    (setf (size-vector obj) (make-array dimensions :initial-element 'undef))
    (when size-vector
      (when (>= dimensions 1) (setf (x-size obj) (aref size-vector 0)))
      (when (>= dimensions 2) (setf (y-size obj) (aref size-vector 1)))
      (when (>= dimensions 3) (setf (z-size obj) (aref size-vector 2))))))

;; акцессоры размеров

(defmethod x-size ((size cell-size))
  (elt (size-vector size) 0))

(defmethod y-size ((size cell-size))
  (elt (size-vector size) 1))

(defmethod z-size ((size cell-size))
  (elt (size-vector size) 2))

;; мутаторы размеров

(defmethod (setf x-size) (new (size cell-size))
  (setf (elt (size-vector size) 0) new))

(defmethod (setf y-size) (new (size cell-size))
  (setf (elt (size-vector size) 1) new))

(defmethod (setf z-size) (new (size cell-size))
  (setf (elt (size-vector size) 2) new))