UTGeometry.h

Go to the documentation of this file.
00001 //==================================================================================================
00002 // Copyright (C) 2010  Brian Tietz    sdbtietz at yahoo dot com
00003 //
00004 // This program is free software; you can redistribute it and/or modify it under the terms of the
00005 // GNU General Public License as published by the Free Software Foundation, version 2.0 of the
00006 // License.
00007 //
00008 // This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
00009 // even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00010 // General Public License for more details.
00011 //
00012 // You should have received a copy of the GNU General Public License along with this program; if
00013 // not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00014 // 02110-1301, USA.
00015 //
00016 // For commercial software, the copyright holder (Brian Tietz, email sdbtietz at yahoo dot com)
00017 // reserves the right and is willing to waive the proprietary source code disclosure aspects of that
00018 // license as applied to the UT library in exchange for either substantial contributions to the
00019 // development of the UT library or other forms of compensation.  Any such waiver must be
00020 // established in writing between the copyright holder and the commercial entity obtaining such a
00021 // waiver.
00022 //==================================================================================================
00023 
00024 
00025 #ifndef _UT_GEOMETRY_H_
00026 #define _UT_GEOMETRY_H_
00027 
00028 
00029 //==================================================================================================
00030 //=== Project headers
00031 //==================================================================================================
00032 #include "UT.h"
00033 #if __cplusplus
00034 #include "UTLists.h"
00035 #endif
00036 
00037 
00038 //==================================================================================================
00039 //=== Forward name declarations
00040 //==================================================================================================
00041 #if __cplusplus
00042 class RegionHStripe_t;
00043 class PoolAllocator_t;
00044 #endif
00045 
00046 
00047 //==================================================================================================
00048 //=== Constants
00049 //==================================================================================================
00053 #define c_pi                                3.1415926535897932384626433832795
00054 
00056 #define c_2_pi                              6.2831853071795864769252867665590
00057 
00059 #define c_pi_div2                           1.5707963267948966192313216916398
00060 
00062 #define c_3_pi_div2                         4.7123889803846898576939650749193
00063 
00070 #define c_dbl_abs_min_denominator           1.0e-12
00071 
00075 #define c_dbl_abs_min_denominator_squared   1.0e-24
00076 
00081 #define c_dbl_abs_min_vh_radial_distance    0.6e-11
00082 
00086 #define c_dbl_compare_equality_threshold    0.6e-6
00087 
00088 
00089 EXTERN_C_BEGIN
00090 
00091 
00092 //==================================================================================================
00093 struct UT_EXPORT Point_t
00094 //==================================================================================================
00112 {
00113     float                   x;
00115 
00116     float                   y;
00118 
00119     #if __cplusplus
00120 
00121     inline                  Point_t();
00123 
00124     inline                  Point_t( float x, float y );
00126 
00127     inline                  Point_t(const Point_t& copy);
00129 
00130     inline const Point_t&   operator =(const Point_t& copy);
00132 
00133     bool                    operator ==(const Point_t& other) const;
00139 
00140     bool                    operator !=(const Point_t& other) const;
00146 
00147     inline Point_t          operator +(const Point_t& add) const;
00149 
00150     inline Point_t          operator -(const Point_t& subtract) const;
00154 
00155     inline const Point_t&   operator +=(const Point_t& add);
00157 
00158     inline const Point_t&   operator -=(const Point_t& subtract);
00161 
00162     #endif // __cplusplus
00163 };
00164 
00165 
00166 //==================================================================================================
00167 struct UT_EXPORT Rect_t
00168 //==================================================================================================
00180 {
00181     float                   left;
00184 
00185     float                   top;
00188 
00189     float                   right;
00200 
00201     float                   bottom;
00212 
00213     #if __cplusplus
00214     inline                  Rect_t();
00217 
00218     inline                  Rect_t( float left, float top, float right, float bottom );
00220 
00221     inline                  Rect_t(const Rect_t& copy);
00223 
00224     inline const Rect_t&    operator =(const Rect_t& copy);
00226 
00227     bool                    operator ==(const Rect_t& other) const;
00233 
00234     bool                    operator !=(const Rect_t& other) const;
00240 
00241     inline Rect_t           operator +(const Point_t& add) const;
00246 
00247     inline Rect_t           operator -(const Point_t& subtract) const;
00252 
00253     inline const Rect_t&    operator +=(const Point_t& add);
00257 
00258     inline const Rect_t&    operator -=(const Point_t& subtract);
00262 
00263     bool                    Contains(const Point_t& point) const;
00265 
00266     bool                    Overlapping(const Rect_t& other) const;
00269 
00270     Rect_t                  operator &(const Rect_t& intersect) const;
00273 
00274     const Rect_t&           operator &=(const Rect_t& intersect);
00276 
00277     Rect_t                  operator |(const Rect_t& intersect) const;
00279 
00280     const Rect_t&           operator |=(const Rect_t& intersect);
00283 
00284     inline float            Width() const;
00286 
00287     inline float            Height() const;
00289 
00290     void                    OffsetTo(const Point_t& left_top);
00293 
00294     inline void             InsetBy(float value);
00296 
00297     inline void             InsetBy( float left, float top, float right, float bottom );
00299 
00300     inline void             ExpandBy(float value);
00302 
00303     inline void             ExpandBy( float left, float top, float right, float bottom );
00305 
00306     void                    ExpandToInteger();
00309 
00310     inline Rect_t           OffsetToCopy(const Point_t& left_top) const;
00314 
00315     inline Rect_t           InsetByCopy(float value) const;
00319 
00320     inline Rect_t           InsetByCopy( float left, float top, float right, float bottom ) const;
00324 
00325     inline Rect_t           ExpandByCopy(float value) const;
00329 
00330     inline Rect_t           ExpandByCopy( float left, float top, float right, float bottom ) const;
00334 
00335     inline Point_t          LeftTop() const;
00337 
00338     inline Point_t          RightTop() const;
00340 
00341     inline Point_t          LeftBottom() const;
00343 
00344     inline Point_t          RightBottom() const;
00346 
00347     #endif // __cplusplus
00348 };
00349 
00350 
00351 EXTERN_C_END
00352 
00353 #if __cplusplus
00354 
00355 
00356 //==================================================================================================
00357 class UT_EXPORT Region_t
00358 //==================================================================================================
00360 {
00361     //----------------------------------------------------------------------------------------------
00362     public:
00363     //----------------------------------------------------------------------------------------------
00364                     Region_t(bool main_thread_only = false);
00371 
00372                     Region_t( const Rect_t& rect, bool main_thread_only = false );
00378 
00379                     Region_t( const Region_t& copy, bool main_thread_only = false );
00390 
00391                     ~Region_t();
00393 
00394     const Region_t& operator =(const Region_t& copy);
00396 
00397     const Region_t& operator =(const Rect_t& copy);
00399 
00400     const Region_t& operator |=(const Rect_t& rect);
00402 
00403     const Region_t& operator +=(const Rect_t& rect);
00405 
00406     const Region_t& operator -=(const Rect_t& rect);
00411 
00412     const Region_t& operator &=(const Rect_t& rect);
00414 
00415     const Region_t& operator |=(const Region_t& other);
00417 
00418     const Region_t& operator +=(const Region_t& other);
00420 
00421     const Region_t& operator -=(const Region_t& other);
00426 
00427     const Region_t& operator &=(const Region_t& other);
00429 
00430     bool            operator ==(const Region_t& other);
00432 
00433     inline bool     operator !=(const Region_t& other);
00435 
00436     int             CountRects() const;
00438 
00439     inline Rect_t   RectAt(int index) const;
00443 
00444     void            GetRectAt( out Rect_t* rect, int index ) const;
00448 
00449     void            Clear();
00451 
00452     void            Shift(const Point_t& offset);
00458 
00459     bool            Contains(const Point_t& point) const;
00461 
00462     bool            Overlapping(const Rect_t& rect) const;
00465 
00466     inline Rect_t   BoundingBox() const;
00468 
00469     void            GetBoundingBox(out Rect_t* bounding_box) const;
00471 
00472     //----------------------------------------------------------------------------------------------
00473     private:
00474     //----------------------------------------------------------------------------------------------
00475     bool            PrepForStripeOpMainLoop(    const Rect_t& op_rect,
00476                                                 bool add_op_rect,
00477                                                 RegionHStripe_t** existing,
00478                                                 float* merge_y,
00479                                                 bool* any_changes_made );
00480     void            StripeOpMainLoop(   const Rect_t& op_rect,
00481                                         bool add_op_rect,
00482                                         RegionHStripe_t* existing,
00483                                         float merge_y,
00484                                         bool any_changes_made );
00485     void            ConsolidateRows(const Rect_t& op_rect);
00486 
00487     //----------------------------------------------------------------------------------------------
00488     private:
00489     //----------------------------------------------------------------------------------------------
00490     PoolAllocator_t*                    m_allocator;
00491     BTree_t< RegionHStripe_t, float >   m_stripes;
00492     mutable int                         m_optimize_num_rects;
00493     mutable RegionHStripe_t*            m_optimize_rect_at_index_stripe;
00494     mutable int                         m_optimize_rect_at_index_index;
00495                                             // Valid only if m_optimize_rect_at_index_stripe is not
00496                                             // NULL
00497 };
00498 
00499 
00500 //==================================================================================================
00501 class UT_EXPORT Polygon_t
00502 //==================================================================================================
00514 {
00515     //----------------------------------------------------------------------------------------------
00516     public:
00517     //----------------------------------------------------------------------------------------------
00518     inline                  Polygon_t();
00520 
00521                             Polygon_t( const Point_t* vertices, int num_vertices );
00523 
00524                             Polygon_t(const Rect_t& rect);
00528 
00529                             Polygon_t(const Polygon_t& polygon);
00531 
00532     inline void             AddVertex(const Point_t& vertex);
00535 
00536     inline void             InsertVertex( const Point_t& vertex, int index );
00540 
00541     inline void             RemoveVertex(int index);
00543 
00544     inline void             ReplaceVertex( int index, const Point_t& vertex );
00546 
00547     inline int              CountVertices() const;
00549 
00550     inline void             Clear();
00552 
00553     inline const Point_t&   VertexAt(int index) const;
00555 
00556     const Polygon_t&        operator =(const Polygon_t& copy);
00558 
00559     const Polygon_t&        operator =(const Rect_t& rect);
00561 
00562     void                    Shift(const Point_t& offset);
00569 
00570     bool                    Contains(const Point_t& point) const;
00573 
00574     bool                    Overlapping(const Rect_t& rect) const;
00577 
00578     inline Rect_t           BoundingBox() const;
00581 
00582     void                    GetBoundingBox(out Rect_t* bounding_box) const;
00585 
00586     void                    FindClosestPoint(   const Point_t& from,
00587                                                 out Point_t* closest_point_on_polygon,
00588                                                 out int* after_index,
00589                                                 bool on_edge_if_inside ) const;
00600 
00601     void                    RotateAbout( double radians, const Point_t& point );
00604 
00605     //----------------------------------------------------------------------------------------------
00606     private:
00607     //----------------------------------------------------------------------------------------------
00608     Array_t<Point_t>        m_vertices;
00609     Point_t                 m_builtin_points[4];
00610     int                     m_num_vertices;
00611 };
00612 
00613 
00614 #endif // __cplusplus
00615 
00616 EXTERN_C_BEGIN
00617 
00618 
00619 //==================================================================================================
00620 struct UT_EXPORT Circle_t
00621 //==================================================================================================
00640 {
00641     Point_t                 center;
00643 
00644     double                  radius;
00646 
00647     #if __cplusplus
00648     inline                  Circle_t();
00651 
00652     inline                  Circle_t( const Point_t& center, double radius );
00654 
00655     inline                  Circle_t(const Circle_t& copy);
00657 
00658     inline void             Set( const Point_t& center, double radius );
00660 
00661     inline const Circle_t&  operator =(const Circle_t& copy);
00663 
00664     inline Circle_t         operator +(const Point_t& add) const;
00667 
00668     inline Circle_t         operator -(const Point_t& subtract) const;
00671 
00672     inline const Circle_t&  operator +=(const Point_t& add);
00675 
00676     inline const Circle_t&  operator -=(const Point_t& subtract);
00679 
00680     bool                    Contains(const Point_t& point) const;
00682 
00683     bool                    Overlapping(const Rect_t& rect) const;
00686 
00687     inline Rect_t           BoundingBox() const;
00689 
00690     inline void             GetBoundingBox(out Rect_t* bounding_box) const;
00692 
00693     int                     FindXIntercepts(    float y,
00694                                                 out float* x,
00695                                                 out double* radian = NULL,
00696                                                 out double* slope = NULL ) const;
00712 
00713     int                     FindYIntercepts(    float x,
00714                                                 out float* y,
00715                                                 out double* radian = NULL,
00716                                                 out double* slope = NULL ) const;
00732 
00733     void                    FindClosestPoint(   const Point_t& from,
00734                                                 bool on_edge_if_inside,
00735                                                 out Point_t* closest_point_on_circle,
00736                                                 out double* radian = NULL,
00737                                                 out double* slope = NULL ) const;
00756     #endif // __cplusplus
00757 };
00758 
00759 
00760 EXTERN_C_END
00761 
00762 #if __cplusplus
00763 
00764 
00765 //==================================================================================================
00766 class UT_EXPORT Ellipse_t
00767 //==================================================================================================
00812 {
00813     //----------------------------------------------------------------------------------------------
00814     public:
00815     //----------------------------------------------------------------------------------------------
00816     inline                  Ellipse_t();
00818 
00819                             Ellipse_t(  const Point_t& center,
00820                                         float width,
00821                                         float height,
00822                                         double rotation );
00827 
00828                             Ellipse_t(const Ellipse_t& copy);
00830 
00831     void                    Set(    const Point_t& center,
00832                                     float width,
00833                                     float height,
00834                                     double rotation );
00836 
00837     inline Point_t          Center() const;
00839 
00840     inline void             GetCenter(out Point_t* center) const;
00842 
00843     inline float            Width() const;
00845 
00846     inline float            Height() const;
00848 
00849     inline double           Rotation() const;
00852 
00853     const Ellipse_t&        operator =(const Ellipse_t& copy);
00855 
00856     inline Ellipse_t        operator +(const Point_t& add) const;
00859 
00860     inline Ellipse_t        operator -(const Point_t& subtract) const;
00863 
00864     inline const Ellipse_t& operator +=(const Point_t& add);
00867 
00868     inline const Ellipse_t& operator -=(const Point_t& subtract);
00871 
00872     bool                    Contains(const Point_t& point) const;
00874 
00875     bool                    Overlapping(const Rect_t& rect) const;
00878 
00879     inline Rect_t           BoundingBox() const;
00882 
00883     void                    GetBoundingBox( out Rect_t* bounding_box,
00884                                             out double* t_left = NULL,
00885                                             out double* t_top = NULL,
00886                                             out double* t_right = NULL,
00887                                             out double* t_bottom = NULL ) const;
00891 
00892     void                    GetPointAndSlopeAtT(    double t,
00893                                                     out Point_t* point_on_ellipse,
00894                                                     out double* slope = NULL ) const;
00897 
00898     int                     FindXIntercepts(    float y,
00899                                                 out float* x,
00900                                                 out double* t = NULL,
00901                                                 out double* slope = NULL ) const;
00908 
00909     int                     FindYIntercepts(    float x,
00910                                                 out float* y,
00911                                                 out double* t = NULL,
00912                                                 out double* slope = NULL ) const;
00919 
00920     void                    FindClosestPoint(   const Point_t& from,
00921                                                 bool on_edge_if_inside,
00922                                                 out Point_t* closest_point_on_ellipse,
00923                                                 out double* t = NULL,
00924                                                 out double* slope = NULL ) const;
00937 
00938     void                    Rotate(double radians);
00940 
00941     void                    RotateAbout( double radians, const Point_t& point );
00944 
00945     //----------------------------------------------------------------------------------------------
00946     private:
00947     //----------------------------------------------------------------------------------------------
00948     void                PrecalculateValues();
00949     int                 FindUnrotatedXIntercepts(   float y,
00950                                                     out float* x,
00951                                                     out double* t ,
00952                                                     out double* slope ) const;
00953     int                 Find90DegreeRotatedXIntercepts( float y,
00954                                                         out float* x,
00955                                                         out double* t,
00956                                                         out double* slope ) const;
00957     int                 FindRotatedNoWidthXIntercepts(  float y,
00958                                                         out float* x,
00959                                                         out double* t,
00960                                                         out double* slope ) const;
00961     int                 FindRotatedNoHeightXIntercepts( float y,
00962                                                         out float* x,
00963                                                         out double* t,
00964                                                         out double* slope ) const;
00965 
00966     int                 FindUnrotatedYIntercepts(   float x,
00967                                                     out float* y,
00968                                                     out double* t ,
00969                                                     out double* slope ) const;
00970     int                 Find90DegreeRotatedYIntercepts( float x,
00971                                                         out float* y,
00972                                                         out double* t,
00973                                                         out double* slope ) const;
00974     int                 FindRotatedNoWidthYIntercepts(  float x,
00975                                                         out float* y,
00976                                                         out double* t,
00977                                                         out double* slope ) const;
00978     int                 FindRotatedNoHeightYIntercepts( float x,
00979                                                         out float* y,
00980                                                         out double* t,
00981                                                         out double* slope ) const;
00982 
00983     void                FindClosestPointNoWidth(    double point_x,
00984                                                     double point_y,
00985                                                     out Point_t* closest_point_on_ellipse,
00986                                                     out double* t,
00987                                                     out double* slope ) const;
00988     void                FindClosestPointNoHeight(   double point_x,
00989                                                     double point_y,
00990                                                     out Point_t* closest_point_on_ellipse,
00991                                                     out double* t,
00992                                                     out double* slope ) const;
00993 
00994     //----------------------------------------------------------------------------------------------
00995     private:
00996     //----------------------------------------------------------------------------------------------
00997     Point_t             m_center;
00998     float               m_half_width;
00999     float               m_half_height;
01000     double              m_rotation;
01001 
01002     // Pre-calculated values:
01003     bool                m_rotated;
01004     uint8               m_rotated_90_degree_increments;
01005     double              m_sin_rotation;
01006     double              m_cos_rotation;
01007 };
01008 
01009 
01010 EXTERN_C_BEGIN
01011 #endif // __cplusplus
01012 
01013 
01014 //==================================================================================================
01015 //=== Utility functions
01016 //==================================================================================================
01017 
01022 extern UT_EXPORT void expand_to_integer( float* value, bool expand_to_lower_number );
01023 
01028 extern UT_EXPORT bool find_line_intercept(  const Point_t* line_a_from,
01029                                             const Point_t* line_a_to,
01030                                             const Point_t* line_b_from,
01031                                             const Point_t* line_b_to,
01032                                             out Point_t* intercept,
01033                                             bool only_if_line_segments_intercept );
01034 
01035 #if __cplusplus
01036 EXTERN_C_END
01037 
01042 inline bool find_line_intercept(    const Point_t& line_a_from,
01043                                     const Point_t& line_a_to,
01044                                     const Point_t& line_b_from,
01045                                     const Point_t& line_b_to,
01046                                     out Point_t* intercept,
01047                                     bool only_if_line_segments_intercept = true );
01048 
01049 EXTERN_C_BEGIN
01050 #endif // __cplusplus
01051 
01054 extern UT_EXPORT bool find_slope_intercept( const Point_t* line_a_from,
01055                                             double line_a_slope,
01056                                             const Point_t* line_b_from,
01057                                             double line_b_slope,
01058                                             out Point_t* intercept );
01059 
01060 #if __cplusplus
01061 EXTERN_C_END
01062 
01065 inline bool find_slope_intercept(   const Point_t& line_a_from,
01066                                     double line_a_slope,
01067                                     const Point_t& line_b_from,
01068                                     double line_b_slope,
01069                                     out Point_t* intercept );
01070 
01071 EXTERN_C_BEGIN
01072 #endif // __cplusplus
01073 
01078 extern UT_EXPORT bool find_line_x_intercept(    const Point_t* line_a_from,
01079                                                 const Point_t* line_a_to,
01080                                                 const Point_t* line_b_from,
01081                                                 const Point_t* line_b_to,
01082                                                 out float* x_intercept,
01083                                                 bool only_if_line_segments_intercept );
01084 
01085 #if __cplusplus
01086 EXTERN_C_END
01087 
01092 inline bool find_line_x_intercept(  const Point_t& line_a_from,
01093                                     const Point_t& line_a_to,
01094                                     const Point_t& line_b_from,
01095                                     const Point_t& line_b_to,
01096                                     out float* x_intercept,
01097                                     bool only_if_line_segments_intercept = true );
01098 
01099 EXTERN_C_BEGIN
01100 #endif // __cplusplus
01101 
01105 extern UT_EXPORT bool find_slope_x_intercept(   const Point_t* line_a_from,
01106                                                 double line_a_slope,
01107                                                 const Point_t* line_b_from,
01108                                                 double line_b_slope,
01109                                                 out float* x_intercept );
01110 
01111 #if __cplusplus
01112 EXTERN_C_END
01113 
01117 inline bool find_slope_x_intercept( const Point_t& line_a_from,
01118                                     double line_a_slope,
01119                                     const Point_t& line_b_from,
01120                                     double line_b_slope,
01121                                     out float* x_intercept );
01122 
01123 EXTERN_C_BEGIN
01124 #endif // __cplusplus
01125 
01130 extern UT_EXPORT bool find_line_y_intercept(    const Point_t* line_a_from,
01131                                                 const Point_t* line_a_to,
01132                                                 const Point_t* line_b_from,
01133                                                 const Point_t* line_b_to,
01134                                                 out float* y_intercept,
01135                                                 bool only_if_line_segments_intercept );
01136 
01137 #if __cplusplus
01138 EXTERN_C_END
01139 
01144 inline bool find_line_y_intercept(  const Point_t& line_a_from,
01145                                     const Point_t& line_a_to,
01146                                     const Point_t& line_b_from,
01147                                     const Point_t& line_b_to,
01148                                     out float* y_intercept,
01149                                     bool only_if_line_segments_intercept = true );
01150 
01151 EXTERN_C_BEGIN
01152 #endif // __cplusplus
01153 
01157 extern UT_EXPORT bool find_slope_y_intercept(   const Point_t* line_a_from,
01158                                                 double line_a_slope,
01159                                                 const Point_t* line_b_from,
01160                                                 double line_b_slope,
01161                                                 out float* y_intercept );
01162 
01163 #if __cplusplus
01164 EXTERN_C_END
01165 
01169 inline bool find_slope_y_intercept( const Point_t& line_a_from,
01170                                     double line_a_slope,
01171                                     const Point_t& line_b_from,
01172                                     double line_b_slope,
01173                                     out float* y_intercept );
01174 
01175 EXTERN_C_BEGIN
01176 #endif // __cplusplus
01177 
01180 extern UT_EXPORT void normalize_radians(double* radian);
01181 
01182 #if __cplusplus
01183 EXTERN_C_END
01184 
01185 
01186 
01187 
01188 //==================================================================================================
01189 //==================================================================================================
01190 //===
01191 //=== Inline function implementations: utility functions
01192 //===
01193 //==================================================================================================
01194 //==================================================================================================
01195 inline bool
01196 find_line_intercept(    const Point_t& line_a_from,
01197                         const Point_t& line_a_to,
01198                         const Point_t& line_b_from,
01199                         const Point_t& line_b_to,
01200                         out Point_t* intercept,
01201                         bool only_if_line_segments_intercept )
01202 {
01203     return find_line_intercept( &line_a_from,
01204                                 &line_a_to,
01205                                 &line_b_from,
01206                                 &line_b_to,
01207                                 intercept,
01208                                 only_if_line_segments_intercept );
01209 }
01210 
01211 
01212 inline bool
01213 find_slope_intercept(   const Point_t& line_a_from,
01214                         double line_a_slope,
01215                         const Point_t& line_b_from,
01216                         double line_b_slope,
01217                         out Point_t* intercept )
01218 {
01219     return find_slope_intercept(    &line_a_from,
01220                                     line_a_slope,
01221                                     &line_b_from,
01222                                     line_b_slope,
01223                                     intercept );
01224 }
01225 
01226 
01227 inline bool
01228 find_line_x_intercept(  const Point_t& line_a_from,
01229                         const Point_t& line_a_to,
01230                         const Point_t& line_b_from,
01231                         const Point_t& line_b_to,
01232                         out float* x_intercept,
01233                         bool only_if_line_segments_intercept )
01234 {
01235     return find_line_x_intercept(   &line_a_from,
01236                                     &line_a_to,
01237                                     &line_b_from,
01238                                     &line_b_to,
01239                                     x_intercept,
01240                                     only_if_line_segments_intercept );
01241 }
01242 
01243 
01244 inline bool
01245 find_slope_x_intercept( const Point_t& line_a_from,
01246                         double line_a_slope,
01247                         const Point_t& line_b_from,
01248                         double line_b_slope,
01249                         out float* x_intercept )
01250 {
01251     return find_slope_x_intercept(  &line_a_from,
01252                                     line_a_slope,
01253                                     &line_b_from,
01254                                     line_b_slope,
01255                                     x_intercept );
01256 }
01257 
01258 
01259 inline bool
01260 find_line_y_intercept(  const Point_t& line_a_from,
01261                         const Point_t& line_a_to,
01262                         const Point_t& line_b_from,
01263                         const Point_t& line_b_to,
01264                         out float* y_intercept,
01265                         bool only_if_line_segments_intercept )
01266 {
01267     return find_line_y_intercept(   &line_a_from,
01268                                     &line_a_to,
01269                                     &line_b_from,
01270                                     &line_b_to,
01271                                     y_intercept,
01272                                     only_if_line_segments_intercept );
01273 }
01274 
01275 
01276 inline bool
01277 find_slope_y_intercept( const Point_t& line_a_from,
01278                         double line_a_slope,
01279                         const Point_t& line_b_from,
01280                         double line_b_slope,
01281                         out float* y_intercept )
01282 {
01283     return find_slope_y_intercept(  &line_a_from,
01284                                 line_a_slope,
01285                                 &line_b_from,
01286                                 line_b_slope,
01287                                 y_intercept );
01288 }
01289 
01290 
01291 
01292 
01293 //==================================================================================================
01294 //==================================================================================================
01295 //===
01296 //=== Inline function implementations: struct Point_t
01297 //===
01298 //==================================================================================================
01299 //==================================================================================================
01300 inline
01301 Point_t::Point_t()
01302 {
01303     // Constructor for an uninitialized point, just to make the compiler happy (not actually
01304     // initialized).
01305 }
01306 
01307 
01308 inline
01309 Point_t::Point_t( float a_x, float a_y )
01310 {
01311     x = a_x;
01312     y = a_y;
01313 }
01314 
01315 
01316 inline
01317 Point_t::Point_t(const Point_t& copy)
01318 {
01319     x = copy.x;
01320     y = copy.y;
01321 }
01322 
01323 
01324 inline const Point_t&
01325 Point_t::operator =(const Point_t& copy)
01326 {
01327     x = copy.x;
01328     y = copy.y;
01329     return *this;
01330 }
01331 
01332 
01333 inline Point_t
01334 Point_t::operator +(const Point_t& add) const
01335 {
01336     return Point_t( x+add.x, y+add.y );
01337 }
01338 
01339 
01340 inline Point_t
01341 Point_t::operator -(const Point_t& subtract) const
01342 {
01343     return Point_t( x-subtract.x, y-subtract.y );
01344 }
01345 
01346 
01347 inline const Point_t&
01348 Point_t::operator +=(const Point_t& add)
01349 {
01350     x += add.x;
01351     y += add.y;
01352     return *this;
01353 }
01354 
01355 
01356 inline const Point_t&
01357 Point_t::operator -=(const Point_t& subtract)
01358 {
01359     x -= subtract.x;
01360     y -= subtract.y;
01361     return *this;
01362 }
01363 
01364 
01365 
01366 
01367 //==================================================================================================
01368 //==================================================================================================
01369 //===
01370 //=== Inline function implementations: struct Rect_t
01371 //===
01372 //==================================================================================================
01373 //==================================================================================================
01374 inline
01375 Rect_t::Rect_t()
01376 {
01377     // Constructor for an uninitialized rectangle, just to make the compiler happy.
01378 }
01379 
01380 
01381 inline
01382 Rect_t::Rect_t( float a_left, float a_top, float a_right, float a_bottom )
01383 {
01384     left = a_left;
01385     top = a_top;
01386     right = a_right;
01387     bottom = a_bottom;
01388 }
01389 
01390 
01391 inline
01392 Rect_t::Rect_t(const Rect_t& copy)
01393 {
01394     left = copy.left;
01395     top = copy.top;
01396     right = copy.right;
01397     bottom = copy.bottom;
01398 }
01399 
01400 
01401 inline const Rect_t&
01402 Rect_t::operator =(const Rect_t& copy)
01403 {
01404     left = copy.left;
01405     top = copy.top;
01406     right = copy.right;
01407     bottom = copy.bottom;
01408     return *this;
01409 }
01410 
01411 
01412 inline Rect_t
01413 Rect_t::operator +(const Point_t& add) const
01414 {
01415     return Rect_t( left+add.x, top+add.y, right+add.x, bottom+add.y );
01416 }
01417 
01418 
01419 inline Rect_t
01420 Rect_t::operator -(const Point_t& subtract) const
01421 {
01422     return Rect_t( left-subtract.x, top-subtract.y, right-subtract.x, bottom-subtract.y );
01423 }
01424 
01425 
01426 inline const Rect_t&
01427 Rect_t::operator +=(const Point_t& add)
01428 {
01429     left += add.x;
01430     right += add.x;
01431     top += add.y;
01432     bottom += add.y;
01433     return *this;
01434 }
01435 
01436 
01437 inline const Rect_t&
01438 Rect_t::operator -=(const Point_t& subtract)
01439 {
01440     left -= subtract.x;
01441     right -= subtract.x;
01442     top -= subtract.y;
01443     bottom -= subtract.y;
01444     return *this;
01445 }
01446 
01447 
01448 inline float
01449 Rect_t::Width() const
01450 {
01451     return right - left;
01452 }
01453 
01454 
01455 inline float
01456 Rect_t::Height() const
01457 {
01458     return bottom - top;
01459 }
01460 
01461 
01462 inline void
01463 Rect_t::InsetBy(float value)
01464 {
01465     left += value;
01466     top += value;
01467     right -= value;
01468     bottom -= value;
01469 }
01470 
01471 
01472 inline void
01473 Rect_t::InsetBy( float d_left, float d_top, float d_right, float d_bottom )
01474 {
01475     left += d_left;
01476     top += d_top;
01477     right -= d_right;
01478     bottom -= d_bottom;
01479 }
01480 
01481 
01482 inline void
01483 Rect_t::ExpandBy(float value)
01484 {
01485     left -= value;
01486     top -= value;
01487     right += value;
01488     bottom += value;
01489 }
01490 
01491 
01492 inline void
01493 Rect_t::ExpandBy( float d_left, float d_top, float d_right, float d_bottom )
01494 {
01495     left -= d_left;
01496     top -= d_top;
01497     right += d_right;
01498     bottom += d_bottom;
01499 }
01500 
01501 
01502 inline Rect_t
01503 Rect_t::OffsetToCopy(const Point_t& left_top) const
01504 {
01505     Rect_t offset = *this;
01506     offset.OffsetTo(left_top);
01507     return offset;
01508 }
01509 
01510 
01511 inline Rect_t
01512 Rect_t::InsetByCopy(float value) const
01513 {
01514     return Rect_t( left+value, top+value, right-value, bottom-value );
01515 }
01516 
01517 
01518 inline Rect_t
01519 Rect_t::InsetByCopy( float d_left, float d_top, float d_right, float d_bottom ) const
01520 {
01521     return Rect_t( left+d_left, top+d_top, right-d_right, bottom-d_bottom );
01522 }
01523 
01524 
01525 inline Rect_t
01526 Rect_t::ExpandByCopy(float value) const
01527 {
01528     return Rect_t( left-value, top-value, right+value, bottom+value );
01529 }
01530 
01531 
01532 inline Rect_t
01533 Rect_t::ExpandByCopy( float d_left, float d_top, float d_right, float d_bottom ) const
01534 {
01535     return Rect_t( left-d_left, top-d_top, right+d_right, bottom+d_bottom );
01536 }
01537 
01538 
01539 inline Point_t
01540 Rect_t::LeftTop() const
01541 {
01542     return Point_t( left, top );
01543 }
01544 
01545 
01546 inline Point_t
01547 Rect_t::RightTop() const
01548 {
01549     return Point_t( right, top );
01550 }
01551 
01552 
01553 inline Point_t
01554 Rect_t::LeftBottom() const
01555 {
01556     return Point_t( left, bottom );
01557 }
01558 
01559 
01560 inline Point_t
01561 Rect_t::RightBottom() const
01562 {
01563     return Point_t( right, bottom );
01564 }
01565 
01566 
01567 
01568 
01569 //==================================================================================================
01570 //==================================================================================================
01571 //===
01572 //=== Inline function implementations: class Region_t
01573 //===
01574 //==================================================================================================
01575 //==================================================================================================
01576 inline bool
01577 Region_t::operator !=(const Region_t& other)
01578 {
01579     return !(*this == other);
01580 }
01581 
01582 
01583 inline Rect_t
01584 Region_t::RectAt(int index) const
01585 {
01586     Rect_t rect;
01587     GetRectAt( &rect, index );
01588     return rect;
01589 }
01590 
01591 
01592 inline Rect_t
01593 Region_t::BoundingBox() const
01594 {
01595     Rect_t rect;
01596     GetBoundingBox(&rect);
01597     return rect;
01598 }
01599 
01600 
01601 
01602 
01603 //==================================================================================================
01604 //==================================================================================================
01605 //===
01606 //=== Inline function implementations: class Polygon_t
01607 //===
01608 //==================================================================================================
01609 //==================================================================================================
01610 inline
01611 Polygon_t::Polygon_t()
01612 {
01613     m_vertices.InstallStackBuffer( m_builtin_points, 4 );
01614 }
01615 
01616 
01617 inline void
01618 Polygon_t::AddVertex(const Point_t& vertex)
01619 {
01620     m_vertices += vertex;
01621 }
01622 
01623 
01624 inline void
01625 Polygon_t::InsertVertex( const Point_t& vertex, int index )
01626 {
01627     m_vertices.AddItemAt( vertex, index );
01628 }
01629 
01630 
01631 inline void
01632 Polygon_t::ReplaceVertex( int index, const Point_t& vertex )
01633 {
01634     m_vertices[index] = vertex;
01635 }
01636 
01637 
01638 inline void
01639 Polygon_t::RemoveVertex(int index)
01640 {
01641     m_vertices.RemoveItemAt(index);
01642 }
01643 
01644 
01645 inline int
01646 Polygon_t::CountVertices() const
01647 {
01648     return m_vertices.CountItems();
01649 }
01650 
01651 
01652 inline void
01653 Polygon_t::Clear()
01654 {
01655     m_vertices.SetNumValidItems(0);
01656 }
01657 
01658 
01659 inline const Point_t&
01660 Polygon_t::VertexAt(int index) const
01661 {
01662     assert( index < m_vertices.CountItems() );
01663     return m_vertices[index];
01664 }
01665 
01666 
01667 inline Rect_t
01668 Polygon_t::BoundingBox() const
01669 {
01670     Rect_t bounding_box;
01671     GetBoundingBox(&bounding_box);
01672     return bounding_box;
01673 }
01674 
01675 
01676 
01677 
01678 //==================================================================================================
01679 //==================================================================================================
01680 //===
01681 //=== Inline function implementations: struct Circle_t
01682 //===
01683 //==================================================================================================
01684 //==================================================================================================
01685 inline
01686 Circle_t::Circle_t()
01687 {
01688     // Constructor for an uninitialized circle, just to make the compiler happy.
01689 }
01690 
01691 
01692 inline
01693 Circle_t::Circle_t( const Point_t& a_center, double a_radius )
01694 {
01695     center = a_center;
01696     radius = a_radius;
01697 }
01698 
01699 
01700 inline
01701 Circle_t::Circle_t(const Circle_t& copy)
01702 {
01703     center = copy.center;
01704     radius = copy.radius;
01705 }
01706 
01707 
01708 inline void
01709 Circle_t::Set( const Point_t& a_center, double a_radius )
01710 {
01711     center = a_center;
01712     radius = a_radius;
01713 }
01714 
01715 
01716 inline const Circle_t&
01717 Circle_t::operator =(const Circle_t& copy)
01718 {
01719     center = copy.center;
01720     radius = copy.radius;
01721     return *this;
01722 }
01723 
01724 
01725 inline Circle_t
01726 Circle_t::operator +(const Point_t& add) const
01727 {
01728     return Circle_t( center + add, radius );
01729 }
01730 
01731 
01732 inline Circle_t
01733 Circle_t::operator -(const Point_t& subtract) const
01734 {
01735     return Circle_t( center - subtract, radius );
01736 }
01737 
01738 
01739 inline const Circle_t&
01740 Circle_t::operator +=(const Point_t& add)
01741 {
01742     center += add;
01743     return *this;
01744 }
01745 
01746 
01747 inline const Circle_t&
01748 Circle_t::operator -=(const Point_t& subtract)
01749 {
01750     center -= subtract;
01751     return *this;
01752 }
01753 
01754 
01755 inline Rect_t
01756 Circle_t::BoundingBox() const
01757 {
01758     return Rect_t(  center.x-static_cast<float>(radius),
01759                     center.y-static_cast<float>(radius),
01760                     center.x+static_cast<float>(radius),
01761                     center.y+static_cast<float>(radius) );
01762 }
01763 
01764 
01765 inline void
01766 Circle_t::GetBoundingBox(out Rect_t* bounding_box) const
01767 {
01768     bounding_box->left = center.x-static_cast<float>(radius);
01769     bounding_box->top = center.y-static_cast<float>(radius);
01770     bounding_box->right = center.x+static_cast<float>(radius);
01771     bounding_box->bottom = center.y+static_cast<float>(radius);
01772 }
01773 
01774 
01775 
01776 
01777 //==================================================================================================
01778 //==================================================================================================
01779 //===
01780 //=== Inline function implementations: class Ellipse_t
01781 //===
01782 //==================================================================================================
01783 //==================================================================================================
01784 inline
01785 Ellipse_t::Ellipse_t()
01786 {
01787     m_half_width = 0;
01788     m_half_height = 0;
01789     m_rotation = 0;
01790     m_rotated = false;
01791     m_rotated_90_degree_increments = false;
01792     m_sin_rotation = 0;
01793     m_cos_rotation = 1;
01794 }
01795 
01796 
01797 inline Point_t
01798 Ellipse_t::Center() const
01799 {
01800     return m_center;
01801 }
01802 
01803 
01804 inline void
01805 Ellipse_t::GetCenter(out Point_t* center) const
01806 {
01807     *center = m_center;
01808 }
01809 
01810 
01811 inline float
01812 Ellipse_t::Width() const
01813 {
01814     return m_half_width * 2;
01815 }
01816 
01817 
01818 inline float
01819 Ellipse_t::Height() const
01820 {
01821     return m_half_height * 2;
01822 }
01823 
01824 
01825 inline double
01826 Ellipse_t::Rotation() const
01827 {
01828     return m_rotation;
01829 }
01830 
01831 
01832 inline Ellipse_t
01833 Ellipse_t::operator +(const Point_t& add) const
01834 {
01835     return Ellipse_t( m_center+add, m_half_width*2, m_half_height*2, m_rotation );
01836 }
01837 
01838 
01839 inline Ellipse_t
01840 Ellipse_t::operator -(const Point_t& subtract) const
01841 {
01842     return Ellipse_t( m_center-subtract, m_half_width*2, m_half_height*2, m_rotation );
01843 }
01844 
01845 
01846 inline const Ellipse_t&
01847 Ellipse_t::operator +=(const Point_t& add)
01848 {
01849     m_center += add;
01850     return *this;
01851 }
01852 
01853 
01854 inline const Ellipse_t&
01855 Ellipse_t::operator -=(const Point_t& subtract)
01856 {
01857     m_center -= subtract;
01858     return *this;
01859 }
01860 
01861 
01862 inline Rect_t
01863 Ellipse_t::BoundingBox() const
01864 {
01865     Rect_t temp;
01866     GetBoundingBox(&temp);
01867     return temp;
01868 }
01869 
01870 
01871 #endif // __cplusplus
01872 #endif // _UT_GEOMETRY_H_

Generated on Tue Dec 14 22:35:05 2010 for UT library by  doxygen 1.6.1