common/csg.ss
#lang scheme
;; csg.ss
;; Support for CSG primitives
(require "../utils.ss")

(provide (except-out (struct-out csg) make-csg))

;; Structure to indicate we're looking at a CSG operation
(define-struct csg
  ()
  #:transparent)

(define-syntax define-csg
  (syntax-rules ()
    [(_ name slot ...)
     (begin
       (provide (struct-out name))
       (define-struct (name csg)
         (slot ...)
         #:transparent))]))

(define-csg union
  objects)
(provide unite)
(define (unite . objects)
  (assert (not (null? objects)))
  (if (union? (first objects))
      (make-union (append (rest objects) (union-objects (first objects))))
      (make-union objects)))

(define-csg subtraction
  main-object objects)
(provide subtract)
(define (subtract . objects)
  (assert (not (null? objects)))
  (if (subtraction? (first objects))
      (make-subtraction (subtraction-main-object (first objects)) (append (rest objects) (subtraction-objects (first objects))))
      (make-subtraction (first objects) (rest objects))))


(define-csg intersection
  objects)
(provide intersect)
(define (intersect . objects)
  (if (intersection? (first objects))
      (make-intersection (append (rest objects) (intersection-objects (first objects))))
      (make-intersection objects)))