Skip to content

Commit 937bfff

Browse files
committed
fixed "Interacting with SV triangle"
1 parent 476462c commit 937bfff

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

src/main/kotlin/imgui/imgui/widgets colorEditorPicker.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -369,12 +369,12 @@ interface imgui_widgetsColorEditorPicker {
369369
}
370370
val cosHueAngle = glm.cos(-h * 2f * glm.PIf)
371371
val sinHueAngle = glm.sin(-h * 2f * glm.PIf)
372-
if (triangleContainsPoint(trianglePa, trianglePb, trianglePc, initialOff.rotateAssign(cosHueAngle, sinHueAngle))) { // TODO check
372+
if (triangleContainsPoint(trianglePa, trianglePb, trianglePc, initialOff.rotate(cosHueAngle, sinHueAngle))) {
373373
// Interacting with SV triangle
374-
val currentOffUnrotated = currentOff.rotateAssign(cosHueAngle, sinHueAngle)
374+
val currentOffUnrotated = currentOff.rotate(cosHueAngle, sinHueAngle)
375375
if (!triangleContainsPoint(trianglePa, trianglePb, trianglePc, currentOffUnrotated))
376376
currentOffUnrotated put triangleClosestPoint(trianglePa, trianglePb, trianglePc, currentOffUnrotated)
377-
val (uu, vv, ww) = triangleBarycentricCoords(trianglePa, trianglePb, trianglePc, currentOffUnrotated)
377+
val (uu, vv, _) = triangleBarycentricCoords(trianglePa, trianglePb, trianglePc, currentOffUnrotated)
378378
v = glm.clamp(1f - vv, 0.0001f, 1f)
379379
s = glm.clamp(uu / v, 0.0001f, 1f)
380380
valueChangedSv = true

src/main/kotlin/imgui/internal/helpers.kt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,15 +181,15 @@ fun triangleContainsPoint(a: Vec2, b: Vec2, c: Vec2, p: Vec2): Boolean {
181181
return ((b1 == b2) && (b2 == b3))
182182
}
183183

184-
fun triangleBarycentricCoords(a: Vec2, b: Vec2, c: Vec2, p: Vec2, outU: Float = 0f, outV: Float = 0f, outW: Float = 0f): FloatArray {
184+
fun triangleBarycentricCoords(a: Vec2, b: Vec2, c: Vec2, p: Vec2): FloatArray {
185185
val v0 = b - a
186186
val v1 = c - a
187187
val v2 = p - a
188188
val denom = v0.x * v1.y - v1.x * v0.y
189-
return floatArrayOf(
190-
(v2.x * v1.y - v1.x * v2.y) / denom,
191-
(v0.x * v2.y - v2.x * v0.y) / denom,
192-
1f - outV - outW)
189+
val outV = (v2.x * v1.y - v1.x * v2.y) / denom
190+
val outW = (v0.x * v2.y - v2.x * v0.y) / denom
191+
val outU = 1f - outV - outW
192+
return floatArrayOf(outU, outV, outW)
193193
}
194194

195195
fun triangleClosestPoint(a: Vec2, b: Vec2, c: Vec2, p: Vec2): Vec2 {
@@ -281,7 +281,6 @@ fun Vec2.invLength(failValue: Float): Float {
281281
return failValue
282282
}
283283

284-
fun Vec2.rotateAssign(cosA: Float, sinA: Float) = invoke(x * cosA - y * sinA, x * sinA + y * cosA)
285284
fun Vec2.rotate(cosA: Float, sinA: Float) = Vec2(x * cosA - y * sinA, x * sinA + y * cosA)
286285
fun linearSweep(current: Float, target: Float, speed: Float) = when {
287286
current < target -> glm.min(current + speed, target)

0 commit comments

Comments
 (0)