Skip to content

Commit 1f0c31f

Browse files
committed
Replaced default parameters with overloaded methods because they compile differently
1 parent 5fa4d79 commit 1f0c31f

File tree

1 file changed

+99
-8
lines changed

1 file changed

+99
-8
lines changed

src/main/scala/vecmatlib/color/Color.scala

Lines changed: 99 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,22 @@ import vecmatlib.Float4
66
* Class that represents a color as a four-dimensional float vector whose components are in a range from 0.0 to 1.0.
77
* Values outside the (0.0, 1.0) range are allowed.
88
*
9-
* @constructor Constructs a color with the four given values
9+
* @constructor Constructs a color with the four given RGBA values
1010
* @param r Red component of the color in a range from 0.0 to 1.0
1111
* @param g Green component of the color in a range from 0.0 to 1.0
1212
* @param b Blue component of the color in a range from 0.0 to 1.0
1313
* @param a Red component of the color in a range from 0.0 to 1.0
1414
*/
15-
case class Color(r: Float, g: Float, b: Float, a: Float = 1.0f) extends Float4 {
15+
case class Color(r: Float, g: Float, b: Float, a: Float) extends Float4 {
16+
17+
/**
18+
* Constructs a color with the three given RGB values and an alpha value of 1.0
19+
*
20+
* @param r Red component of the color in a range from 0.0 to 1.0
21+
* @param g Green component of the color in a range from 0.0 to 1.0
22+
* @param b Blue component of the color in a range from 0.0 to 1.0
23+
*/
24+
def this(r: Float, g: Float, b: Float) = this(r, g, b, 1.0f)
1625

1726
/**
1827
* Returns a new color resulting from adding the given color to this one.
@@ -23,7 +32,17 @@ case class Color(r: Float, g: Float, b: Float, a: Float = 1.0f) extends Float4 {
2332
* @param a Alpha component of the color to add
2433
* @return A color resulting from adding the given color to this one
2534
*/
26-
def +(r: Float, g: Float, b: Float, a: Float = 0.0f): Color = Color(this.r + r, this.g + g, this.b + b, this.a + a)
35+
def +(r: Float, g: Float, b: Float, a: Float): Color = Color(this.r + r, this.g + g, this.b + b, this.a + a)
36+
37+
/**
38+
* Returns a new color resulting from adding the given color to this one.
39+
*
40+
* @param r Red component of the color to add
41+
* @param g Green component of the color to add
42+
* @param b Blue component of the color to add
43+
* @return A color resulting from adding the given color to this one
44+
*/
45+
def +(r: Float, g: Float, b: Float): Color = this + (r, g, b, 0.0f)
2746

2847
/**
2948
* Returns a new color resulting from adding the given color to this one.
@@ -44,7 +63,19 @@ case class Color(r: Float, g: Float, b: Float, a: Float = 1.0f) extends Float4 {
4463
* @param a Alpha component of the color to add
4564
* @return A color resulting from adding the given color to this one
4665
*/
47-
def add(r: Float, g: Float, b: Float, a: Float = 0.0f): Color = this + (r, g, b, a)
66+
def add(r: Float, g: Float, b: Float, a: Float): Color = this + (r, g, b, a)
67+
68+
/**
69+
* Returns a new color resulting from adding the given color to this one.
70+
*
71+
* This method can be used in place of the '+' operator for better interoperability with Java.
72+
*
73+
* @param r Red component of the color to add
74+
* @param g Green component of the color to add
75+
* @param b Blue component of the color to add
76+
* @return A color resulting from adding the given color to this one
77+
*/
78+
def add(r: Float, g: Float, b: Float): Color = this.add(r, g, b, 0.0f)
4879

4980
/**
5081
* Returns a new color resulting from adding the given color to this one.
@@ -65,7 +96,17 @@ case class Color(r: Float, g: Float, b: Float, a: Float = 1.0f) extends Float4 {
6596
* @param a Alpha component of the color to subtract
6697
* @return A color resulting from subtracting the given color from this one
6798
*/
68-
def -(r: Float, g: Float, b: Float, a: Float = 0.0f): Color = Color(this.r - r, this.g - g, this.b - b, this.a - a)
99+
def -(r: Float, g: Float, b: Float, a: Float): Color = Color(this.r - r, this.g - g, this.b - b, this.a - a)
100+
101+
/**
102+
* Returns a new color resulting from subtracting the given color from this one.
103+
*
104+
* @param r Red component of the color to subtract
105+
* @param g Green component of the color to subtract
106+
* @param b Blue component of the color to subtract
107+
* @return A color resulting from subtracting the given color from this one
108+
*/
109+
def -(r: Float, g: Float, b: Float): Color = this - (r, g, b, 0.0f)
69110

70111
/**
71112
* Returns a new color resulting from subtracting the given color from this one.
@@ -86,7 +127,19 @@ case class Color(r: Float, g: Float, b: Float, a: Float = 1.0f) extends Float4 {
86127
* @param a Alpha component of the color to subtract
87128
* @return A color resulting from subtracting the given color from this one
88129
*/
89-
def subtract(r: Float, g: Float, b: Float, a: Float = 0.0f): Color = this - (r, g, b, a)
130+
def subtract(r: Float, g: Float, b: Float, a: Float): Color = this - (r, g, b, a)
131+
132+
/**
133+
* Returns a new color resulting from subtracting the given color from this one.
134+
*
135+
* This method can be used in place of the '-' operator for better interoperability with Java.
136+
*
137+
* @param r Red component of the color to subtract
138+
* @param g Green component of the color to subtract
139+
* @param b Blue component of the color to subtract
140+
* @return A color resulting from subtracting the given color from this one
141+
*/
142+
def subtract(r: Float, g: Float, b: Float): Color = this.subtract(r, g, b, 0.0f)
90143

91144
/**
92145
* Returns a new color resulting from subtracting the given color from this one.
@@ -107,7 +160,17 @@ case class Color(r: Float, g: Float, b: Float, a: Float = 1.0f) extends Float4 {
107160
* @param a Alpha component of the color
108161
* @return A color resulting from multiplying every component of this color with the given ones
109162
*/
110-
def *(r: Float, g: Float, b: Float, a: Float = 1.0f): Color = Color(this.r * r, this.g * g, this.b * b, this.a * a)
163+
def *(r: Float, g: Float, b: Float, a: Float): Color = Color(this.r * r, this.g * g, this.b * b, this.a * a)
164+
165+
/**
166+
* Returns a new color resulting from multiplying every component of this color with the given ones.
167+
*
168+
* @param r Red component of the color
169+
* @param g Green component of the color
170+
* @param b Blue component of the color
171+
* @return A color resulting from multiplying every component of this color with the given ones
172+
*/
173+
def *(r: Float, g: Float, b: Float): Color = this * (r, g, b, 1.0f)
111174

112175
/**
113176
* Returns a new color resulting from the component-wise multiplication of this color with the given one.
@@ -128,7 +191,19 @@ case class Color(r: Float, g: Float, b: Float, a: Float = 1.0f) extends Float4 {
128191
* @param a Alpha component of the color
129192
* @return A color resulting from multiplying every component of this color with the given ones
130193
*/
131-
def blend(r: Float, g: Float, b: Float, a: Float = 1.0f): Color = this * (r, g, b, a)
194+
def blend(r: Float, g: Float, b: Float, a: Float): Color = this * (r, g, b, a)
195+
196+
/**
197+
* Returns a new color resulting from multiplying every component of this color with the given ones.
198+
*
199+
* This method can be used in place of the '*' operator for better interoperability with Java.
200+
*
201+
* @param r Red component of the color
202+
* @param g Green component of the color
203+
* @param b Blue component of the color
204+
* @return A color resulting from multiplying every component of this color with the given ones
205+
*/
206+
def blend(r: Float, g: Float, b: Float): Color = this.blend(r, g, b, 1.0f)
132207

133208
/**
134209
* Returns a new color resulting from the component-wise multiplication of this color with the given one.
@@ -218,3 +293,19 @@ case class Color(r: Float, g: Float, b: Float, a: Float = 1.0f) extends Float4 {
218293
*/
219294
override def w: Float = this.a
220295
}
296+
297+
/**
298+
* Color companion object.
299+
*/
300+
object Color {
301+
302+
/**
303+
* Constructs a color with the three given RGB values and an alpha value of 1.0.
304+
*
305+
* @param r Red component of the color in a range from 0.0 to 1.0
306+
* @param g Green component of the color in a range from 0.0 to 1.0
307+
* @param b Blue component of the color in a range from 0.0 to 1.0
308+
* @return A color with the three given RGB values and an alpha value of 1.0
309+
*/
310+
def apply(r: Float, g: Float, b: Float): Color = this.apply(r, g, b, 1.0f)
311+
}

0 commit comments

Comments
 (0)