home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 July: Mac OS SDK / Dev.CD Jul 96 SDK / Dev.CD Jul 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc / OpenDoc Development / Debugging Support / OpenDoc Source Code / Utilities / Interfaces / LineOps.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-22  |  2.1 KB  |  77 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        LineOps.h
  3.  
  4.     Contains:    Geometric operations on lines in 2-space.
  5.  
  6.     Owned by:    Jens Alfke
  7.                 IntersectLines by Ken Turkowski, from Apple Technical Memorandum KT14.
  8.  
  9.     Copyright:    © 1993 - 1995 by Apple Computer, Inc., all rights reserved.
  10.  
  11.     Theory of Operation:
  12.     
  13.     Endpoints of lines or ranges need not be given in any particular order.
  14.     
  15.     Ranges include both endpoints, unline rectangles which don't include right and bottom.
  16.     (This is necessary to make segments that share an endpoint intersect, and to make e.g.
  17.     the horizontal range of a vertical line be non-empty.)
  18.     
  19. */
  20.  
  21.  
  22. #ifndef _LINEOPS_
  23. #define _LINEOPS_
  24.  
  25. #ifndef _ODTYPES_
  26. #include "ODTypes.h"
  27. #endif
  28.  
  29.  
  30. enum{
  31.     kIntersection,                // Segments intersect
  32.     kOutsideIntersection,        // Lines intersect, but past ends of segments
  33.     kNoIntersection                // Lines are parallel or degenerate
  34. };
  35. typedef short IntersectionStatus;
  36.  
  37.  
  38. const ODCoordinate kFixedEpsilon = 7;        // This is about 0.0001 pixels
  39.  
  40.  
  41. extern "C" {
  42.  
  43.  
  44. inline ODCoordinate Min( ODCoordinate a, ODCoordinate b )    {return a<b ?a :b;}
  45. inline ODCoordinate Max( ODCoordinate a, ODCoordinate b )    {return a>b ?a :b;}
  46.  
  47. inline ODCoordinate Abs( ODCoordinate n )                    {return n>=0 ?n :-n;}
  48.  
  49. Boolean WithinEpsilon( ODCoordinate a, ODCoordinate b );
  50.  
  51. ODCoordinate        Distance( const ODPoint &p0, const ODPoint &p1 );
  52.  
  53. void                GetLineShift( ODPoint p0, ODPoint p1, ODCoordinate dist,
  54.                                     ODPoint &delta );
  55.  
  56. IntersectionStatus    IntersectLines( const ODPoint &p0, const ODPoint &p1,
  57.                                     const ODPoint &q0, const ODPoint &q1,
  58.                                     ODPoint *sect );
  59.                 
  60. Boolean                IntersectSegments( const ODPoint &p0, const ODPoint &p1,
  61.                                        const ODPoint &q0, const ODPoint &q1,
  62.                                        ODPoint *sect );
  63.  
  64. ODCoordinate        GetLineXAtY( const ODPoint &p0, const ODPoint &p1,
  65.                                        ODCoordinate y );
  66.  
  67. Fract                GetIntersectionT( const ODPoint &p0, const ODPoint &p1,
  68.                                       const ODPoint § );
  69.  
  70. Boolean                InRange( ODCoordinate n,  ODCoordinate r0, ODCoordinate r1 );
  71.  
  72. Boolean                RangesDisjoint( ODCoordinate a0, ODCoordinate a1,
  73.                                     ODCoordinate b0, ODCoordinate b1 );
  74.  
  75. }
  76.  
  77. #endif /*_LINEOPS_*/