Trapezoid.Trepresents a set of points lying in a quadrilateral whose north and south edges are horizontal and whose west and east edges have arbitrary non-horizontal slopes. For example, a diagonal line can be represented as a tall skinny trapezoid.
INTERFACEFor a trapezoid
Trapezoid; IMPORT Point; TYPE T = RECORD vlo, vhi: INTEGER; m1, m2: Rational; p1, p2: Point.T; END; Rational = RECORD n, d: INTEGER END;
tr.vhi are the
v coordinates of its north and south edges, respectively;
tr.m2 are the slopes of its west and east edges, respectively, as
(delta v) / (delta h). A denominator
of zero represents an infinite slope; i.e., a vertical
edge. A numerator of zero is illegal.
tr.p2 are points on the infinite lines
that extend the west and east edges, respectively.
\medskip Trapezoids are closed on the north and west edges, open on the south and east edges, closed on the northwest corner, and open on the other corners.
q represents the rational number
PROCEDURE FromEdges (y1, p1, q1: INTEGER; y2, p2, q2: INTEGER): T;
Return a trapezoid whose vertices are
(p2, y2), and
(q2, y2). The altitude of the trapezoid must be non-zero.
PROCEDURE FromVertices (READONLY p1, p2, q1, q2: Point.T): T;
Return a trapezoid from four vertices. The
p2vertices must have the same y-coordinates, as must the
q2vertices. Furthermore, the altitude of the trapezoid must be non-zero.
PROCEDURE FromTriangle (READONLY a, b, c: Point.T): T;
Return a trapezoid from the vertices of a triangle. One of the sides of the triangle must be parallel to the x-axis, and the triangle's altitude must be non-zero.