BWAPI
SPAR/AIModule/BWTA/vendors/CGAL/CGAL/Iso_rectangle_2_Iso_rectangle_2_intersection.h
Go to the documentation of this file.
00001 // Copyright (c) 2000  Utrecht University (The Netherlands),
00002 // ETH Zurich (Switzerland), Freie Universitaet Berlin (Germany),
00003 // INRIA Sophia-Antipolis (France), Martin-Luther-University Halle-Wittenberg
00004 // (Germany), Max-Planck-Institute Saarbruecken (Germany), RISC Linz (Austria),
00005 // and Tel-Aviv University (Israel).  All rights reserved.
00006 //
00007 // This file is part of CGAL (www.cgal.org); you can redistribute it and/or
00008 // modify it under the terms of the GNU Lesser General Public License as
00009 // published by the Free Software Foundation; version 2.1 of the License.
00010 // See the file LICENSE.LGPL distributed with CGAL.
00011 //
00012 // Licensees holding a valid commercial license may use this file in
00013 // accordance with the commercial license agreement provided with the software.
00014 //
00015 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00016 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00017 //
00018 // $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/CGAL-3.5-branch/Intersections_2/include/CGAL/Iso_rectangle_2_Iso_rectangle_2_intersection.h $
00019 // $Id: Iso_rectangle_2_Iso_rectangle_2_intersection.h 39776 2007-08-08 15:15:20Z spion $
00020 // 
00021 //
00022 // Author(s)     : Geert-Jan Giezeman
00023 
00024 
00025 #ifndef CGAL_ISO_RECTANGLE_2_ISO_RECTANGLE_2_INTERSECTION_H
00026 #define CGAL_ISO_RECTANGLE_2_ISO_RECTANGLE_2_INTERSECTION_H
00027 
00028 #include <CGAL/Iso_rectangle_2.h>
00029 #include <CGAL/Object.h>
00030 
00031 CGAL_BEGIN_NAMESPACE
00032 
00033 namespace CGALi {
00034 
00035 template <class K>
00036 Object
00037 intersection(
00038     const typename K::Iso_rectangle_2 &irect1,
00039     const typename K::Iso_rectangle_2 &irect2,
00040     const K&)
00041 {
00042     typedef typename K::FT  FT;
00043     Rational_traits<FT>  rt;
00044     typename K::Construct_point_2 construct_point_2;
00045     typename K::Construct_object_2 construct_object;
00046     typename K::Construct_iso_rectangle_2 construct_iso_rectangle_2;
00047     const typename K::Point_2 &min1 = (irect1.min)();
00048     const typename K::Point_2 &min2 = (irect2.min)();
00049     const typename K::Point_2 &max1 = (irect1.max)();
00050     const typename K::Point_2 &max2 = (irect2.max)();
00051     typename K::FT minx, miny, maxx, maxy;
00052     typename K::Point_2 newmin;
00053     typename K::Point_2 newmax;
00054     minx = (min1.x() >= min2.x()) ? min1.x() : min2.x();
00055     maxx = (max1.x() <= max2.x()) ? max1.x() : max2.x();
00056     if (maxx < minx)
00057         return Object();
00058     miny = (min1.y() >= min2.y()) ? min1.y() : min2.y();
00059     maxy = (max1.y() <= max2.y()) ? max1.y() : max2.y();
00060     if (maxy < miny)
00061         return Object();
00062     if (rt.denominator(minx) == rt.denominator(miny)) {
00063         newmin = construct_point_2(rt.numerator(minx), rt.numerator(miny),
00064                                    rt.denominator(minx));
00065     } else {
00066         newmin = construct_point_2(rt.numerator(minx)   * rt.denominator(miny),
00067                                    rt.numerator(miny)   * rt.denominator(minx),
00068                                    rt.denominator(minx) * rt.denominator(miny));
00069     }
00070     if (rt.denominator(maxx) == rt.denominator(maxy)) {
00071         newmax = construct_point_2(rt.numerator(maxx), rt.numerator(maxy),
00072                                    rt.denominator(maxx));
00073     } else {
00074         newmax = construct_point_2(rt.numerator(maxx)   * rt.denominator(maxy),
00075                                    rt.numerator(maxy)   * rt.denominator(maxx),
00076                                    rt.denominator(maxx) * rt.denominator(maxy));
00077     }
00078     return construct_object(construct_iso_rectangle_2(newmin, newmax));
00079 }
00080 
00081 
00082 } // namespace CGALi
00083 
00084 
00085 template <class K>
00086 inline
00087 Object
00088 intersection(const Iso_rectangle_2<K> &irect1,
00089              const Iso_rectangle_2<K> &irect2)
00090 {
00091   typedef typename K::Intersect_2 Intersect;
00092   return Intersect()(irect1, irect2);
00093 }
00094 
00095 
00096 template <class K>
00097 inline bool
00098 do_intersect(const Iso_rectangle_2<K> &irect1,
00099              const Iso_rectangle_2<K> &irect2)
00100 {
00101     return ! intersection(irect1, irect2).is_empty();
00102 }
00103 
00104 CGAL_END_NAMESPACE
00105 
00106 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines