0022792: Globally defined symbol PI conflicts with VTK definition (Intel compiler)
[occt.git] / src / Graphic2d / Graphic2d_Line.cxx
CommitLineData
7fd59977 1// Modified 23/02/98 : FMN ; Remplacement PI par Standard_PI
2
3// 10/11/98 : GG ; Protection sur methode IsOn() lorsque
4// les points sont confondus.
5
6#define G002 //GG_100500
7// Change IsOn method with a best computation on short segments.
8//
9
10#include <Graphic2d_Line.ixx>
11
12Graphic2d_Line::Graphic2d_Line (const Handle(Graphic2d_GraphicObject)& aGraphicObject)
13 :Graphic2d_Primitive (aGraphicObject),
14 myTypeOfPolygonFilling (Graphic2d_TOPF_EMPTY),
15 myDrawEdge (Standard_True),
16 myWidthIndex (0),
17 myTypeIndex (0),
18 myPatternIndex (0),
19 myInteriorColorIndex (1) {
20
21 SetFamily(Graphic2d_TOP_LINE);
22}
23
24void Graphic2d_Line::SetWidthIndex (const Standard_Integer anIndex) {
25
26 myWidthIndex = anIndex;
27 ResetIndex ();
28
29}
30
31void Graphic2d_Line::SetTypeIndex (const Standard_Integer anIndex) {
32
33 myTypeIndex = anIndex;
34 ResetIndex ();
35
36}
37
38void Graphic2d_Line::SetInteriorColorIndex (const Standard_Integer anIndex) {
39
40 myInteriorColorIndex = anIndex;
41 ResetIndex ();
42
43}
44
45void Graphic2d_Line::SetDrawEdge (const Standard_Boolean aDraw) {
46
47 myDrawEdge = aDraw;
48 ResetIndex ();
49
50}
51
52void Graphic2d_Line::SetInteriorPattern (const Standard_Integer anIndex) {
53
54 myPatternIndex = anIndex;
55 ResetIndex ();
56
57}
58
59void Graphic2d_Line::SetTypeOfPolygonFilling (const Graphic2d_TypeOfPolygonFilling aType) {
60
61 myTypeOfPolygonFilling = aType;
62 ResetIndex ();
63
64}
65
66Standard_Integer Graphic2d_Line::WidthIndex () const {
67
68 return myWidthIndex;
69
70}
71
72Standard_Integer Graphic2d_Line::InteriorColorIndex () const {
73
74 return myInteriorColorIndex;
75
76}
77
78Standard_Integer Graphic2d_Line::InteriorPattern () const {
79
80 return myPatternIndex;
81
82}
83
84Graphic2d_TypeOfPolygonFilling Graphic2d_Line::TypeOfPolygonFilling () const {
85
86 return myTypeOfPolygonFilling;
87
88}
89
90Standard_Integer Graphic2d_Line::TypeIndex () const {
91
92 return myTypeIndex;
93
94}
95
96void Graphic2d_Line::DrawLineAttrib (const Handle(Graphic2d_Drawer)& aDrawer)
97 const {
98
99 aDrawer->SetLineAttrib (myColorIndex,myTypeIndex,myWidthIndex);
100
101 switch (myTypeOfPolygonFilling) {
102 case Graphic2d_TOPF_FILLED:
103 aDrawer->SetPolyAttrib (myInteriorColorIndex,0,myDrawEdge);
104 break;
105 case Graphic2d_TOPF_PATTERNED:
106 aDrawer->SetPolyAttrib (myInteriorColorIndex,
107 myPatternIndex,myDrawEdge);
108 break;
109 default: break;
110 }
111
112}
113
114void Graphic2d_Line::DrawMarkerAttrib (const Handle(Graphic2d_Drawer)& aDrawer)
115 const {
116
117Standard_Boolean filled = (myTypeOfPolygonFilling != Graphic2d_TOPF_EMPTY);
118
119 switch (myTypeOfPolygonFilling) {
120 case Graphic2d_TOPF_FILLED:
121 aDrawer->SetPolyAttrib (myInteriorColorIndex,0,Standard_False);
122 break;
123 case Graphic2d_TOPF_PATTERNED:
124 aDrawer->SetPolyAttrib (myInteriorColorIndex,myPatternIndex,Standard_False);
125 break;
126 default: break;
127 }
128
129 aDrawer->SetMarkerAttrib (myColorIndex,myWidthIndex,filled);
130
131}
132
133Standard_Boolean Graphic2d_Line::IsIn ( const Standard_ShortReal aX,
134 const Standard_ShortReal aY,
135 const TShort_Array1OfShortReal& X,
136 const TShort_Array1OfShortReal& Y,
137 const Standard_ShortReal aPrecision)
138{
139 Standard_Integer i1=0,i2=0,n;
140 Standard_Real dx1,dy1,dx2,dy2,anglesum=0.,angle;
141 Standard_Real prosca,provec,norme1,norme2,cosin;
142 n = X.Length ();
143 for (Standard_Integer m = 1; m <= n; m++) {
144 i1++;
145 i2 = (i1 == n) ? 1 : i1 + 1;
146 dx1 = X(i1) - aX; dy1 = Y(i1) - aY;
147 dx2 = X(i2) - aX; dy2 = Y(i2) - aY;
148 prosca = dx1 * dx2 + dy1 * dy2;
149 provec = dx1 * dy2 - dx2 * dy1;
150 norme1 = Sqrt ( dx1 * dx1 + dy1 * dy1 );
151 norme2 = Sqrt ( dx2 * dx2 + dy2 * dy2 );
152 if ( norme1 <= aPrecision || norme2 <= aPrecision ) return Standard_True;
153
154 cosin = prosca / norme1 / norme2;
155 if ( cosin >= 1 ) angle = 0.;
156 else {
c6541a0c 157 if ( cosin <= -1) angle = - M_PI;
7fd59977 158 else
159 angle = Sign ( ACos ( cosin ) , provec );
160 }
161 anglesum = anglesum + angle;}
162 return (Abs (anglesum) > 1.) ;
163}
164
165Standard_Boolean Graphic2d_Line::IsOn ( const Standard_ShortReal aX,
166 const Standard_ShortReal aY,
167 const Standard_ShortReal aX1,
168 const Standard_ShortReal aY1,
169 const Standard_ShortReal aX2,
170 const Standard_ShortReal aY2,
171 const Standard_ShortReal aPrecision)
172{
173
174Standard_ShortReal DX = aX2 - aX1, DY = aY2 - aY1, dd = DX*DX + DY*DY;
175
176
177#ifdef G002
178 if( Sqrt(dd) < aPrecision )
179#else
180 if( dd < aPrecision )
181#endif
182 return (Abs (aX - aX1) + Abs (aY - aY1)) < aPrecision;
183
184Standard_ShortReal lambda = (DX*(aX-aX1) + DY*(aY-aY1)) / dd;
185
186 if ( lambda >= 0. && lambda <= 1. ) {
187
188 // On prend comme norme la somme des valeurs absolues:
189 Standard_ShortReal Xproj = aX1 + lambda * DX;
190 Standard_ShortReal Yproj = aY1 + lambda * DY;
191 return (Abs (aX - Xproj) + Abs (aY - Yproj)) < aPrecision;
192
193 }
194 else
195 return Standard_False;
196}
197
198void Graphic2d_Line::Save(Aspect_FStream& aFStream) const
199{
200 *aFStream << myColorIndex << ' ' << myWidthIndex << endl;
201 *aFStream << myTypeIndex << ' ' << myPatternIndex << endl;
202 *aFStream << myInteriorColorIndex << ' ' << myTypeOfPolygonFilling << ' ' << myDrawEdge << endl;
203}
204
205void Graphic2d_Line::Retrieve(Aspect_IFStream& anIFStream)
206{
207 int topf;
208 *anIFStream >> myColorIndex >> myWidthIndex;
209 *anIFStream >> myTypeIndex >> myPatternIndex;
210 *anIFStream >> myInteriorColorIndex;
211 *anIFStream >> topf;
212 myTypeOfPolygonFilling=Graphic2d_TypeOfPolygonFilling(topf);
213 *anIFStream >> myDrawEdge;
214}
215