Our "language" has five kinds of values and four other kinds of expressions:
A NoPoints represents the empty set of two-dimensional points.
A Point represents a two-dimensional point with an
y-coordinate. Both coordinates are floating-point numbers.
A Line is a non-vertical infinite line in the plane, represented by a slope and an intercept (as in
y = mx + bwhere
mis the slope and
bis the intercept), both floating-point numbers.
A VerticalLine is an infinite vertical line in the plane, represented by its
A LineSegment is a (finite) line segment, represented by the
y-coordinatesof its endpoints (so four total floating-point numbers).
An Intersect expression is not a value. It has two subexpressions. The semantics is to evaluate the subexpressions (in the same environment) and then return the value that is the intersection (in the geometric sense) of the two subresults. For example, the intersection of two lines could be one of:
NoPoints, if the lines are parallel
Point, if the lines intersect
Line, if the lines have the same slope and intercept (see the note below about what we mean by "the same" for floating-point numbers)
A Let expression is not a value. It is like let-expressions in other languages we have studied: The first subexpression is evaluated and the result bound to a variable that is added to the environment for evaluating the second subexpression.
A Var expression is not a value. It is for using variables in the environment: We look up a string in the environment to get a geometric value.
A Shift expression is not a value. It has a deltaX (a floating-point number), a deltaY (a floating-point number), and a subexpression. The semantics is to evaluate the subexpression and then shift the result by
deltaX(in the x-direction; positive is "to the right") and
deltaY(in the y-direction; positive is "up"). More specifically, shifting for each form of value is as follows:
mand an intercept of
VerticalLineshifted by deltaX; the deltaY is irrelevant.
LineSegmenthas its endpoints shift by deltaX and deltaY.