Skip to content

Commit c6fb6db

Browse files
committed
Fixed Better follow GLSL min and max specification
g-truc/glm@fc53581 increase coverage
1 parent 98c8138 commit c6fb6db

File tree

10 files changed

+537
-72
lines changed

10 files changed

+537
-72
lines changed

src/main/kotlin/glm_/epsilon.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import glm_.glm.greaterThan
66
import glm_.glm.lessThan
77
import glm_.quat.Quat
88
import glm_.quat.QuatD
9+
import glm_.vec1.Vec1
10+
import glm_.vec1.Vec1bool
911
import glm_.vec2.*
1012
import glm_.vec3.*
1113
import glm_.vec4.*
@@ -32,6 +34,9 @@ interface epsilon {
3234
fun epsilonNotEqual(x: Short, y: Short, epsilon: Short) = abs(x - y) >= epsilon
3335

3436

37+
fun epsilonEqual(a: Vec1, b: Vec1, epsilon: Float, res: Vec1bool = Vec1bool()) = lessThan(abs(a - b), Vec1(epsilon), res)
38+
fun epsilonEqual(a: Vec1, b: Vec1, epsilon: Vec1, res: Vec1bool = Vec1bool()) = lessThan(abs(a - b), epsilon)
39+
3540
fun epsilonEqual(a: Vec2, b: Vec2, epsilon: Float, res: Vec2bool = Vec2bool()) = lessThan(abs(a - b), Vec2(epsilon), res)
3641
fun epsilonEqual(a: Vec2, b: Vec2, epsilon: Vec2, res: Vec2bool = Vec2bool()) = lessThan(abs(a - b), epsilon)
3742

src/main/kotlin/glm_/func/common/func_common.kt

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ import kotlin.math.absoluteValue
2121
import kotlin.math.sign
2222
import kotlin.math.ceil as _ceil
2323
import kotlin.math.floor as _floor
24-
import kotlin.math.max as _max
25-
import kotlin.math.min as _min
2624
import kotlin.math.round as _round
2725

2826

@@ -78,19 +76,19 @@ interface func_common {
7876
// TODO modf
7977

8078

81-
fun min(a: Float, b: Float) = _min(a, b)
82-
fun min(a: Double, b: Double) = _min(a, b)
83-
fun min(a: Byte, b: Byte) = _min(a.i, b.i).b
84-
fun min(a: Int, b: Int) = _min(a, b)
85-
fun min(a: Long, b: Long) = _min(a, b)
86-
fun min(a: Short, b: Short) = _min(a.i, b.i).s
79+
fun min(a: Float, b: Float) = if(b < a) b else a
80+
fun min(a: Double, b: Double) = if(b < a) b else a
81+
fun min(a: Byte, b: Byte) = if(b < a) b else a
82+
fun min(a: Int, b: Int) = if(b < a) b else a
83+
fun min(a: Long, b: Long) = if(b < a) b else a
84+
fun min(a: Short, b: Short) = if(b < a) b else a
8785

88-
fun max(a: Float, b: Float) = _max(a, b)
89-
fun max(a: Double, b: Double) = _max(a, b)
90-
fun max(a: Byte, b: Byte) = _max(a.i, b.i).b
91-
fun max(a: Int, b: Int) = _max(a, b)
92-
fun max(a: Long, b: Long) = _max(a, b)
93-
fun max(a: Short, b: Short) = _max(a.i, b.i).s
86+
fun max(a: Float, b: Float) = if(a < b) b else a
87+
fun max(a: Double, b: Double) = if(a < b) b else a
88+
fun max(a: Byte, b: Byte) = if(a < b) b else a
89+
fun max(a: Int, b: Int) = if(a < b) b else a
90+
fun max(a: Long, b: Long) = if(a < b) b else a
91+
fun max(a: Short, b: Short) = if(a < b) b else a
9492

9593

9694
fun clamp(a: Float, min: Float, max: Float) = min(max(a, min), max)

0 commit comments

Comments
 (0)