\manpage {rat\_segment} {} {Rational Segments} 
 
\definition
An instance $s$ of the data type $rat\_segment$ is a directed straight line
segment with rational coordinates in the two-dimensional plane, i.e.,
a line segment $[p,q]$ connecting two rational points $p$ and $q$ (cf. 
\ref{Rational Points}). $p$ is called the start point and $q$ is called the 
end point of $s$. The segment $[(0,0),(0,0)]$ is said to be empty. 
 
\creation s 
 
\create { }
   { introduces a variable \var\ of type \name. \var\ is initialized
            to the empty segment.  }
 
 
\create {(rat\_point\ p,\ rat\_point\ q)}
   { introduces a variable \var\ of type \name. \var\ is initialized
            to the segment $(p,q)$.  }
 
 
\create {(integer\ x1,\ integer\ y1,\ integer\ x2,\ integer\ y2)}
   { introduces a variable \var\ of type \name. \var\ is initialized
            to the segment $[(x1,y1),(x2,y2)]$.  }
 
 
\operations 2 3.5 
 
\op  rat\_point start {()}
           {  returns the start point of segment \var. }
 
 
\op  rat\_point end {()}
           {  returns the end point of segment \var. }
 
 
\op  double xcoord1 {()}
           {  returns a double precision approximation of the $x$-coordinate
              of the start point of segment \var. }
 
 
\op  double xcoord2 {()}
           {  returns a double precision approximation of the $x$-coordinate
              of the end point of segment \var. }
 
 
\op  double ycoord1 {()}
           {  returns a double precision approximation of the $y$-coordinate
              of the start point of segment \var. }
 
 
\op  double ycoord2 {()}
           {  returns a double precision approximation of the $y$-coordinate
              of the end point of segment \var. }
 
 
\op  integer X1 {()}
           {  returns the first homogeneous coordinate of the start point
              of segment \var. }
 
 
\op  integer X2 {()}
           {  returns the first homogeneous coordinate of the end point
              of segment \var. }
 
 
\op  integer Y1 {()}
           {  returns the second homogeneous coordinate of the start point
              of segment \var. }
 
 
\op  integer Y2 {()}
           {  returns the second homogeneous coordinate of the end point
              of segment \var. }
 
 
\op  integer W1 {()}
           {  returns the third homogeneous coordinate of the start point
              of segment \var. }
 
 
\op  integer W2 {()}
           {  returns the third homogeneous coordinate of the end point
              of segment \var. }
 
 
\op  integer dx {()}
           {  returns the normalized $x$-difference $X1\cdot W2 - X2\cdot W1$
              of the segment.  }
 
 
\op  integer dy {()}
           {  returns the normalized $y$-difference $Y1\cdot W2 - Y2\cdot W1$
              of the segment.  }
 
 
\op  bool vertical {()}
           {  returns true if \var\ is vertical and false otherwise.  }
 
 
\op  bool horizontal {()}
           {  returns true if \var\ is horizontal and false otherwise.  }
 
 
\opl int cmp\_slope {( rat\_segment\ s1)}
           {  compares the slopes of \var\ and $s1$.  }
 
 
\opl bool intersection {( rat\_segment\ t, \ rat\_point\&\ p)}
           {  if \var\ and $t$ are not collinear and intersect the
            point of intersection is assigned to $p$ and the result is
            true, otherwise the result is false.  }
 
 
\opl bool intersection\_of\_lines {( rat\_segment\ t, \ rat\_point\&\ p)}
           {  if the lines supporting \var\ and $t$ are not parallel
            their point of intersection is assigned to $p$ and the result is
            true, otherwise the result is false.  }
 
 
\binop int == {s}
         {  Test for equality. }
 
 
\binop int != {s}
         {  Test for inequality. }
 
 
\binopfunc  ostream\&   {ostream\&\ O\ << rat\_segment\ s}
           {  writes the homogeneous coordinates of $s$ (six $integer$ numbers)
               to output stream $O$. }
 
 
\binopfunc  istream\&   {istream\&\ I\ >>rat\_segment\&\ s}
           {  reads the homogeneous coordinates of $s$ (six $integer$ numbers)
               from input stream $I$. }
 
 
\func  int cmp\_slopes {( rat\_segment\ s1, \  rat\_segment\ s2)}
           {  TO BE WRITTEN  }
 
 
\func  int orientation {( rat\_segment\ s, \  rat\_point\ p)}
           {  TO BE WRITTEN  }
 
 
\func  int cmp\_segments\_at\_xcoord {( rat\_segment\ s1, \  rat\_segment\ s2, \  rat\_point\ r)}
           {  TO BE WRITTEN  }
 
 
