home *** CD-ROM | disk | FTP | other *** search
- /*
- File: AltPoint.h
-
- Contains: C++ savvy points and rects (alternate ODPoint, ODRect)
-
- Owned by: Jens Alfke
-
- Copyright: © 1993 - 1995 by Apple Computer, Inc., all rights reserved.
-
- Notes:
-
- These are alternate definitions of the ODPoint and ODRect structs.
- These definitions have the same size and data format and can be used
- interchangeably with the basic definitions; but they're much more C++
- savvy, with constructors, operators, conversions, and utility methods.
-
- To use these classes instead of the defaults, just include "AltPoint.h"
- as the first thing in your source file. It has to be included first so
- it can override the default struct definitions in PlfmType.h.
-
- This API and implementation are **NOT** an official part of the OpenDoc
- API, just handy utilities for C++ programmers.
-
- */
-
-
- #ifndef _ALTPOINT_
- #define _ALTPOINT_
-
- // Make sure that built-in structs do not get defined by PlfmType.h.
- #if !defined(SOM_Module_OpenDoc_GeoTypes_defined)
- #define SOM_Module_OpenDoc_GeoTypes_defined
- #else
- #error "Must include AltPoint.h *before* ODTypes.h!"
- #endif
-
-
- #ifndef _ODTYPESF_
- #include "ODTypesF.h" // Must include before ODTypesM.xh
- #endif
-
- #ifndef SOM_Module_OpenDoc_Global_TypesB_defined
- #include "ODTypesB.xh"
- #endif
-
- #ifdef _PLATFORM_MACINTOSH_
- #ifndef __TYPES__
- #include <Types.h>
- #endif
- #endif
-
- //==============================================================================
- // ODCoordinate
- //==============================================================================
-
- typedef ODFixed ODCoordinate;
-
- //==============================================================================
- // ODPoint
- //==============================================================================
-
- struct ODPoint {
- public:
-
- // CONTENTS:
-
- ODCoordinate x, y;
-
- // CONSTRUCTORS:
-
- ODPoint( ) { }
-
- ODPoint( ODCoordinate xx, ODCoordinate yy )
- {x=xx; y=yy;}
-
- ODPoint( const ODPoint& ); // Copy constructor
-
- // ASSIGNMENT:
-
- ODPoint& operator= ( const ODPoint& ); // Copy from another pt
-
- // MODIFICATION:
-
- inline void Clear( )
- {x=y=0;}
- inline void Set( ODCoordinate xx, ODCoordinate yy )
- {x=xx; y=yy;}
- void Offset( ODCoordinate x, ODCoordinate y );
- void operator+=( const ODPoint& );
- void operator-=( const ODPoint& );
-
- // ACCESSORS:
-
- ODSShort IntX( ) const; // Returns X-coord as (16bit) integer
- ODSShort IntY( ) const; // Returns Y-coord as (16bit) integer
-
- // COMPARISON:
-
- ODBoolean operator==( const ODPoint& ) const;
- ODBoolean operator!=( const ODPoint& ) const;
- ODBoolean ApproxEquals( const ODPoint& ) const; // to within roundoff error
-
- // MAC TOOLBOX CONVENIENCES:
-
- #ifdef _PLATFORM_MACINTOSH_
- ODPoint( Point ); // Construct from QD point
- ODPoint& operator= ( const Point& ); // Copy from a QD Point
- Point AsQDPoint( ) const; // Convert to integer (QD) point
- void operator+=( const Point& ); // Add/subtract QD point
- void operator-=( const Point& );
- #endif
- };
-
-
- //==============================================================================
- // ODRect
- //==============================================================================
-
- struct ODRect {
- public:
-
- // CONTENTS:
-
- ODCoordinate left, top, right, bottom;
-
- // CONSTRUCTORS:
-
- ODRect( ) { }
- ODRect( ODCoordinate l, ODCoordinate t,
- ODCoordinate r, ODCoordinate b )
- {left=l; top=t; right=r; bottom=b; }
- ODRect( const ODPoint&, const ODPoint& ); // Any 2 opposite pts
- ODRect( const ODPoint &topLeft, ODCoordinate width, ODCoordinate height );
- #ifdef _PLATFORM_MACINTOSH_
- ODRect( const Rect& );
- #endif
-
- // ASSIGNMENT:
-
- #ifdef _PLATFORM_MACINTOSH_
- ODRect& operator= ( const Rect& );
- #endif
-
- // MODIFICATION:
-
- void Clear( );
- void Set( ODCoordinate l, ODCoordinate t, ODCoordinate r, ODCoordinate b );
- void Set( const ODPoint&, ODCoordinate width, ODCoordinate height );
- void Set( const ODPoint&, const ODPoint& ); // Any 2 opposite pts
- void SetInt( short l, short t, short r, short b );
- void Offset( ODCoordinate x, ODCoordinate y );
- void Offset( const ODPoint& );
- void Inset( ODCoordinate x, ODCoordinate y );
-
- void operator&= ( const ODRect& ); // Intersect with rectangle
- void operator|= ( const ODRect& ); // Union with rectangle
- void operator|= ( const ODPoint& ); // Expand to fit point
-
- // ACCESSORS
-
- const ODPoint& TopLeft( ) const
- {return *(ODPoint*)&left;}
- ODPoint& TopLeft( )
- {return *(ODPoint*)&left;}
- const ODPoint& BotRight( ) const
- {return *(ODPoint*)&right;}
- ODPoint& BotRight( )
- {return *(ODPoint*)&right;}
- ODCoordinate Width( ) const
- {return right-left;}
- ODCoordinate Height( ) const
- {return bottom-top;}
- #ifdef _PLATFORM_MACINTOSH_
- void AsQDRect( Rect& ) const;
- #endif
-
- // TESTING
-
- ODBoolean operator==( const ODRect& ) const;
- ODBoolean operator!=( const ODRect &r ) const
- {return !(*this==r);}
- ODBoolean ApproxEquals( const ODRect &r ) const;
-
- ODBoolean IsEmpty( ) const;
- ODBoolean Contains( const ODPoint& ) const;
- ODBoolean Contains( const ODRect& ) const;
- ODBoolean ApproxContains( const ODRect& ) const;
- ODBoolean Intersects( const ODRect& ) const;
- };
-
-
- #endif //_ALTPOINT_
-