Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup math package #1864

Merged
merged 14 commits into from
Sep 22, 2023
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package korlibs.image.util

import korlibs.datastructure.*
import korlibs.math.geom.range.*
import korlibs.math.range.*

class NinePatchSlices private constructor(val ranges: List<FloatRangeExclusive>, dummy: Unit) {
constructor(ranges: List<FloatRangeExclusive>) : this(ranges.sortedBy { it.start }, Unit)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package korlibs.image.util

import korlibs.datastructure.*
import korlibs.datastructure.doubleArrayListOf
import korlibs.math.geom.*
import korlibs.math.geom.range.until
import kotlin.test.Test
import kotlin.test.assertEquals
import korlibs.math.range.*
import kotlin.test.*

class NinePatchToolsTest {
@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
package korlibs.image.vector

import korlibs.image.color.Colors
import korlibs.image.util.NinePatchSlices
import korlibs.image.util.NinePatchSlices2D
import korlibs.image.vector.format.readSVG
import korlibs.io.async.suspendTest
import korlibs.io.file.std.resourcesVfs
import korlibs.image.color.*
import korlibs.image.util.*
import korlibs.image.vector.format.*
import korlibs.io.async.*
import korlibs.io.file.std.*
import korlibs.math.geom.*
import korlibs.math.geom.range.until
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue
import korlibs.math.range.*
import kotlin.test.*

class NinePatchShapeTest {
@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
package korlibs.math.geom.range
@file:Suppress("PackageDirectoryMismatch")

package korlibs.math.range

import korlibs.number.*

Expand Down
37 changes: 37 additions & 0 deletions korge-foundation/src/commonMain/kotlin/korlibs/math/geom/Anchor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,40 @@ data class Anchor(val sx: Float, val sy: Float) : Interpolable<Anchor> {

operator fun Size.times(anchor: Anchor): Point = this.toVector() * anchor.toVector()
//operator fun SizeInt.times(anchor: Anchor): PointInt = (this.toVector().toFloat() * anchor.toVector()).toInt()

data class Anchor3(val sx: Float, val sy: Float, val sz: Float) : Interpolable<Anchor3> {
fun toVector(): Vector3 = Vector3(sx, sy, sz)

val floatX: Float get() = sx
val floatY: Float get() = sy
val floatZ: Float get() = sz

val doubleX: Double get() = sx.toDouble()
val doubleY: Double get() = sy.toDouble()
val doubleZ: Double get() = sz.toDouble()

val ratioX: Ratio get() = sx.toRatio()
val ratioY: Ratio get() = sy.toRatio()
val ratioZ: Ratio get() = sz.toRatio()

constructor(sx: Double, sy: Double, sz: Double) : this(sx.toFloat(), sy.toFloat(), sz.toFloat())
constructor(sx: Int, sy: Int, sz: Int) : this(sx.toFloat(), sy.toFloat(), sz.toFloat())

fun withX(sx: Float): Anchor3 = Anchor3(sx, sy, sz)
fun withX(sx: Int): Anchor3 = Anchor3(sx.toFloat(), sy, sz)
fun withX(sx: Double): Anchor3 = Anchor3(sx.toFloat(), sy, sz)

fun withY(sy: Float): Anchor3 = Anchor3(sx, sy, sz)
fun withY(sy: Int): Anchor3 = Anchor3(sx, sy.toFloat(), sz)
fun withY(sy: Double): Anchor3 = Anchor3(sx, sy.toFloat(), sz)

fun withZ(sz: Float): Anchor3 = Anchor3(sx, sy, sz)
fun withZ(sz: Int): Anchor3 = Anchor3(sx, sy, sz.toFloat())
fun withZ(sz: Double): Anchor3 = Anchor3(sx, sy, sz.toFloat())

override fun interpolateWith(ratio: Ratio, other: Anchor3): Anchor3 = Anchor3(
ratio.interpolate(this.sx, other.sx),
ratio.interpolate(this.sy, other.sy),
ratio.interpolate(this.sz, other.sz),
)
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package korlibs.math.geom

import korlibs.math.*
import korlibs.math.geom.range.*
import korlibs.math.interpolation.*
import korlibs.math.range.*
import korlibs.number.*
import kotlin.math.*

Expand Down
25 changes: 0 additions & 25 deletions korge-foundation/src/commonMain/kotlin/korlibs/math/geom/Circle.kt

This file was deleted.

16 changes: 7 additions & 9 deletions korge-foundation/src/commonMain/kotlin/korlibs/math/geom/Line.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package korlibs.math.geom

import korlibs.math.almostEquals
import korlibs.math.clamp
import korlibs.math.annotations.*
import korlibs.math.geom.bezier.*
import korlibs.math.geom.shape.*
import korlibs.math.geom.vector.*
import korlibs.math.isAlmostZero
import kotlin.math.*
import korlibs.math.*
import korlibs.math.annotations.KormaExperimental
import korlibs.math.geom.bezier.Bezier
import korlibs.math.geom.shape.Shape2D
import korlibs.math.geom.shape.buildVectorPath
import korlibs.math.geom.vector.VectorPath
import kotlin.math.sign

//@KormaValueApi
data class Line(val a: Vector2, val b: Vector2) : Shape2D {
Expand Down Expand Up @@ -169,5 +168,4 @@ data class Line(val a: Vector2, val b: Vector2) : Shape2D {
fun getIntersectXY(a: Point, b: Point, c: Point, d: Point): Point? =
getIntersectXY(a.x, a.y, b.x, b.y, c.x, c.y, d.x, d.y)
}

}

This file was deleted.

Loading