Skip to content

Commit 3a46201

Browse files
authored
Enhance Color4F and method naming change (#2072)
* Move set methods from Vec4 to base Vec4Base to allow usage with all subclasses of Vec4Base Rename Vec4::set method to setDirection to reflect its actual purpose Remove trivial copy constructor method since it does not need to be explicitly implemented * Add copyright line
1 parent 8fd2a55 commit 3a46201

File tree

2 files changed

+54
-73
lines changed

2 files changed

+54
-73
lines changed

core/math/Vec4.cpp

+5-38
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/**
22
Copyright 2013 BlackBerry Inc.
33
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
4+
Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md).
45
56
Licensed under the Apache License, Version 2.0 (the "License");
67
you may not use this file except in compliance with the License.
@@ -27,23 +28,15 @@
2728

2829
NS_AX_MATH_BEGIN
2930

30-
Vec4::Vec4() : Vec4Base() {}
31+
Vec4::Vec4() {}
3132

3233
Vec4::Vec4(float xx, float yy, float zz, float ww) : Vec4Base(xx, yy, zz, ww) {}
3334

34-
Vec4::Vec4(const float* src)
35-
{
36-
set(src);
37-
}
35+
Vec4::Vec4(const float* src) : Vec4Base(src) {}
3836

3937
Vec4::Vec4(const Vec4& p1, const Vec4& p2)
4038
{
41-
set(p1, p2);
42-
}
43-
44-
Vec4::Vec4(const Vec4& copy)
45-
{
46-
set(copy);
39+
setDirection(p1, p2);
4740
}
4841

4942
Vec4 Vec4::fromColor(unsigned int color)
@@ -219,33 +212,7 @@ Vec4 Vec4::getNormalized() const
219212
return v;
220213
}
221214

222-
void Vec4::set(float xx, float yy, float zz, float ww)
223-
{
224-
this->x = xx;
225-
this->y = yy;
226-
this->z = zz;
227-
this->w = ww;
228-
}
229-
230-
void Vec4::set(const float* array)
231-
{
232-
GP_ASSERT(array);
233-
234-
x = array[0];
235-
y = array[1];
236-
z = array[2];
237-
w = array[3];
238-
}
239-
240-
void Vec4::set(const Vec4& v)
241-
{
242-
this->x = v.x;
243-
this->y = v.y;
244-
this->z = v.z;
245-
this->w = v.w;
246-
}
247-
248-
void Vec4::set(const Vec4& p1, const Vec4& p2)
215+
void Vec4::setDirection(const Vec4& p1, const Vec4& p2)
249216
{
250217
x = p2.x - p1.x;
251218
y = p2.y - p1.y;

core/math/Vec4.h

+49-35
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Copyright 2013 BlackBerry Inc.
33
Copyright (c) 2014-2017 Chukong Technologies
44
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
5+
Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md).
56
67
Licensed under the Apache License, Version 2.0 (the "License");
78
you may not use this file except in compliance with the License.
@@ -45,6 +46,8 @@ class Vec4Base
4546

4647
Vec4Base() : x(0.0f), y(0.0f), z(0.0f), w(0.0f) {}
4748
Vec4Base(float xx, float yy, float zz, float ww) : x(xx), y(yy), z(zz), w(ww) {}
49+
explicit Vec4Base(const float* src) { this->set(src); }
50+
4851
union
4952
{
5053
struct
@@ -108,6 +111,50 @@ class Vec4Base
108111
return *static_cast<impl_type*>(this);
109112
}
110113

114+
/**
115+
* Sets the elements of this vector to the specified values.
116+
*
117+
* @param xx The new x coordinate.
118+
* @param yy The new y coordinate.
119+
* @param zz The new z coordinate.
120+
* @param ww The new w coordinate.
121+
*/
122+
void set(float xx, float yy, float zz, float ww)
123+
{
124+
this->x = xx;
125+
this->y = yy;
126+
this->z = zz;
127+
this->w = ww;
128+
}
129+
130+
/**
131+
* Sets the elements of this vector from the values in the specified array.
132+
*
133+
* @param array An array containing the elements of the vector in the order x, y, z, w.
134+
*/
135+
void set(const float* array)
136+
{
137+
GP_ASSERT(array);
138+
139+
this->x = array[0];
140+
this->y = array[1];
141+
this->z = array[2];
142+
this->w = array[3];
143+
}
144+
145+
/**
146+
* Sets the elements of this vector to those in the specified vector.
147+
*
148+
* @param v The vector to copy.
149+
*/
150+
void set(const impl_type& v)
151+
{
152+
this->x = v.x;
153+
this->y = v.y;
154+
this->z = v.z;
155+
this->w = v.w;
156+
}
157+
111158
inline impl_type& operator-() { return impl_type{*static_cast<impl_type*>(this)}.negate(); }
112159

113160
/**
@@ -246,7 +293,7 @@ class AX_DLL Vec4 : public Vec4Base<Vec4>
246293
*
247294
* @param array An array containing the elements of the vector in the order x, y, z, w.
248295
*/
249-
Vec4(const float* array);
296+
explicit Vec4(const float* array);
250297

251298
/**
252299
* Constructs a vector that describes the direction between the specified points.
@@ -256,15 +303,6 @@ class AX_DLL Vec4 : public Vec4Base<Vec4>
256303
*/
257304
Vec4(const Vec4& p1, const Vec4& p2);
258305

259-
/**
260-
* Constructor.
261-
*
262-
* Creates a new vector that is a copy of the specified vector.
263-
*
264-
* @param copy The vector to copy.
265-
*/
266-
Vec4(const Vec4& copy);
267-
268306
/**
269307
* Creates a new vector from an integer interpreted as an RGBA value.
270308
* E.g. 0xff0000ff represents opaque red or the vector (1, 0, 0, 1).
@@ -413,37 +451,13 @@ class AX_DLL Vec4 : public Vec4Base<Vec4>
413451
*/
414452
Vec4 getNormalized() const;
415453

416-
/**
417-
* Sets the elements of this vector to the specified values.
418-
*
419-
* @param xx The new x coordinate.
420-
* @param yy The new y coordinate.
421-
* @param zz The new z coordinate.
422-
* @param ww The new w coordinate.
423-
*/
424-
void set(float xx, float yy, float zz, float ww);
425-
426-
/**
427-
* Sets the elements of this vector from the values in the specified array.
428-
*
429-
* @param array An array containing the elements of the vector in the order x, y, z, w.
430-
*/
431-
void set(const float* array);
432-
433-
/**
434-
* Sets the elements of this vector to those in the specified vector.
435-
*
436-
* @param v The vector to copy.
437-
*/
438-
void set(const Vec4& v);
439-
440454
/**
441455
* Sets this vector to the directional vector between the specified points.
442456
*
443457
* @param p1 The first point.
444458
* @param p2 The second point.
445459
*/
446-
void set(const Vec4& p1, const Vec4& p2);
460+
void setDirection(const Vec4& p1, const Vec4& p2);
447461

448462
/**
449463
* Subtracts the specified vectors and stores the result in dst.

0 commit comments

Comments
 (0)