Skip to content

Commit 1cf7f76

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents 074c483 + 11ff45e commit 1cf7f76

File tree

10 files changed

+1598
-1
lines changed

10 files changed

+1598
-1
lines changed

src/main/kotlin/glm_/func/func_exponential.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package glm_.func
22

3+
import glm_.d
4+
import glm_.i
35
import glm_.vec2.Vec2
46
import glm_.vec2.Vec2d
57
import glm_.vec3.Vec3
@@ -212,6 +214,7 @@ interface func_exponential {
212214

213215
fun log2(a: Double) = _log2(a)
214216
fun log2(a: Float) = _log2(a)
217+
fun log2(a: Int) = _log2(a.d).i
215218

216219
fun log2(a: Vec2, res: Vec2 = Vec2()) {
217220
res.x = log2(a.x)

src/main/kotlin/glm_/glm.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,11 @@ object glm :
5858
packing,
5959
func_packing,
6060

61-
random {
61+
random,
62+
63+
optimumPow,
64+
65+
gradientPaint {
6266

6367
@JvmField
6468
val detail = Detail

src/main/kotlin/glm_/gradientPaint.kt

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package glm_
2+
3+
import glm_.vec2.Vec2
4+
5+
interface gradientPaint {
6+
7+
fun radialGradient(
8+
center: Vec2,
9+
radius: Float,
10+
focal: Vec2,
11+
position: Vec2
12+
): Float {
13+
val fX = focal.x - center.x
14+
val fY = focal.y - center.y
15+
val dX = position.x - focal.x
16+
val dY = position.y - focal.y
17+
val radius2 = glm.pow2(radius)
18+
val fX2 = glm.pow2(fX)
19+
val fY2 = glm.pow2(fY)
20+
21+
val numerator = (dX * fX + dY * fY) + glm.sqrt(radius2 * (glm.pow2(dX) + glm.pow2(dY)) - glm.pow2(dX * fY - dY * fX))
22+
val denominator = radius2 - (fX2 + fY2)
23+
return numerator / denominator
24+
}
25+
26+
fun linearGradient(
27+
point0: Vec2,
28+
point1: Vec2,
29+
position: Vec2
30+
): Float {
31+
val distX = point1.x - point0.x
32+
val distY = point1.y - point0.y
33+
val dot = distX * distX + distY * distY
34+
return (distX * (position.x - point0.x) + distY * (position.y - point0.y)) / dot
35+
}
36+
}

src/main/kotlin/glm_/optimumPow.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package glm_
2+
3+
interface optimumPow {
4+
5+
fun pow2(x: Float) = x * x
6+
7+
fun pow3(x: Float) = x * x * x
8+
9+
fun pow4(x: Float) = (x * x) * (x * x)
10+
}

src/main/kotlin/glm_/round.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ import glm_.vec3.Vec3i
88

99
interface round {
1010

11+
fun floorMultiple(source: Int, multiple: Int) = when {
12+
source > 0 -> source - source % multiple
13+
else -> {
14+
val tmp = source + 1
15+
tmp - tmp % multiple - multiple
16+
}
17+
}
1118

1219
fun ceilMultiple(source: Float, multiple: Float) =
1320
if (source > 0) source + (multiple - source % multiple)

0 commit comments

Comments
 (0)