KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sg_base.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2015 Cirilo Bernardo <[email protected]>
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
21
22#include <cmath>
23#include <iostream>
24#include <sstream>
25#include <wx/log.h>
26
28
29
31{
32 red = 0.0;
33 green = 0.0;
34 blue = 0.0;
35}
36
37SGCOLOR::SGCOLOR( float aRVal, float aGVal, float aBVal )
38{
39 if( !checkRange( aRVal, aGVal, aBVal ) )
40 {
41 wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [BUG] invalid value passed to constructor" ),
42 __FILE__, __FUNCTION__, __LINE__ );
43 red = 0.0;
44 green = 0.0;
45 blue = 0.0;
46 return;
47 }
48
49 red = aRVal;
50 green = aGVal;
51 blue = aBVal;
52}
53
54
55void SGCOLOR::GetColor( float& aRedVal, float& aGreenVal, float& aBlueVal ) const noexcept
56{
57 aRedVal = red;
58 aGreenVal = green;
59 aBlueVal = blue;
60}
61
62
63void SGCOLOR::GetColor( SGCOLOR& aColor ) const noexcept
64{
65 aColor.red = red;
66 aColor.green = green;
67 aColor.blue = blue;
68}
69
70
71void SGCOLOR::GetColor( SGCOLOR* aColor ) const noexcept
72{
73 wxCHECK_MSG( aColor, /* void */, wxT( "NULL pointer passed for aRGBColor" ) );
74
75 aColor->red = red;
76 aColor->green = green;
77 aColor->blue = blue;
78}
79
80
81bool SGCOLOR::SetColor( float aRedVal, float aGreenVal, float aBlueVal )
82{
83 if( !checkRange( aRedVal, aGreenVal, aBlueVal ) )
84 return false;
85
86 red = aRedVal;
87 green = aGreenVal;
88 blue = aBlueVal;
89
90 return true;
91}
92
93
94bool SGCOLOR::SetColor( const SGCOLOR& aColor ) noexcept
95{
96 red = aColor.red;
97 green = aColor.green;
98 blue = aColor.blue;
99 return true;
100}
101
102
103bool SGCOLOR::SetColor( const SGCOLOR* aColor ) noexcept
104{
105 wxCHECK_MSG( aColor, false, wxT( "NULL pointer passed for aRGBColor" ) );
106
107 red = aColor->red;
108 green = aColor->green;
109 blue = aColor->blue;
110 return true;
111}
112
113
114bool SGCOLOR::checkRange( float aRedVal, float aGreenVal, float aBlueVal ) const noexcept
115{
116 bool ok = true;
117
118 if( aRedVal < 0.0 || aRedVal > 1.0 )
119 {
120 wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [BUG] invalid RED value: %g" ),
121 __FILE__, __FUNCTION__, __LINE__, aRedVal );
122
123 ok = false;
124 }
125
126 if( aGreenVal < 0.0 || aGreenVal > 1.0 )
127 {
128 wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [BUG] invalid GREEN value: %g" ),
129 __FILE__, __FUNCTION__, __LINE__, aGreenVal );
130
131 ok = false;
132 }
133
134 if( aBlueVal < 0.0 || aBlueVal > 1.0 )
135 {
136 wxLogTrace( MASK_3D_SG, wxT( "%s:%s:%d * [BUG] invalid BLUE value: %g" ),
137 __FILE__, __FUNCTION__, __LINE__, aBlueVal );
138
139 ok = false;
140 }
141
142 return ok;
143}
144
145
147{
148 x = 0.0;
149 y = 0.0;
150 z = 0.0;
151}
152
153
154SGPOINT::SGPOINT( double aXVal, double aYVal, double aZVal ) noexcept
155{
156 x = aXVal;
157 y = aYVal;
158 z = aZVal;
159}
160
161
162void SGPOINT::GetPoint( const double& aXVal, const double& aYVal, const double& aZVal ) noexcept
163{
164 x = aXVal;
165 y = aYVal;
166 z = aZVal;
167}
168
169
170void SGPOINT::GetPoint( const SGPOINT& aPoint ) noexcept
171{
172 x = aPoint.x;
173 y = aPoint.y;
174 z = aPoint.z;
175}
176
177
178void SGPOINT::GetPoint( const SGPOINT* aPoint ) noexcept
179{
180 wxCHECK_MSG( aPoint, /* void */, wxT( "NULL pointer passed for aPoint" ) );
181
182 x = aPoint->x;
183 y = aPoint->y;
184 z = aPoint->z;
185}
186
187
188void SGPOINT::SetPoint( double aXVal, double aYVal, double aZVal ) noexcept
189{
190 x = aXVal;
191 y = aYVal;
192 z = aZVal;
193}
194
195
196void SGPOINT::SetPoint( const SGPOINT& aPoint ) noexcept
197{
198 x = aPoint.x;
199 y = aPoint.y;
200 z = aPoint.z;
201}
202
203
205{
206 vx = 0.0;
207 vy = 0.0;
208 vz = 1.0;
209}
210
211
212SGVECTOR::SGVECTOR( double aXVal, double aYVal, double aZVal )
213{
214 vx = aXVal;
215 vy = aYVal;
216 vz = aZVal;
217 normalize();
218}
219
220
221void SGVECTOR::GetVector( double& aXVal, double& aYVal, double& aZVal ) const noexcept
222{
223 aXVal = vx;
224 aYVal = vy;
225 aZVal = vz;
226}
227
228
229void SGVECTOR::SetVector( double aXVal, double aYVal, double aZVal )
230{
231 vx = aXVal;
232 vy = aYVal;
233 vz = aZVal;
234 normalize();
235}
236
237
238void SGVECTOR::SetVector( const SGVECTOR& aVector )
239{
240 aVector.GetVector( vx, vy, vz );
241}
242
243
244void SGVECTOR::normalize( void ) noexcept
245{
246 double dx = vx * vx;
247 double dy = vy * vy;
248 double dz = vz * vz;
249 double dv2 = sqrt( dx + dy + dz );
250
251 if( ( dx + dy + dz ) < 1e-8 )
252 {
253 // use the default; the numbers are too small to be believable
254 vx = 0.0;
255 vy = 0.0;
256 vz = 1.0;
257 return;
258 }
259
260 vx /= dv2;
261 vy /= dv2;
262 vz /= dv2;
263}
264
265
266SGVECTOR& SGVECTOR::operator=( const SGVECTOR& source ) noexcept
267{
268 vx = source.vx;
269 vy = source.vy;
270 vz = source.vz;
271 return *this;
272}
bool SetColor(float aRedVal, float aGreenVal, float aBlueVal)
Definition sg_base.cpp:81
float red
Definition sg_base.h:42
void GetColor(float &aRedVal, float &aGreenVal, float &aBlueVal) const noexcept
Definition sg_base.cpp:55
bool checkRange(float aRedVal, float aGreenVal, float aBlueVal) const noexcept
Definition sg_base.cpp:114
float green
Definition sg_base.h:43
float blue
Definition sg_base.h:44
SGCOLOR()
Definition sg_base.cpp:30
double z
Definition sg_base.h:68
void GetPoint(const double &aXVal, const double &aYVal, const double &aZVal) noexcept
Definition sg_base.cpp:162
void SetPoint(double aXVal, double aYVal, double aZVal) noexcept
Definition sg_base.cpp:188
double x
Definition sg_base.h:66
double y
Definition sg_base.h:67
void normalize(void) noexcept
Definition sg_base.cpp:244
double vz
Definition sg_base.h:90
void GetVector(double &aXVal, double &aYVal, double &aZVal) const noexcept
Definition sg_base.cpp:221
double vx
Definition sg_base.h:88
double vy
Definition sg_base.h:89
SGVECTOR & operator=(const SGVECTOR &source) noexcept
Definition sg_base.cpp:266
void SetVector(double aXVal, double aYVal, double aZVal)
Definition sg_base.cpp:229
defines the low level classes common to scene graph nodes