1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #ifndef __EDGEARCCIRCLE_HXX__
20 #define __EDGEARCCIRCLE_HXX__
24 namespace INTERP_KERNEL
26 class ArcCArcCIntersector : public SameTypeEdgeIntersector
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;
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);
39 const EdgeArcCircle& getE1() const { return (const EdgeArcCircle&)_e1; }
40 const EdgeArcCircle& getE2() const { return (const EdgeArcCircle&)_e2; }
45 class ArcCSegIntersector : public CrossTypeEdgeIntersector
48 ArcCSegIntersector(const EdgeArcCircle& e1, const EdgeLin& e2, bool reverse=true);
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;
54 const EdgeArcCircle& getE1() const { return (const EdgeArcCircle&)_e1; }
55 const EdgeLin& getE2() const { return (const EdgeLin&)_e2; }
64 class EdgeArcCircle : public Edge
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);
72 void changeMiddle(Node *newMiddle);
73 void dumpInXfigFile(std::ostream& stream, bool direction, int resolution, const Bounds& box) const;
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; }
111 Edge *buildEdgeLyingOnMe(Node *start, Node *end, bool direction=true) const;
113 //!Value between -2Pi and 2Pi
115 //!Value between -Pi and Pi