1 // Copyright (C) 2007-2022 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, or (at your option) any later version.
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 // Author : Anthony Geay (CEA/DEN)
21 #ifndef __INTERPKERNELGEO2DEDGEARCCIRCLE_HXX__
22 #define __INTERPKERNELGEO2DEDGEARCCIRCLE_HXX__
24 #include "INTERPKERNELDefines.hxx"
25 #include "InterpKernelGeo2DEdge.hxx"
26 #include "MCIdType.hxx"
28 namespace INTERP_KERNEL
30 class INTERPKERNEL_EXPORT ArcCArcCIntersector : public SameTypeEdgeIntersector
33 ArcCArcCIntersector(const EdgeArcCircle& e1, const EdgeArcCircle& e2);
34 bool haveTheySameDirection() const;
35 bool areColinears() const;
36 void getPlacements(Node *start, Node *end, TypeOfLocInEdge& whereStart, TypeOfLocInEdge& whereEnd, MergePoints& commonNode) const;
37 void areOverlappedOrOnlyColinears(bool& obviousNoIntersection, bool& areOverlapped);
38 std::list< IntersectElement > getIntersectionsCharacteristicVal() const;
40 //! return angle in ]-Pi;Pi[ - 'node' must be on curve of '_e1'
41 double getAngle(Node *node) const;
42 static bool internalAreColinears(const EdgeArcCircle& a1, const EdgeArcCircle& a2, double& distBetweenCenters, double& cst, double& radiusL, double centerL[2], double& raduisB, double centerB[2]);
43 static bool areArcsOverlapped(const EdgeArcCircle& a1, const EdgeArcCircle& a2);
45 const EdgeArcCircle& getE1() const { return (const EdgeArcCircle&)_e1; }
46 const EdgeArcCircle& getE2() const { return (const EdgeArcCircle&)_e2; }
48 double _dist; // distance between the two arc centers
52 * Cross-type intersector: edge1 is the arc of circle, edge2 is the segment.
54 class INTERPKERNEL_EXPORT ArcCSegIntersector : public CrossTypeEdgeIntersector
57 ArcCSegIntersector(const EdgeArcCircle& e1, const EdgeLin& e2, bool reverse=true);
59 bool areColinears() const;
60 void getPlacements(Node *start, Node *end, TypeOfLocInEdge& whereStart, TypeOfLocInEdge& whereEnd, MergePoints& commonNode) const;
61 void areOverlappedOrOnlyColinears(bool& obviousNoIntersection, bool& areOverlapped);
62 std::list< IntersectElement > getIntersectionsCharacteristicVal() const;
64 const EdgeArcCircle& getE1() const { return (const EdgeArcCircle&)_e1; }
65 const EdgeLin& getE2() const { return (const EdgeLin&)_e2; }
67 double _dx; //!< X extent of the segment
68 double _dy; //!< Y extent of the segment
69 double _drSq; //!< Square of the norm of the seg
70 double _cross; //!< See areOverlappedOrOnlyColinears()
71 double _deltaRoot_div_dr; //!< See areOverlappedOrOnlyColinears()
75 class INTERPKERNEL_EXPORT EdgeArcCircle : public Edge
78 EdgeArcCircle(std::istream& lineInXfig);
79 EdgeArcCircle(Node *start, Node *middle, Node *end, bool direction = true);
80 EdgeArcCircle(double sX, double sY, double mX, double mY, double eX, double eY);
81 EdgeArcCircle(Node *start, Node *end, const double *center, double radius, double angle0, double deltaAngle, bool direction=true);
83 void changeMiddle(Node *newMiddle);
84 void dumpInXfigFile(std::ostream& stream, bool direction, int resolution, const Bounds& box) const;
86 double getAreaOfZone() const;
87 double getCurveLength() const;
88 void getBarycenter(double *bary) const;
89 void getBarycenterOfZone(double *bary) const;
90 void getMiddleOfPoints(const double *p1, const double *p2, double *mid) const;
91 void getMiddleOfPointsOriented(const double *p1, const double *p2, double *mid) const;
92 bool isIn(double characterVal) const;
93 Node *buildRepresentantOfMySelf() const;
94 bool isLower(double val1, double val2) const;
95 double getCharactValue(const Node& node) const;
96 double getCharactValueBtw0And1(const Node& node) const;
97 double getDistanceToPoint(const double *pt) const;
98 bool isNodeLyingOn(const double *coordOfNode) const;
99 TypeOfFunction getTypeOfFunc() const { return ARC_CIRCLE; }
100 void dynCastFunction(const EdgeLin * &seg,
101 const EdgeArcCircle * &arcSeg) const { arcSeg=this; }
102 const double *getCenter() const { return _center; }
103 void getCenter(double *center) const { center[0]=_center[0]; center[1]=_center[1]; }
104 bool doIHaveSameDirectionAs(const Edge& other) const { return false; }
105 void applySimilarity(double xBary, double yBary, double dimChar);
106 void unApplySimilarity(double xBary, double yBary, double dimChar);
107 double getAngle0() const { return _angle0; }
108 double getRadius() const { return _radius; }
109 double getAngle() const { return _angle; }
110 void tesselate(const mcIdType *conn, mcIdType offset, double eps, std::vector<mcIdType>& newConn, std::vector<double>& addCoo) const;
111 static EdgeArcCircle *BuildFromNodes(Node *start, Node *middle, Node *end);
112 static double GetAbsoluteAngle(const double *vect, double& normVect);
113 static double GetAbsoluteAngleOfNormalizedVect(double ux, double uy);
114 static void GetArcOfCirclePassingThru(const double *start, const double *middle, const double *end,
115 double *center, double& radius, double& angleInRad, double& angleInRad0);
116 //! To avoid in aggressive optimizations nan.
117 static double SafeSqrt(double val) { double ret=std::max(val,0.); return sqrt(ret); }
118 static double SafeAcos(double cosAngle) { double ret=std::min(cosAngle,1.); ret=std::max(ret,-1.); return acos(ret); }
119 static double SafeAsin(double sinAngle) { double ret=std::min(sinAngle,1.); ret=std::max(ret,-1.); return asin(ret); }
120 //! @param start and @param angleIn in ]-Pi;Pi] and @param delta in ]-2*Pi,2*Pi[
121 static bool IsIn2Pi(double start, double delta, double angleIn);
122 //! 'delta' 'start' in ]-Pi;Pi[
123 static bool IsAngleNotIn(double start, double delta, double angleIn);
124 //! for an angle 'angle' in ]-3*Pi;3*Pi[ returns angle in ]-Pi;Pi[
125 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; }
128 Edge *buildEdgeLyingOnMe(Node *start, Node *end, bool direction=true) const;
131 //! Absolute angle where the arc starts. Value between -Pi and Pi
133 //! Angular span of the arc. Value between -2Pi and 2Pi
135 //! Radius of the arc of circle
137 //! Center of the arc of circle