Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

gugr_bool.h

Go to the documentation of this file.
00001 /* LIBGUL - Geometry Utility Library
00002  * Copyright (C) 1998-1999 Norbert Irmer
00003  *
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Library General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2 of the License, or (at your option) any later version.
00008  *
00009  * This library is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * Library General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Library General Public
00015  * License along with this library; if not, write to the
00016  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00017  * Boston, MA 02111-1307, USA.
00018  */
00019 
00020 #ifndef GUGR_BOOL_H
00021 #define GUGR_BOOL_H
00022 
00023 namespace gugr {
00024 
00025 /*---------------------------------------------------------------------
00026   calculates the intersection of two polygons
00027 ----------------------------------------------------------------------*/
00028 GULAPI void DoIntersection( 
00029         gul::List< gul::ListNode<gugr::polyline> >& PA, 
00030         gul::List< gul::ListNode<gugr::polyline> >& PB,
00031         const rational& far_x,
00032         const rational& far_y,
00033         gul::List<gul::ListNode<gul::polyline<gul::point2<rational> > > >& C );
00034 
00035 /*---------------------------------------------------------------------
00036   calculates the union of two polygons
00037 ----------------------------------------------------------------------*/
00038 GULAPI void DoUnion( 
00039           List< ListNode<polyline> >& PA, 
00040           List< ListNode<polyline> >& PB,
00041           const rational& far_x,
00042           const rational& far_y,
00043           List<ListNode<gul::polyline<point2<rational> > > >& C );
00044 
00045 /*---------------------------------------------------------------------
00046   calculates the difference of two polygons
00047 ----------------------------------------------------------------------*/
00048 GULAPI void DoDifference( 
00049           List< ListNode<polyline> >& PA, 
00050           List< ListNode<polyline> >& PB,
00051           const rational& far_x,
00052           const rational& far_y,
00053           List<ListNode<gul::polyline<point2<rational> > > >& C );
00054 
00055 /*---------------------------------------------------------------
00056   convert polylines with floating-point points into polylines with
00057   rational points
00058 ----------------------------------------------------------------*/  
00059 template< class T >
00060 GULAPI void ConvertToRationalPolys(  
00061       List< ListNode< gul::polyline<point2<T> > > >& A,
00062       List< ListNode< gul::polyline<point2<T> > > >& B,
00063       T *ret_minx,
00064       T *ret_miny,
00065       T *ret_scale,
00066       rational *ret_far_x,  // far away
00067       rational *ret_far_y,
00068       List< ListNode<gugr::polyline> >& PA,
00069       List< ListNode<gugr::polyline> >& PB );
00070 
00071 /*---------------------------------------------------------------
00072   convert a polyline with rational points into a polyline with
00073   floating-point points
00074 ----------------------------------------------------------------*/  
00075 template< class T >
00076 GULAPI void ConvertToFloatPoly(
00077       List< ListNode<gul::polyline<point2<rational> > > >& inA,
00078       T minx,
00079       T miny,
00080       T scale,
00081       List< ListNode<gul::polyline<point2<T> > > >& outA );
00082 
00083 /*---------------------------------------------------------------------
00084   calculates the intersection of two polygons (floating-point variant)
00085 ----------------------------------------------------------------------*/
00086 template< class T >
00087 inline void Intersection( 
00088         gul::List<gul::ListNode<gul::polyline<gul::point2<T> > > >& fPA, 
00089         gul::List<gul::ListNode<gul::polyline<gul::point2<T> > > >& fPB,
00090         gul::List<gul::ListNode<gul::polyline<gul::point2<T> > > >& fPC )
00091 {
00092   T minx,miny,scale;
00093   rational far_x,far_y;
00094   gul::List<gul::ListNode<gugr::polyline> > PA,PB;
00095   gul::List<gul::ListNode<gul::polyline<gul::point2<rational> > > > PC;
00096 
00097   ConvertToRationalPolys(fPA,fPB,&minx,&miny,&scale,&far_x,&far_y,PA,PB);
00098   DoIntersection(PA,PB,far_x,far_y,PC);
00099   ConvertToFloatPoly(PC,minx,miny,scale,fPC);
00100 }
00101 
00102 /*---------------------------------------------------------------------
00103   calculates the union of two polygons (floating-point variant)
00104 ----------------------------------------------------------------------*/
00105 template< class T >
00106 inline void Union( 
00107         gul::List<gul::ListNode<gul::polyline<gul::point2<T> > > >& fPA, 
00108         gul::List<gul::ListNode<gul::polyline<gul::point2<T> > > >& fPB,
00109         gul::List<gul::ListNode<gul::polyline<gul::point2<T> > > >& fPC )
00110 {
00111   T minx,miny,scale;
00112   rational far_x,far_y;
00113   gul::List<gul::ListNode<gugr::polyline> > PA,PB;
00114   gul::List<gul::ListNode<gul::polyline<gul::point2<rational> > > > PC;
00115 
00116   ConvertToRationalPolys(fPA,fPB,&minx,&miny,&scale,&far_x,&far_y,PA,PB);
00117   DoUnion(PA,PB,far_x,far_y,PC);
00118   ConvertToFloatPoly(PC,minx,miny,scale,fPC);
00119 }
00120 
00121 /*---------------------------------------------------------------------
00122   calculates the difference of two polygons (floating-point variant)
00123 ----------------------------------------------------------------------*/
00124 template< class T >
00125 inline void Difference( 
00126         gul::List<gul::ListNode<gul::polyline<gul::point2<T> > > >& fPA, 
00127         gul::List<gul::ListNode<gul::polyline<gul::point2<T> > > >& fPB,
00128         gul::List<gul::ListNode<gul::polyline<gul::point2<T> > > >& fPC )
00129 {
00130   T minx,miny,scale;
00131   rational far_x,far_y;
00132   gul::List<gul::ListNode<gugr::polyline> > PA,PB;
00133   gul::List<gul::ListNode<gul::polyline<gul::point2<rational> > > > PC;
00134 
00135   ConvertToRationalPolys(fPA,fPB,&minx,&miny,&scale,&far_x,&far_y,PA,PB);
00136   // DumpPS<T>::set_transformation(minx,miny,scale,scale);
00137   DoDifference(PA,PB,far_x,far_y,PC);
00138   ConvertToFloatPoly(PC,minx,miny,scale,fPC);
00139 }
00140 
00141 }
00142 
00143 #endif

Generated on Mon Jan 21 04:17:28 2002 for GUL 0.6 - Geometry Utility Library by doxygen1.2.13.1 written by Dimitri van Heesch, © 1997-2001