]> SALOME platform Git repositories - tools/medcoupling.git/blob - src/INTERP_KERNEL/Geometric2D/EdgeArcCircle.hxx
Salome HOME
Merge from BR_V5_DEV 16Feb09
[tools/medcoupling.git] / src / INTERP_KERNEL / Geometric2D / EdgeArcCircle.hxx
1 //  Copyright (C) 2007-2008  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 #ifndef __EDGEARCCIRCLE_HXX__
20 #define __EDGEARCCIRCLE_HXX__
21
22 #include "Edge.hxx"
23
24 namespace INTERP_KERNEL
25 {
26   class ArcCArcCIntersector : public SameTypeEdgeIntersector
27   {
28   public:
29     ArcCArcCIntersector(const EdgeArcCircle& e1, const EdgeArcCircle& e2);
30     bool haveTheySameDirection() const;
31     void getPlacements(Node *start, Node *end, TypeOfLocInEdge& whereStart, TypeOfLocInEdge& whereEnd, MergePoints& commonNode) const;
32     void areOverlappedOrOnlyColinears(const Bounds *whereToFind, bool& obviousNoIntersection, bool& areOverlapped);
33     std::list< IntersectElement > getIntersectionsCharacteristicVal() const;
34   private:
35     //! return angle in ]-Pi;Pi[ - 'node' must be on curve of '_e1'
36     double getAngle(Node *node) const;
37     static bool areArcsOverlapped(const EdgeArcCircle& a1, const EdgeArcCircle& a2);
38   private:
39     const EdgeArcCircle& getE1() const { return (const EdgeArcCircle&)_e1; }
40     const EdgeArcCircle& getE2() const { return (const EdgeArcCircle&)_e2; }
41   private:
42     double _dist;
43   };
44
45   class ArcCSegIntersector : public CrossTypeEdgeIntersector
46   {
47   public:
48     ArcCSegIntersector(const EdgeArcCircle& e1, const EdgeLin& e2, bool reverse=true);
49     //virtual overloading
50     void getPlacements(Node *start, Node *end, TypeOfLocInEdge& whereStart, TypeOfLocInEdge& whereEnd, MergePoints& commonNode) const;
51     void areOverlappedOrOnlyColinears(const Bounds *whereToFind, bool& obviousNoIntersection, bool& areOverlapped);
52     std::list< IntersectElement > getIntersectionsCharacteristicVal() const;
53   private:
54     const EdgeArcCircle& getE1() const { return (const EdgeArcCircle&)_e1; }
55     const EdgeLin& getE2() const { return (const EdgeLin&)_e2; }
56   private:
57     double _dx;
58     double _dy;
59     double _drSq;
60     double _cross;
61     double _determinant;
62   };
63   
64   class EdgeArcCircle : public Edge
65   {
66   public:
67     EdgeArcCircle(std::istream& lineInXfig);
68     EdgeArcCircle(Node *start, Node *middle, Node *end, bool direction = true);
69     EdgeArcCircle(double sX, double sY, double mX, double mY, double eX, double eY);
70     EdgeArcCircle(Node *start, Node *end, const double *center, double radius, double angle0, double deltaAngle, bool direction=true);
71     //! for tests
72     void changeMiddle(Node *newMiddle);
73     void dumpInXfigFile(std::ostream& stream, bool direction, int resolution, const Bounds& box) const;
74     void update(Node *m);
75     double getAreaOfZone() const;
76     double getCurveLength() const;
77     void getBarycenter(double *bary) const;
78     void getBarycenterOfZone(double *bary) const;
79     bool isIn(double characterVal) const;
80     Node *buildRepresentantOfMySelf() const;
81     bool isLower(double val1, double val2) const;
82     double getCharactValue(const Node& node) const;
83     double getDistanceToPoint(const double *pt) const;
84     bool isNodeLyingOn(const double *coordOfNode) const;
85     TypeOfFunction getTypeOfFunc() const { return ARC_CIRCLE; }
86     void dynCastFunction(const EdgeLin * &seg,
87                          const EdgeArcCircle * &arcSeg) const { arcSeg=this; }
88     const double *getCenter() const { return _center; }
89     void getCenter(double *center) const { center[0]=_center[0]; center[1]=_center[1]; }
90     bool doIHaveSameDirectionAs(const Edge& other) const { return false; }
91     void applySimilarity(double xBary, double yBary, double dimChar);
92     double getAngle0() const { return _angle0; }
93     double getRadius() const { return _radius; }
94     double getAngle() const { return _angle; }
95     static double getAbsoluteAngle(const double *vect, double& normVect);
96     static double getAbsoluteAngleOfNormalizedVect(double ux, double uy);
97     static void getArcOfCirclePassingThru(const double *start, const double *middle, const double *end, 
98                                           double *center, double& radius, double& angleInRad, double& angleInRad0);
99     //! To avoid in aggressive optimizations nan.
100     static double safeSqrt(double val) { double ret=std::max(val,0.); return sqrt(ret); }
101     static double safeAcos(double cosAngle) { double ret=std::min(cosAngle,1.); ret=std::max(ret,-1.); return acos(ret); }
102     static double safeAsin(double sinAngle) { double ret=std::min(sinAngle,1.); ret=std::max(ret,-1.); return asin(ret); }
103     //! @param start and @param angleIn in ]-Pi;Pi] and @param delta in ]-2*Pi,2*Pi[
104     static bool isIn2Pi(double start, double delta, double angleIn);
105     //! 'delta' 'start' in ]-Pi;Pi[
106     static bool isAngleNotIn(double start, double delta, double angleIn);
107     //! for an angle 'angle' in ]-3*Pi;3*Pi[ returns angle in ]-Pi;Pi[
108     static double normalizeAngle(double angle) { if(angle>M_PI) return angle-2.*M_PI; if(angle<-M_PI) return angle+2.*M_PI; return angle; }
109   protected:
110     void updateBounds();
111     Edge *buildEdgeLyingOnMe(Node *start, Node *end, bool direction=true) const;
112   protected:
113     //!Value between -2Pi and 2Pi
114     double _angle;
115     //!Value between -Pi and Pi
116     double _angle0;
117     double _radius;
118     double _center[2];
119   };
120 }
121
122 #endif