Salome HOME
Merge from V6_main_20120808 08Aug12
[tools/medcoupling.git] / src / INTERP_KERNEL / Geometric2D / InterpKernelGeo2DBounds.hxx
1 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #ifndef __INTERPKERNELGEO2DBOUNDS_HXX__
21 #define __INTERPKERNELGEO2DBOUNDS_HXX__
22
23 #include "INTERPKERNELDefines.hxx"
24
25 #include <algorithm>
26
27 namespace INTERP_KERNEL
28 {
29   /*!
30    * Relative LOC
31    */
32   typedef enum
33     {
34       IN              = 0,
35       OUT             = 1,
36       ON_BOUNDARY_POS = 2,
37       ON_BOUNDARY_NEG = 3
38     } Position;
39   
40   class INTERPKERNEL_EXPORT Bounds
41   {
42   public:
43     Bounds():_x_min(0.),_x_max(0.),_y_min(0.),_y_max(0.) { }
44     double &operator[](int i);
45     const double& operator[](int i) const;
46     double getDiagonal() const;
47     void getBarycenter(double& xBary, double& yBary) const;
48     void applySimilarity(double xBary, double yBary, double dimChar);
49     void unApplySimilarity(double xBary, double yBary, double dimChar);
50     Bounds& operator=(const Bounds& other) { _x_min=other._x_min; _x_max=other._x_max; _y_min=other._y_min; _y_max=other._y_max; return *this; }
51     Bounds(double xMin, double xMax, double yMin, double yMax):_x_min(xMin),_x_max(xMax),_y_min(yMin),_y_max(yMax) { }
52     void setValues(double xMin, double xMax, double yMin, double yMax) { _x_min=xMin; _x_max=xMax; _y_min=yMin; _y_max=yMax; }
53     void prepareForAggregation();
54     void getInterceptedArc(const double *center, double radius, double& intrcptArcAngle0, double& intrcptArcDelta) const;
55     int fitXForXFig(double val, int res) const { return (int)fitXForXFigD(val,res); }
56     int fitYForXFig(double val, int res) const { return (int)fitYForXFigD(val,res); }
57     double fitXForXFigD(double val, int res) const;
58     double fitYForXFigD(double val, int res) const;
59     Bounds *nearlyAmIIntersectingWith(const Bounds& other) const;
60     Bounds *amIIntersectingWith(const Bounds& other) const;
61     //! No approximations.
62     Position where(double x, double y) const;
63     //! Idem where method but with approximations.
64     Position nearlyWhere(double x, double y) const;
65     void aggregate(const Bounds& other);
66     double getCaracteristicDim() const { return std::max(_x_max-_x_min,_y_max-_y_min); }
67   protected:
68     double _x_min;
69     double _x_max;
70     double _y_min;
71     double _y_max;
72   };
73 }
74
75 #endif