0028316: Coding Rules - Elimilate confusing aliases of Standard_Real type in V3d_View
[occt.git] / src / Aspect / Aspect_RectangularGrid.cxx
CommitLineData
973c2be1 1// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 2//
973c2be1 3// This file is part of Open CASCADE Technology software library.
b311480e 4//
d5f74e42 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
973c2be1 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.
b311480e 10//
973c2be1 11// Alternatively, this file may be used under the terms of Open CASCADE
12// commercial license or contractual agreement.
b311480e 13
7fd59977 14// Modified 23/02/98 : FMN ; Remplacement PI par Standard_PI
15
42cf5bc1 16#include <Aspect_RectangularGrid.hxx>
17#include <Standard_NegativeValue.hxx>
18#include <Standard_NullValue.hxx>
19#include <Standard_NumericError.hxx>
20#include <Standard_Type.hxx>
7fd59977 21
92efcf78 22IMPLEMENT_STANDARD_RTTIEXT(Aspect_RectangularGrid,Aspect_Grid)
23
7fd59977 24Aspect_RectangularGrid::Aspect_RectangularGrid(
ee2be2a8 25 const Standard_Real aXStep,
26 const Standard_Real aYStep,
27 const Standard_Real anXOrigin,
28 const Standard_Real anYOrigin,
29 const Standard_Real aFirstAngle,
30 const Standard_Real aSecondAngle,
31 const Standard_Real aRotationAngle)
7fd59977 32:Aspect_Grid(anXOrigin,anYOrigin,aRotationAngle),myXStep(aXStep),myYStep(aYStep),myFirstAngle(aFirstAngle),mySecondAngle(aSecondAngle)
33
34{
35 Standard_NumericError_Raise_if(!CheckAngle (aFirstAngle,mySecondAngle),
36 "networks are parallel");
37
38 Standard_NegativeValue_Raise_if(aXStep < 0. , "invalid x step");
39 Standard_NegativeValue_Raise_if(aYStep < 0. , "invalid y step");
40 Standard_NullValue_Raise_if(aXStep == 0. , "invalid x step");
41 Standard_NullValue_Raise_if(aYStep == 0. , "invalid y step");
42}
43
44
45
ee2be2a8 46void Aspect_RectangularGrid::SetXStep(const Standard_Real aStep) {
7fd59977 47 Standard_NegativeValue_Raise_if(aStep < 0. , "invalid x step");
48 Standard_NullValue_Raise_if(aStep == 0. , "invalid y step");
49 myXStep = aStep;
50 Init();
51 UpdateDisplay();
52}
53
ee2be2a8 54void Aspect_RectangularGrid::SetYStep(const Standard_Real aStep) {
7fd59977 55 Standard_NegativeValue_Raise_if(aStep < 0. , "invalid x step");
56 Standard_NullValue_Raise_if(aStep == 0. , "invalid y step");
57 myYStep = aStep;
58 Init();
59 UpdateDisplay();
60}
61
ee2be2a8 62void Aspect_RectangularGrid::SetAngle (const Standard_Real anAngle1,
63 const Standard_Real anAngle2)
64{
7fd59977 65 Standard_NumericError_Raise_if(!CheckAngle (anAngle1,anAngle2 ),
66 "axis are parallel");
67 myFirstAngle = anAngle1;
68 mySecondAngle = anAngle2;
69 Init();
70 UpdateDisplay();
71}
72
73void Aspect_RectangularGrid::SetGridValues(
ee2be2a8 74 const Standard_Real theXOrigin,
75 const Standard_Real theYOrigin,
76 const Standard_Real theXStep,
77 const Standard_Real theYStep,
78 const Standard_Real theRotationAngle) {
7fd59977 79
80 myXOrigin = theXOrigin;
81 myYOrigin = theYOrigin;
82 Standard_NegativeValue_Raise_if(theXStep < 0. , "invalid x step");
83 Standard_NullValue_Raise_if(theXStep == 0. , "invalid x step");
84 myXStep = theXStep;
85 Standard_NegativeValue_Raise_if(theYStep < 0. , "invalid y step");
86 Standard_NullValue_Raise_if(theYStep == 0. , "invalid y step");
87 myYStep = theYStep;
88 myRotationAngle = theRotationAngle;
89 Init();
90 UpdateDisplay();
91}
92
ee2be2a8 93void Aspect_RectangularGrid::Compute(const Standard_Real X,
94 const Standard_Real Y,
95 Standard_Real& gridX,
96 Standard_Real& gridY) const {
7fd59977 97 Standard_Real D1 = b1 * X - a1 * Y - c1;
98 Standard_Real D2 = b2 * X - a2 * Y - c2;
99 Standard_Integer n1 = Standard_Integer ( Abs(D1)/myXStep + 0.5);
100 Standard_Integer n2 = Standard_Integer ( Abs(D2)/myYStep + 0.5);
101 Standard_Real offset1 = c1 + Standard_Real(n1) * Sign (myXStep , D1);
102 Standard_Real offset2 = c2 + Standard_Real(n2) * Sign (myYStep , D2);
7fd59977 103 Standard_Real Delta = a1*b2 - b1*a2;
104 gridX = ( offset2*a1 - offset1*a2) /Delta;
105 gridY = ( offset2*b1 - offset1*b2) /Delta;
7fd59977 106}
107
ee2be2a8 108Standard_Real Aspect_RectangularGrid::XStep() const {
7fd59977 109 return myXStep;
110}
111
ee2be2a8 112Standard_Real Aspect_RectangularGrid::YStep() const {
7fd59977 113 return myYStep;
114}
115
ee2be2a8 116Standard_Real Aspect_RectangularGrid::FirstAngle() const {
7fd59977 117 return myFirstAngle;
118}
119
ee2be2a8 120Standard_Real Aspect_RectangularGrid::SecondAngle() const {
7fd59977 121 return mySecondAngle;
122}
123
124void Aspect_RectangularGrid::Init () {
125
126//+zov Fixing CTS17856
127// a1 = Cos (myFirstAngle + RotationAngle() );
128// b1 = Sin (myFirstAngle + RotationAngle() );
129// c1 = XOrigin() * b1 - YOrigin() * a1;
130//
c6541a0c
D
131// a2 = Cos (mySecondAngle + RotationAngle() + M_PI / 2.);
132// b2 = Sin (mySecondAngle + RotationAngle() + M_PI / 2.);
7fd59977 133// c2 = XOrigin() * b2 - YOrigin() * a2;
134
7fd59977 135 Standard_Real angle1 = myFirstAngle + RotationAngle();
136 Standard_Real angle2 = mySecondAngle + RotationAngle();
137 if ( angle1 != 0. ) {
138 a1 = -Sin (angle1);
139 b1 = Cos (angle1);
140 c1 = XOrigin() * b1 - YOrigin() * a1;
141 } else {
142 a1 = 0.; b1 = 1.; c1 = XOrigin();
143 }
144
145 if ( angle2 != 0. ) {
c6541a0c 146 angle2 += M_PI / 2.;
7fd59977 147 a2 = -Sin (angle2);
148 b2 = Cos (angle2);
149 c2 = XOrigin() * b2 - YOrigin() * a2;
150 } else {
151 a2 = -1.; b2 = 0.; c2 = YOrigin();
152 }
7fd59977 153//-zov
154}
155
156Standard_Boolean Aspect_RectangularGrid::CheckAngle(const Standard_Real alpha,
157 const Standard_Real beta) const {
c6541a0c 158 return (Abs( Sin(alpha) * Cos(beta + M_PI / 2.) - Cos(alpha) * Sin(beta + M_PI / 2.)) != 0) ;
7fd59977 159}
160
161