; "points.oo"  -- without setters (note points1.oo)  -- KenD

(require 'yasos)


;;----------------
;; point interface
;;----------------

(define-predicate POINT?)  ;; answers #f (false) by default
(define-operation (X obj))
(define-operation (Y obj))
(define-operation (SET-X! obj new-x))
(define-operation (SET-Y! obj new-y))


;;---------------------
;; point implementation
;;---------------------

(define (MAKE-POINT the-x the-y)
  (object
     ((POINT? self) #t) ;; yes, this is a point object
     ((X self) the-x)
     ((Y self) the-y)
     ((SET-X! self val)
      (set! the-x val)
      the-x)
     ((SET-Y! self val)
      (set! the-y val)
      the-y)
     ((SIZE self) 2)
     ((PRINT self port)
      (format port "#<point: ~a ~a>" (x self) (y self)))
) )

;;-----------------------------
;; 3D point interface additions
;;-----------------------------

(define-operation (Z obj))
(define-operation (SET-Z! obj new-z))


;;------------------------
;; 3D point implementation
;;------------------------

(define (MAKE-POINT-3D the-x the-y the-z)
   (object-with-ancestors ( (a-point (make-point the-x the-y)) )
      ((Z self) the-z)
      ((SET-Z! self val) (set! the-z val) the-z)
      ;; override inherited SIZE and PRINT operations
      ((SIZE self) 3)
      ((PRINT self port)
       (format port "#<3D-point: ~a ~a ~a>" (x self) (y self) (z self)))
)  )
