;;; A Point represents a location in $\Bbb R^2$. (define (make-Point x y) (f64vector x y)) (define (Point-x p) (f64vector-ref p 0)) (define (Point-y p) (f64vector-ref p 1)) (define (Point-x-set! p val) (f64vector-set! p 0 val)) (define (Point-y-set! p val) (f64vector-set! p 1 val)) (define (Point? p) (declare (fixnum)) (and (f64vector? p) (= (f64vector-length p) 2))) (define (Point-add p1 p2) (declare (flonum)) (make-Point (+ (Point-x p1) (Point-x p2)) (+ (Point-y p1) (Point-y p2)))) (define (Point-subtract p1 p2) (declare (flonum)) (make-Point (- (Point-x p1) (Point-x p2)) (- (Point-y p1) (Point-y p2)))) (define (Point-scale x p) (declare (flonum)) (make-Point (* x (Point-x p)) (* x (Point-y p)))) (define (Point-dot-product p1 p2) (declare (flonum)) (+ (* (Point-x p1) (Point-x p2)) (* (Point-y p1) (Point-y p2)))) (define (Point-L2-norm p) (declare (flonum)) (let ((x (Point-x p)) (y (Point-y p))) (sqrt (+ (* x x) (* y y))))) (define (Point-zero) (make-Point 0.0 0.0))