1 // Modified 23/02/98 : FMN ; Remplacement PI par Standard_PI
3 #define CSR577 //GG 25/09/00 Avoid to have unaccuracy coordinates computation
4 // when the grid is activated.
8 #include <Aspect_RectangularGrid.ixx>
11 Aspect_RectangularGrid::Aspect_RectangularGrid(
12 const Quantity_Length aXStep,
13 const Quantity_Length aYStep,
14 const Quantity_Length anXOrigin,
15 const Quantity_Length anYOrigin,
16 const Quantity_PlaneAngle aFirstAngle,
17 const Quantity_PlaneAngle aSecondAngle,
18 const Quantity_PlaneAngle aRotationAngle)
19 :Aspect_Grid(anXOrigin,anYOrigin,aRotationAngle),myXStep(aXStep),myYStep(aYStep),myFirstAngle(aFirstAngle),mySecondAngle(aSecondAngle)
22 Standard_NumericError_Raise_if(!CheckAngle (aFirstAngle,mySecondAngle),
23 "networks are parallel");
25 Standard_NegativeValue_Raise_if(aXStep < 0. , "invalid x step");
26 Standard_NegativeValue_Raise_if(aYStep < 0. , "invalid y step");
27 Standard_NullValue_Raise_if(aXStep == 0. , "invalid x step");
28 Standard_NullValue_Raise_if(aYStep == 0. , "invalid y step");
33 void Aspect_RectangularGrid::SetXStep(const Quantity_Length aStep) {
34 Standard_NegativeValue_Raise_if(aStep < 0. , "invalid x step");
35 Standard_NullValue_Raise_if(aStep == 0. , "invalid y step");
41 void Aspect_RectangularGrid::SetYStep(const Quantity_Length aStep) {
42 Standard_NegativeValue_Raise_if(aStep < 0. , "invalid x step");
43 Standard_NullValue_Raise_if(aStep == 0. , "invalid y step");
49 void Aspect_RectangularGrid::SetAngle(const Quantity_PlaneAngle anAngle1,
50 const Quantity_PlaneAngle anAngle2){
52 Standard_NumericError_Raise_if(!CheckAngle (anAngle1,anAngle2 ),
54 myFirstAngle = anAngle1;
55 mySecondAngle = anAngle2;
60 void Aspect_RectangularGrid::SetGridValues(
61 const Quantity_Length theXOrigin,
62 const Quantity_Length theYOrigin,
63 const Quantity_Length theXStep,
64 const Quantity_Length theYStep,
65 const Quantity_PlaneAngle theRotationAngle) {
67 myXOrigin = theXOrigin;
68 myYOrigin = theYOrigin;
69 Standard_NegativeValue_Raise_if(theXStep < 0. , "invalid x step");
70 Standard_NullValue_Raise_if(theXStep == 0. , "invalid x step");
72 Standard_NegativeValue_Raise_if(theYStep < 0. , "invalid y step");
73 Standard_NullValue_Raise_if(theYStep == 0. , "invalid y step");
75 myRotationAngle = theRotationAngle;
80 void Aspect_RectangularGrid::Compute(const Quantity_Length X,
81 const Quantity_Length Y,
82 Quantity_Length& gridX,
83 Quantity_Length& gridY) const {
84 Standard_Real D1 = b1 * X - a1 * Y - c1;
85 Standard_Real D2 = b2 * X - a2 * Y - c2;
86 Standard_Integer n1 = Standard_Integer ( Abs(D1)/myXStep + 0.5);
87 Standard_Integer n2 = Standard_Integer ( Abs(D2)/myYStep + 0.5);
88 Standard_Real offset1 = c1 + Standard_Real(n1) * Sign (myXStep , D1);
89 Standard_Real offset2 = c2 + Standard_Real(n2) * Sign (myYStep , D2);
91 Standard_Real Delta = a1*b2 - b1*a2;
92 gridX = ( offset2*a1 - offset1*a2) /Delta;
93 gridY = ( offset2*b1 - offset1*b2) /Delta;
95 Standard_Real Delta = b1*a2 - a1*b2;
96 gridX = ( offset1*a2 - offset2*a1) /Delta;
97 gridY = ( offset1*b2 - offset2*b1) /Delta;
100 cout << "Aspect_RectangularGrid::Compute (" << Quantity_Length (X) << ", "
101 << Quantity_Length (Y) << ", " << Quantity_Length (gridX) << ", "
102 << Quantity_Length (gridY) << ")" << endl;
106 Quantity_Length Aspect_RectangularGrid::XStep() const {
110 Quantity_Length Aspect_RectangularGrid::YStep() const {
114 Quantity_Length Aspect_RectangularGrid::FirstAngle() const {
118 Quantity_Length Aspect_RectangularGrid::SecondAngle() const {
119 return mySecondAngle;
122 void Aspect_RectangularGrid::Init () {
124 //+zov Fixing CTS17856
125 // a1 = Cos (myFirstAngle + RotationAngle() );
126 // b1 = Sin (myFirstAngle + RotationAngle() );
127 // c1 = XOrigin() * b1 - YOrigin() * a1;
129 // a2 = Cos (mySecondAngle + RotationAngle() + Standard_PI/2.);
130 // b2 = Sin (mySecondAngle + RotationAngle() + Standard_PI/2.);
131 // c2 = XOrigin() * b2 - YOrigin() * a2;
134 Standard_Real angle1 = myFirstAngle + RotationAngle();
135 Standard_Real angle2 = mySecondAngle + RotationAngle();
136 if ( angle1 != 0. ) {
139 c1 = XOrigin() * b1 - YOrigin() * a1;
141 a1 = 0.; b1 = 1.; c1 = XOrigin();
144 if ( angle2 != 0. ) {
145 angle2 += Standard_PI/2.;
148 c2 = XOrigin() * b2 - YOrigin() * a2;
150 a2 = -1.; b2 = 0.; c2 = YOrigin();
153 a1 = -Sin (myFirstAngle + RotationAngle());
154 b1 = Cos (myFirstAngle + RotationAngle());
155 c1 = XOrigin() * b1 - YOrigin() * a1;
157 a2 = -Sin (mySecondAngle + RotationAngle() + Standard_PI/2.);
158 b2 = Cos (mySecondAngle + RotationAngle() + Standard_PI/2.);
159 c2 = XOrigin() * b2 - YOrigin() * a2;
164 Standard_Boolean Aspect_RectangularGrid::CheckAngle(const Standard_Real alpha,
165 const Standard_Real beta) const {
166 return Abs( Sin(alpha)*Cos(beta+Standard_PI/2.) - Cos(alpha)*Sin(beta+Standard_PI/2.) != 0) ;