; hw7#2 ; CS 381 homework 7 problem 2 ; Jacob Lundberg ;; ;; Problem Two ;; ; This is certainly simpler than Problem One, but it also has a bit less internal type checking... ; Instead that would need to be done externally as in this version of MIDPOINT. ; Thus the safety changes to MIDPOINT below. ; POINT structs hold data on a two dimensional point. (defstruct POINT "Two Dimensional POINT" x y) ; SEGMENT structs define a two dimensional line segment by its two end points, which are POINT structs. (defstruct SEGMENT "Two Dimensional SEGMENT" point1 point2) ; MIDPOINT returns the midpoint of a line segment created using MAKE-SEGMENT. ; This will fail in flames if the segment or points are uninitialised... (defun MIDPOINT (seg1) (cond ; make sure seg1 is a SEGMENT struct ((not (SEGMENT-P seg1)) nil) ; make sure that the first point is a POINT struct ((not (POINT-P (SEGMENT-POINT1 seg1))) nil) ; make sure that the second point is a POINT struct ((not (POINT-P (SEGMENT-POINT2 seg1))) nil) ; finished (and passed) all type checks so return midpoint (T (MAKE-POINT ; find center X value :x (/ (+ (POINT-X (SEGMENT-POINT1 seg1)) (POINT-X (SEGMENT-POINT2 seg1))) 2) ; find center Y value :y (/ (+ (POINT-Y (SEGMENT-POINT1 seg1)) (POINT-Y (SEGMENT-POINT2 seg1))) 2) ) ) ) )