1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 #include <Aspect_RectangularGrid.hxx>
16 #include <Standard_NegativeValue.hxx>
17 #include <Standard_NullValue.hxx>
18 #include <Standard_NumericError.hxx>
20 IMPLEMENT_STANDARD_RTTIEXT(Aspect_RectangularGrid,Aspect_Grid)
22 Aspect_RectangularGrid::Aspect_RectangularGrid(
23 const Standard_Real aXStep,
24 const Standard_Real aYStep,
25 const Standard_Real anXOrigin,
26 const Standard_Real anYOrigin,
27 const Standard_Real aFirstAngle,
28 const Standard_Real aSecondAngle,
29 const Standard_Real aRotationAngle)
30 :Aspect_Grid(anXOrigin,anYOrigin,aRotationAngle),myXStep(aXStep),myYStep(aYStep),myFirstAngle(aFirstAngle),mySecondAngle(aSecondAngle)
33 Standard_NumericError_Raise_if(!CheckAngle (aFirstAngle,mySecondAngle),
34 "networks are parallel");
36 Standard_NegativeValue_Raise_if(aXStep < 0. , "invalid x step");
37 Standard_NegativeValue_Raise_if(aYStep < 0. , "invalid y step");
38 Standard_NullValue_Raise_if(aXStep == 0. , "invalid x step");
39 Standard_NullValue_Raise_if(aYStep == 0. , "invalid y step");
44 void Aspect_RectangularGrid::SetXStep(const Standard_Real aStep) {
45 Standard_NegativeValue_Raise_if(aStep < 0. , "invalid x step");
46 Standard_NullValue_Raise_if(aStep == 0. , "invalid y step");
52 void Aspect_RectangularGrid::SetYStep(const Standard_Real aStep) {
53 Standard_NegativeValue_Raise_if(aStep < 0. , "invalid x step");
54 Standard_NullValue_Raise_if(aStep == 0. , "invalid y step");
60 void Aspect_RectangularGrid::SetAngle (const Standard_Real anAngle1,
61 const Standard_Real anAngle2)
63 Standard_NumericError_Raise_if(!CheckAngle (anAngle1,anAngle2 ),
65 myFirstAngle = anAngle1;
66 mySecondAngle = anAngle2;
71 void Aspect_RectangularGrid::SetGridValues(
72 const Standard_Real theXOrigin,
73 const Standard_Real theYOrigin,
74 const Standard_Real theXStep,
75 const Standard_Real theYStep,
76 const Standard_Real theRotationAngle) {
78 myXOrigin = theXOrigin;
79 myYOrigin = theYOrigin;
80 Standard_NegativeValue_Raise_if(theXStep < 0. , "invalid x step");
81 Standard_NullValue_Raise_if(theXStep == 0. , "invalid x step");
83 Standard_NegativeValue_Raise_if(theYStep < 0. , "invalid y step");
84 Standard_NullValue_Raise_if(theYStep == 0. , "invalid y step");
86 myRotationAngle = theRotationAngle;
91 void Aspect_RectangularGrid::Compute(const Standard_Real X,
92 const Standard_Real Y,
94 Standard_Real& gridY) const {
95 Standard_Real D1 = b1 * X - a1 * Y - c1;
96 Standard_Real D2 = b2 * X - a2 * Y - c2;
97 Standard_Integer n1 = Standard_Integer ( Abs(D1)/myXStep + 0.5);
98 Standard_Integer n2 = Standard_Integer ( Abs(D2)/myYStep + 0.5);
99 Standard_Real offset1 = c1 + Standard_Real(n1) * Sign (myXStep , D1);
100 Standard_Real offset2 = c2 + Standard_Real(n2) * Sign (myYStep , D2);
101 Standard_Real Delta = a1*b2 - b1*a2;
102 gridX = ( offset2*a1 - offset1*a2) /Delta;
103 gridY = ( offset2*b1 - offset1*b2) /Delta;
106 Standard_Real Aspect_RectangularGrid::XStep() const {
110 Standard_Real Aspect_RectangularGrid::YStep() const {
114 Standard_Real Aspect_RectangularGrid::FirstAngle() const {
118 Standard_Real 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() + M_PI / 2.);
130 // b2 = Sin (mySecondAngle + RotationAngle() + M_PI / 2.);
131 // c2 = XOrigin() * b2 - YOrigin() * a2;
133 Standard_Real angle1 = myFirstAngle + RotationAngle();
134 Standard_Real angle2 = mySecondAngle + RotationAngle();
135 if ( angle1 != 0. ) {
138 c1 = XOrigin() * b1 - YOrigin() * a1;
140 a1 = 0.; b1 = 1.; c1 = XOrigin();
143 if ( angle2 != 0. ) {
147 c2 = XOrigin() * b2 - YOrigin() * a2;
149 a2 = -1.; b2 = 0.; c2 = YOrigin();
154 Standard_Boolean Aspect_RectangularGrid::CheckAngle(const Standard_Real alpha,
155 const Standard_Real beta) const {
156 return (Abs( Sin(alpha) * Cos(beta + M_PI / 2.) - Cos(alpha) * Sin(beta + M_PI / 2.)) != 0) ;