Skip to content

Commit 55bd6e8

Browse files
committed
Fix vector substraction
1 parent 0f869ff commit 55bd6e8

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

common/src/main/kotlin/com/lambda/gui/api/component/core/DockingRect.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,15 @@ abstract class DockingRect {
5757
var screenSize: Vec2d = Vec2d.ZERO
5858

5959
var position: Vec2d
60-
get() = relativeToAbs(relativePos).coerceIn(0.0, screenSize.x - size.x, 0.0, screenSize.y - size.y)
60+
get() = relativeToAbs(relativePos)
61+
.coerceIn(0.0, screenSize.x - size.x, 0.0, screenSize.y - size.y)
6162
set(value) {
62-
relativePos = absToRelative(value.roundToStep(ClickGui.dockingGridSize)); if (autoDocking) autoDocking()
63+
relativePos = absToRelative(value.roundToStep(ClickGui.dockingGridSize))
64+
if (autoDocking) autoDocking()
6365
}
6466

65-
private val dockingOffset get() = (screenSize - size) * Vec2d(dockingH.multiplier, dockingV.multiplier)
67+
private val dockingOffset get() =
68+
(screenSize - size) * Vec2d(dockingH.multiplier, dockingV.multiplier)
6669

6770
private fun relativeToAbs(posIn: Vec2d) = posIn + dockingOffset
6871
private fun absToRelative(posIn: Vec2d) = posIn - dockingOffset

common/src/main/kotlin/com/lambda/util/math/MathUtils.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ object MathUtils {
5454
BigDecimal(this).setScale(places, RoundingMode.HALF_EVEN).toDouble()
5555

5656
private val Double.decimals: Int
57-
get() = BigDecimal(this).scale()
57+
get() = BigDecimal.valueOf(this).scale()
5858

5959
fun <T : Number> T.typeConvert(valueIn: Double): T {
6060
@Suppress("UNCHECKED_CAST")
@@ -69,8 +69,7 @@ object MathUtils {
6969
} as T
7070
}
7171

72-
// TODO: wtf is this? is this just a coerce ?
73-
fun Vec2d.roundToStep(step: Double): Vec2d =
72+
fun Vec2d.roundToStep(step: Double) =
7473
Vec2d(x.roundToStep(step), y.roundToStep(step))
7574

7675
fun random(v1: Double, v2: Double): Double {

common/src/main/kotlin/com/lambda/util/math/Vec2d.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ data class Vec2d(val x: Double, val y: Double) {
2323
constructor(x: Float, y: Float) : this(x.toDouble(), y.toDouble())
2424
constructor(x: Int, y: Int) : this(x.toDouble(), y.toDouble())
2525

26-
operator fun unaryMinus(): Vec2d = Vec2d(-x, -y)
26+
operator fun unaryMinus() = Vec2d(-x, -y)
2727

2828
fun plus(x: Double, y: Double) = Vec2d(this.x + x, this.y + y)
2929
infix operator fun plus(other: Vec2d) = plus(other.x, other.y)
3030
infix operator fun plus(other: Double) = plus(other, other)
3131
infix operator fun plus(other: Float): Vec2d = plus(other.toDouble(), other.toDouble())
3232
infix operator fun plus(other: Int): Vec2d = plus(other.toDouble(), other.toDouble())
3333

34-
fun minus(x: Double, y: Double)= Vec2d(this.x + x, this.y + y)
34+
fun minus(x: Double, y: Double) = Vec2d(this.x - x, this.y - y)
3535
infix operator fun minus(other: Vec2d): Vec2d = minus(other.x, other.y)
3636
infix operator fun minus(other: Double): Vec2d = minus(other, other)
3737
infix operator fun minus(other: Float): Vec2d = minus(other.toDouble(), other.toDouble())
@@ -49,7 +49,7 @@ data class Vec2d(val x: Double, val y: Double) {
4949
infix operator fun div(other: Float): Vec2d = div(other.toDouble(), other.toDouble())
5050
infix operator fun div(other: Int): Vec2d = div(other.toDouble(), other.toDouble())
5151

52-
fun roundToInt(): Vec2d = Vec2d(this.x.roundToInt(), this.y.roundToInt())
52+
fun roundToInt() = Vec2d(x.roundToInt(), y.roundToInt())
5353

5454
companion object {
5555
val ZERO = Vec2d(0.0, 0.0)

0 commit comments

Comments
 (0)