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
20 #include "EdgeArcCircle.hxx"
23 using namespace INTERP_KERNEL;
25 Node::Node(double x, double y):_cnt(1),_loc(UNKNOWN)
27 _coords[0]=x; _coords[1]=y;
30 Node::Node(const double *coords):_cnt(1),_loc(UNKNOWN)
36 Node::Node(std::istream& stream):_cnt(1),_loc(UNKNOWN)
40 _coords[0]=((double) tmp)/1e4;
42 _coords[1]=((double) tmp)/1e4;
57 bool Node::isEqual(const Node& other) const
59 const unsigned SPACEDIM=2;
61 for(unsigned i=0;i<SPACEDIM;i++)
62 ret&=areDoubleEquals((*this)[i],other[i]);
66 double Node::getSlope(const Node& other) const
68 return computeSlope(*this, other);
72 * Convenient method. Equivalent to isEqual method. In case of true is returned, '&other' is
73 * added in 'track' container.
75 bool Node::isEqualAndKeepTrack(const Node& other, std::vector<Node *>& track) const
77 bool ret=isEqual(other);
79 track.push_back((Node *)&other);
83 void Node::dumpInXfigFile(std::ostream& stream, int resolution, const Bounds& box) const
85 stream << box.fitXForXFig(_coords[0],resolution) << " " << box.fitYForXFig(_coords[1],resolution) << " ";
88 double Node::distanceWithSq(const Node& other) const
90 return (_coords[0]-other._coords[0])*(_coords[0]-other._coords[0])+(_coords[1]-other._coords[1])*(_coords[1]-other._coords[1]);
94 * WARNING different from 'computeAngle' method ! The returned value are not in the same interval !
95 * Here in -Pi/2; Pi/2. Typically this method returns the same value by exchanging pt1 and pt2.
96 * Use in process of detection of a point in or not in polygon.
98 double Node::computeSlope(const double *pt1, const double *pt2)
100 double x=pt2[0]-pt1[0];
101 double y=pt2[1]-pt1[1];
102 double norm=sqrt(x*x+y*y);
103 double ret=EdgeArcCircle::safeAcos(fabs(x)/norm);
104 if( (x>=0. && y>=0.) || (x<0. && y<0.) )
111 * WARNING different from 'computeSlope' method. Here angle in -Pi;Pi is returned.
112 * This method is anti-symetric.
114 double Node::computeAngle(const double *pt1, const double *pt2)
116 double x=pt2[0]-pt1[0];
117 double y=pt2[1]-pt1[1];
118 double norm=sqrt(x*x+y*y);
119 return EdgeArcCircle::getAbsoluteAngleOfNormalizedVect(x/norm,y/norm);
123 * apply a Similarity transformation on this.
124 * @param xBary is the opposite of the X translation to do.
125 * @param yBary is the opposite of the Y translation to do.
126 * @param dimChar is the reduction factor.
128 void Node::applySimilarity(double xBary, double yBary, double dimChar)
130 _coords[0]=(_coords[0]-xBary)/dimChar;
131 _coords[1]=(_coords[1]-yBary)/dimChar;