home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / odtlktv4.zip / ODTLKT / TOOLKIT / BETA / SAMPLES / OPENDOC / PUBUTILS / LINEOPS.H < prev    next >
Text File  |  1995-11-29  |  3KB  |  97 lines

  1. /********************************************************************/
  2. /*  Licensed Materials - Property of IBM                            */
  3. /*                                                                  */
  4. /*                                                                  */
  5. /* Copyright (C) International Business Machines Corp., 1994.       */
  6. /* Copyright (C) Apple Computer, Inc., 1994                         */
  7. /*                                                                  */
  8. /*  US Government Users Restricted Rights -                         */
  9. /*  Use, duplication, or disclosure restricted                      */
  10. /*  by GSA ADP Schedule Contract with IBM Corp.                     */
  11. /*                                                                  */
  12. /********************************************************************/
  13. /*
  14.   File:    LineOps.h
  15.  
  16.   Contains:  Geometric operations on lines in 2-space.
  17.  
  18.   Theory of Operation:
  19.   
  20.   Endpoints of lines or ranges need not be given in any particular order.
  21.   
  22.   Ranges include both endpoints, unline rectangles which don't include right and bottom.
  23.   (This is necessary to make segments that share an endpoint intersect, and to make e.g.
  24.   the horizontal range of a vertical line be non-empty.)
  25.   
  26. */
  27.  
  28.  
  29. #ifndef _LINEOPS_
  30. #define _LINEOPS_
  31.  
  32. #ifndef INCL_ODDTS // include non-DTS C++ headers
  33.  
  34. #ifndef SOM_Module_OpenDoc_Global_TypesB_defined
  35. #include "ODTypesB.xh"    
  36. #endif
  37.  
  38. #else // include DTS C++ headers
  39.  
  40. #ifndef SOM_HH_DTS_Included
  41. #include <som.hh>
  42. #endif
  43. #ifndef _DTS_HH_INCLUDED_ODTypesB
  44. #include <ODTypesB.hh>
  45. #endif
  46.  
  47. #endif // ! INCL_ODDTS
  48.  
  49. enum{
  50.   kIntersection,        // Segments intersect
  51.   kOutsideIntersection,    // Lines intersect, but past ends of segments
  52.   kNoIntersection        // Lines are parallel or degenerate
  53. };
  54. typedef short IntersectionStatus;
  55.  
  56.  
  57. const ODCoordinate kFixedEpsilon = 7;    // This is about 0.0001 pixels
  58.  
  59.  
  60. extern "C" {
  61.  
  62.  
  63. inline ODCoordinate Min( ODCoordinate a, ODCoordinate b )  {return a<b ?a :b;}
  64. inline ODCoordinate Max( ODCoordinate a, ODCoordinate b )  {return a>b ?a :b;}
  65.  
  66. inline ODCoordinate Abs( ODCoordinate n )          {return n>=0 ?n :-n;}
  67.  
  68. ODBoolean WithinEpsilon( ODCoordinate a, ODCoordinate b );
  69.  
  70. ODCoordinate    Distance( const ODPoint &p0, const ODPoint &p1 );
  71.  
  72. void        GetLineShift( ODPoint p0, ODPoint p1, ODCoordinate dist,
  73.                   ODPoint &delta );
  74.  
  75. IntersectionStatus  IntersectLines( const ODPoint &p0, const ODPoint &p1,
  76.                     const ODPoint &q0, const ODPoint &q1,
  77.                     ODPoint *sect );
  78.           
  79. ODBoolean           IntersectSegments( const ODPoint &p0, const ODPoint &p1,
  80.                      const ODPoint &q0, const ODPoint &q1,
  81.                      ODPoint *sect );
  82.  
  83. ODCoordinate    GetLineXAtY( const ODPoint &p0, const ODPoint &p1,
  84.                      ODCoordinate y );
  85.  
  86. ODFract        GetIntersectionT( const ODPoint &p0, const ODPoint &p1,
  87.                     const ODPoint § );
  88.  
  89. ODBoolean           InRange( ODCoordinate n,  ODCoordinate r0, ODCoordinate r1 );
  90.  
  91. ODBoolean           RangesDisjoint( ODCoordinate a0, ODCoordinate a1,
  92.                   ODCoordinate b0, ODCoordinate b1 );
  93.  
  94. }
  95.  
  96. #endif //_LINEOPS_
  97.