diff --git a/korge-sandbox/src/commonMain/kotlin/samples/MainArc.kt b/korge-sandbox/src/commonMain/kotlin/samples/MainArc.kt index ca3f101799..a121e2f57c 100644 --- a/korge-sandbox/src/commonMain/kotlin/samples/MainArc.kt +++ b/korge-sandbox/src/commonMain/kotlin/samples/MainArc.kt @@ -4,9 +4,8 @@ import com.soywiz.korev.Key import com.soywiz.korge.input.keys import com.soywiz.korge.scene.Scene import com.soywiz.korge.view.* -import com.soywiz.korge.view.vector.gpuShapeView import com.soywiz.korim.color.Colors -import com.soywiz.korma.geom.Point +import com.soywiz.korma.geom.MPoint import com.soywiz.korma.geom.bezier.Arc import com.soywiz.korma.geom.vector.StrokeInfo import com.soywiz.korma.geom.vector.circle @@ -16,8 +15,8 @@ class MainArc : Scene() { override suspend fun SContainer.sceneMain() { //graphics(renderer = GraphicsRenderer.GPU) { shape -> graphics(renderer = GraphicsRenderer.SYSTEM) { shape -> - val p1 = Point(200, 100) - val p2 = Point(300, 200) + val p1 = MPoint(200, 100) + val p2 = MPoint(300, 200) val radius = 100.0 stroke(Colors.BLUE, StrokeInfo(thickness = 10.0)) { diff --git a/korge-sandbox/src/commonMain/kotlin/samples/MainBVH.kt b/korge-sandbox/src/commonMain/kotlin/samples/MainBVH.kt index 01bb04bbb7..5c4a37b0ca 100644 --- a/korge-sandbox/src/commonMain/kotlin/samples/MainBVH.kt +++ b/korge-sandbox/src/commonMain/kotlin/samples/MainBVH.kt @@ -17,10 +17,10 @@ import com.soywiz.korge.view.xy import com.soywiz.korim.color.Colors import com.soywiz.korim.font.* import com.soywiz.korio.util.* -import com.soywiz.korma.geom.Point +import com.soywiz.korma.geom.MPoint import com.soywiz.korma.geom.Ray -import com.soywiz.korma.geom.Rectangle -import com.soywiz.korma.geom.Size +import com.soywiz.korma.geom.MRectangle +import com.soywiz.korma.geom.MSize import com.soywiz.korma.geom.cosine import com.soywiz.korma.geom.ds.BVH2D import com.soywiz.korma.geom.shape.buildVectorPath @@ -60,11 +60,11 @@ class MainBVH : Scene() { bvh.insertOrUpdate(view.getBounds(this), view) } } - val center = Point(width / 2, height / 2) - val dir = Point(-1, -1) + val center = MPoint(width / 2, height / 2) + val dir = MPoint(-1, -1) val ray = Ray(center, dir) val statusText = text("", font = DefaultTtfFontAsBitmap) - var selectedRectangle = Rectangle(Point(100, 100) - Point(50, 50), Size(100, 100)) + var selectedRectangle = MRectangle(MPoint(100, 100) - MPoint(50, 50), MSize(100, 100)) val rayLine = line(center, center + (dir * 1000), Colors.WHITE) val selectedRect = outline(buildVectorPath(VectorPath()) { rect(selectedRectangle) @@ -75,7 +75,7 @@ class MainBVH : Scene() { var allObjectsSize = 0 var rayObjectsSize = 0 var rectangleObjectsSize = 0 - val allObjects = bvh.search(Rectangle(0.0, 0.0, width, height)) + val allObjects = bvh.search(MRectangle(0.0, 0.0, width, height)) val time = measureTime { val rayObjects = bvh.intersect(ray) val rectangleObjects = bvh.search(selectedRectangle) @@ -93,7 +93,7 @@ class MainBVH : Scene() { addUpdater { //println("moved") val mousePos = localMouseXY(views) - val angle = Point.angleFull(center, mousePos) + val angle = MPoint.angleFull(center, mousePos) //println("center=$center, mousePos=$mousePos, angle = $angle") dir.setTo(angle.cosine, angle.sine) rayLine.setPoints(center, center + (dir * 1000)) @@ -103,13 +103,13 @@ class MainBVH : Scene() { mouse { onDown { - selectedRectangle = Rectangle(stage!!.mouseXY - Point(50, 50), Size(100, 100)) + selectedRectangle = MRectangle(stage!!.mouseXY - MPoint(50, 50), MSize(100, 100)) selectedRect.vectorPath = buildVectorPath(VectorPath()) { rect(selectedRectangle) } } onMouseDrag { - selectedRectangle = Rectangle(stage.mouseXY - Point(50, 50), Size(100, 100)) + selectedRectangle = MRectangle(stage.mouseXY - MPoint(50, 50), MSize(100, 100)) selectedRect.vectorPath = buildVectorPath(VectorPath()) { rect(selectedRectangle) } diff --git a/korge-sandbox/src/commonMain/kotlin/samples/MainBezier.kt b/korge-sandbox/src/commonMain/kotlin/samples/MainBezier.kt index 774e99ab9f..01993a70eb 100644 --- a/korge-sandbox/src/commonMain/kotlin/samples/MainBezier.kt +++ b/korge-sandbox/src/commonMain/kotlin/samples/MainBezier.kt @@ -5,11 +5,10 @@ import com.soywiz.korge.scene.Scene import com.soywiz.korge.tween.get import com.soywiz.korge.tween.tween import com.soywiz.korge.view.* -import com.soywiz.korge.view.vector.gpuShapeView import com.soywiz.korim.color.Colors import com.soywiz.korim.vector.EmptyShape import com.soywiz.korio.async.launch -import com.soywiz.korma.geom.Point +import com.soywiz.korma.geom.MPoint import com.soywiz.korma.geom.bezier.Bezier import com.soywiz.korma.geom.vector.circle import com.soywiz.korma.geom.vector.curve @@ -24,7 +23,7 @@ class MainBezier : Scene() { //val shape = gpuShapeView(EmptyShape) val shape = graphics(EmptyShape, renderer = GraphicsRenderer.SYSTEM) //val shape = graphics(EmptyShape, renderer = GraphicsRenderer.GPU) - fun getRandomPoint() = Point(Random[100..500], Random[100..500]) + fun getRandomPoint() = MPoint(Random[100..500], Random[100..500]) class Bez { var p1 = getRandomPoint() var p2 = getRandomPoint() diff --git a/korge-sandbox/src/commonMain/kotlin/samples/MainBezierSample.kt b/korge-sandbox/src/commonMain/kotlin/samples/MainBezierSample.kt index 8895c65ecb..5dcb938aa6 100644 --- a/korge-sandbox/src/commonMain/kotlin/samples/MainBezierSample.kt +++ b/korge-sandbox/src/commonMain/kotlin/samples/MainBezierSample.kt @@ -22,7 +22,7 @@ import com.soywiz.korim.color.ColorTransform import com.soywiz.korim.color.Colors import com.soywiz.korim.paint.Paint import com.soywiz.korim.vector.ShapeBuilder -import com.soywiz.korma.geom.Point +import com.soywiz.korma.geom.MPoint import com.soywiz.korma.geom.bezier.Bezier import com.soywiz.korma.geom.vector.StrokeInfo import com.soywiz.korma.geom.vector.cubic @@ -31,10 +31,10 @@ import com.soywiz.korma.geom.vector.moveTo class MainBezierSample : Scene() { override suspend fun SContainer.sceneMain() { - val p0 = Point(109, 135) - val p1 = Point(25, 190) - val p2 = Point(210, 250) - val p3 = Point(234, 49) + val p0 = MPoint(109, 135) + val p1 = MPoint(25, 190) + val p2 = MPoint(210, 250) + val p3 = MPoint(234, 49) val graphics = cpuGraphics(autoScaling = true) val graphics2 = gpuShapeView().xy(0, 300) @@ -78,7 +78,7 @@ class MainBezierSample : Scene() { createPointController(p3, Colors.YELLOW) { updateGraphics() } } - fun Container.createPointController(point: Point, color: Paint, onMove: () -> Unit) { + fun Container.createPointController(point: MPoint, color: Paint, onMove: () -> Unit) { lateinit var circle: View lateinit var text: Text val anchorView = container { diff --git a/korge-sandbox/src/commonMain/kotlin/samples/MainBunnymark.kt b/korge-sandbox/src/commonMain/kotlin/samples/MainBunnymark.kt index c46dab10d4..fc0f2568ca 100644 --- a/korge-sandbox/src/commonMain/kotlin/samples/MainBunnymark.kt +++ b/korge-sandbox/src/commonMain/kotlin/samples/MainBunnymark.kt @@ -1,7 +1,6 @@ package samples import com.soywiz.klock.* -import com.soywiz.kmem.* import com.soywiz.korge.input.* import com.soywiz.korge.resources.* import com.soywiz.korge.scene.Scene @@ -50,7 +49,7 @@ class Bunny(tex: BmpSlice) : FastSprite(tex) { println("ag.isInstancedSupported=${ag.isInstancedSupported}") //suspend fun main() = Korge(width = 800, height = 600, bgcolor = Colors["#2b2b9b"]) { val wabbitTexture0 = resourcesVfs["bunnys.png"].readBitmap() - val GRAYSCALE_MATRIX = Matrix3D.fromColumns( + val GRAYSCALE_MATRIX = MMatrix3D.fromColumns( 0.33f, 0.33f, 0.33f, 0f, 0.59f, 0.59f, 0.59f, 0f, 0.11f, 0.11f, 0.11f, 0f, diff --git a/korge-sandbox/src/commonMain/kotlin/samples/MainColorPicker.kt b/korge-sandbox/src/commonMain/kotlin/samples/MainColorPicker.kt index 5a14233110..4ad0eb0d98 100644 --- a/korge-sandbox/src/commonMain/kotlin/samples/MainColorPicker.kt +++ b/korge-sandbox/src/commonMain/kotlin/samples/MainColorPicker.kt @@ -12,7 +12,7 @@ import com.soywiz.korim.bitmap.Bitmaps import com.soywiz.korim.bitmap.slice import com.soywiz.korim.format.readBitmap import com.soywiz.korio.file.std.resourcesVfs -import com.soywiz.korma.geom.Rectangle +import com.soywiz.korma.geom.MRectangle class MainColorPicker : Scene() { override suspend fun SContainer.sceneMain() { @@ -22,7 +22,7 @@ class MainColorPicker : Scene() { mouse { move { - val bmp = stage!!.unsafeRenderToBitmapSync(views!!.renderContext, Rectangle(views.stage.mouseX - 5.0, views.stage.mouseY - 5.0, 10.0, 10.0), views!!.globalToWindowScaleAvg) + val bmp = stage!!.unsafeRenderToBitmapSync(views!!.renderContext, MRectangle(views.stage.mouseX - 5.0, views.stage.mouseY - 5.0, 10.0, 10.0), views!!.globalToWindowScaleAvg) magnifier.bitmap = bmp.slice() invalidateRender() } diff --git a/korge-sandbox/src/commonMain/kotlin/samples/MainCoroutine.kt b/korge-sandbox/src/commonMain/kotlin/samples/MainCoroutine.kt index b9d7220db0..4fe52f39ab 100644 --- a/korge-sandbox/src/commonMain/kotlin/samples/MainCoroutine.kt +++ b/korge-sandbox/src/commonMain/kotlin/samples/MainCoroutine.kt @@ -8,7 +8,7 @@ import com.soywiz.korge.view.position import com.soywiz.korge.view.solidRect import com.soywiz.korim.color.Colors import com.soywiz.korio.async.launchImmediately -import com.soywiz.korma.geom.Point +import com.soywiz.korma.geom.MPoint import com.soywiz.korma.random.get import kotlin.random.Random @@ -26,7 +26,7 @@ class MainCoroutine : ScaledScene(512, 512) { val targetX = random[0, 512].toDouble() val targetY = random[0, 512].toDouble() - while (Point.distance(view.x, view.y, targetX, targetY) > 5.0) { + while (MPoint.distance(view.x, view.y, targetX, targetY) > 5.0) { when { view.x < targetX -> view.x += 2 view.x > targetX -> view.x -= 2 diff --git a/korge-sandbox/src/commonMain/kotlin/samples/MainGpuVectorRendering.kt b/korge-sandbox/src/commonMain/kotlin/samples/MainGpuVectorRendering.kt index 4f76144f6b..6c7d4e007b 100644 --- a/korge-sandbox/src/commonMain/kotlin/samples/MainGpuVectorRendering.kt +++ b/korge-sandbox/src/commonMain/kotlin/samples/MainGpuVectorRendering.kt @@ -8,7 +8,6 @@ import com.soywiz.korge.input.* import com.soywiz.korge.scene.Scene import com.soywiz.korge.ui.uiButton import com.soywiz.korge.view.* -import com.soywiz.korge.view.filter.* import com.soywiz.korge.view.vector.* import com.soywiz.korim.bitmap.* import com.soywiz.korim.color.* @@ -148,7 +147,7 @@ class MainGpuVectorRendering : Scene() { globalAlpha = 0.75 fillStyle = BitmapPaint( korgeBitmap, - Matrix().translate(50, 50).scale(0.125), + MMatrix().translate(50, 50).scale(0.125), cycleX = CycleMethod.REPEAT, cycleY = CycleMethod.REPEAT ) @@ -159,7 +158,7 @@ class MainGpuVectorRendering : Scene() { globalAlpha = 0.9 fillStyle = //createLinearGradient(150.0, 0.0, 200.0, 50.0) - createLinearGradient(0.0, 0.0, 100.0, 100.0, transform = Matrix().scale(0.5).pretranslate(300, 0)) + createLinearGradient(0.0, 0.0, 100.0, 100.0, transform = MMatrix().scale(0.5).pretranslate(300, 0)) //.addColorStop(0.0, Colors.BLACK).addColorStop(1.0, Colors.WHITE) .addColorStop(0.0, Colors.RED).addColorStop(0.5, Colors.GREEN).addColorStop(1.0, Colors.BLUE) clip({ diff --git a/korge-sandbox/src/commonMain/kotlin/samples/MainGpuVectorRendering3.kt b/korge-sandbox/src/commonMain/kotlin/samples/MainGpuVectorRendering3.kt index 04dbd5db63..6c8ddd034d 100644 --- a/korge-sandbox/src/commonMain/kotlin/samples/MainGpuVectorRendering3.kt +++ b/korge-sandbox/src/commonMain/kotlin/samples/MainGpuVectorRendering3.kt @@ -14,13 +14,12 @@ import com.soywiz.korim.color.Colors import com.soywiz.korim.text.TextAlignment import com.soywiz.korim.vector.format.pathSvg import com.soywiz.korma.geom.IPoint -import com.soywiz.korma.geom.Matrix -import com.soywiz.korma.geom.Point -import com.soywiz.korma.geom.Rectangle +import com.soywiz.korma.geom.MMatrix +import com.soywiz.korma.geom.MPoint +import com.soywiz.korma.geom.MRectangle import com.soywiz.korma.geom.bezier.StrokePointsMode import com.soywiz.korma.geom.bezier.toStrokePointsList import com.soywiz.korma.geom.degrees -import com.soywiz.korma.geom.minus import com.soywiz.korma.geom.shape.buildVectorPath import com.soywiz.korma.geom.shape.getPoints2List import com.soywiz.korma.geom.vector.LineJoin @@ -50,7 +49,7 @@ class MainGpuVectorRendering3 : Scene() { }.xy(pos) //debugVertexView(pointsList.map { it.vector }, type = AGDrawType.POINTS) - text(desc, alignment = TextAlignment.BASELINE_LEFT).xy(pos - Point(0, 8)) + text(desc, alignment = TextAlignment.BASELINE_LEFT).xy(pos - MPoint(0, 8)) debugVertexView(path.getPoints2List(), color = Colors.YELLOWGREEN, type = AGDrawType.LINE_STRIP).xy(pos).apply { keys { @@ -74,7 +73,7 @@ class MainGpuVectorRendering3 : Scene() { val sx = index * 430 + 15 fun getPos(x: Int, y: Int): IPoint { - return Point(sx + x * 120, 50 + y * 130) + return MPoint(sx + x * 120, 50 + y * 130) } text("${strokeInfo.join}", color = Colors.YELLOWGREEN).xy(sx, 10) @@ -107,7 +106,7 @@ class MainGpuVectorRendering3 : Scene() { }) debugPath("Rect closed", getPos(0, 1), strokeInfo, buildVectorPath { - rect(Rectangle.fromBounds(0, 0, 100, 100)) + rect(MRectangle.fromBounds(0, 0, 100, 100)) }) debugPath("Rect not closed", getPos(1, 1), strokeInfo, buildVectorPath { @@ -153,7 +152,7 @@ class MainGpuVectorRendering3 : Scene() { debugPath("Shape", getPos(2, 4), strokeInfo, buildVectorPath { pathSvg( "m262.15-119.2s2.05-8-2.35-3.6c0,0-6.4,5.2-13.2,5.2,0,0-13.2,2-17.2,14,0,0-3.6,24.4,3.6,29.6,0,0,4.4,6.8,10.8,0.8s20.35-33.6,18.35-46z", - Matrix().setTransform(x = -200.0, y = 150.0).scale(1.2) + MMatrix().setTransform(x = -200.0, y = 150.0).scale(1.2) ) }) } diff --git a/korge-sandbox/src/commonMain/kotlin/samples/MainImageTrace.kt b/korge-sandbox/src/commonMain/kotlin/samples/MainImageTrace.kt index 7ca9280ec8..4ad71ec6cb 100644 --- a/korge-sandbox/src/commonMain/kotlin/samples/MainImageTrace.kt +++ b/korge-sandbox/src/commonMain/kotlin/samples/MainImageTrace.kt @@ -11,7 +11,7 @@ import com.soywiz.korim.bitmap.Bitmap32 import com.soywiz.korim.bitmap.context2d import com.soywiz.korim.bitmap.trace.trace import com.soywiz.korim.color.Colors -import com.soywiz.korma.geom.Rectangle +import com.soywiz.korma.geom.MRectangle import com.soywiz.korma.geom.vector.Winding import com.soywiz.korma.geom.vector.circle import com.soywiz.korma.geom.vector.rect @@ -23,10 +23,10 @@ class MainImageTrace : Scene() { override suspend fun SContainer.sceneMain() { val bmp = Bitmap32(300, 200).context2d { fill(Colors.WHITE, winding = Winding.EVEN_ODD) { - rect(Rectangle.fromBounds(2, 2, 18, 18)) - rectHole(Rectangle.fromBounds(6, 6, 9, 12)) - rectHole(Rectangle.fromBounds(10, 5, 15, 12)) - rect(Rectangle.fromBounds(50, 2, 68, 18)) + rect(MRectangle.fromBounds(2, 2, 18, 18)) + rectHole(MRectangle.fromBounds(6, 6, 9, 12)) + rectHole(MRectangle.fromBounds(10, 5, 15, 12)) + rect(MRectangle.fromBounds(50, 2, 68, 18)) circle(100, 100, 60) circle(100, 100, 30) roundRect(200, 50, 50, 50, 5, 5) diff --git a/korge-sandbox/src/commonMain/kotlin/samples/MainMSDF.kt b/korge-sandbox/src/commonMain/kotlin/samples/MainMSDF.kt index 084c6ec1c6..7f5ce1f35c 100644 --- a/korge-sandbox/src/commonMain/kotlin/samples/MainMSDF.kt +++ b/korge-sandbox/src/commonMain/kotlin/samples/MainMSDF.kt @@ -120,7 +120,7 @@ class MainMSDF : Scene() { solidRect(300, 100, Colors.DARKGREY) if (n == 0) { text("HELLO WORLD áéúóúñ cooool", textSize = 32.0, font = font1).also { - it.setTextBounds(Rectangle(0, 0, 300, 100)) + it.setTextBounds(MRectangle(0, 0, 300, 100)) it.alignment = TextAlignment.MIDDLE_CENTER } } else { diff --git a/korge-sandbox/src/commonMain/kotlin/samples/MainMasks.kt b/korge-sandbox/src/commonMain/kotlin/samples/MainMasks.kt index 47cc9df420..fb83661e62 100644 --- a/korge-sandbox/src/commonMain/kotlin/samples/MainMasks.kt +++ b/korge-sandbox/src/commonMain/kotlin/samples/MainMasks.kt @@ -69,7 +69,7 @@ class MainMasks : Scene() { circle(width * 0.5, height * 0.5, 300.0) } animate(looped = true) { - tween(circle3::pos[path], time = 2.seconds, easing = Easing.LINEAR) + tween(circle3::ipos[path], time = 2.seconds, easing = Easing.LINEAR) } } diff --git a/korge-sandbox/src/commonMain/kotlin/samples/MainOnScreenController.kt b/korge-sandbox/src/commonMain/kotlin/samples/MainOnScreenController.kt index 8dc381861d..3224fdbbf2 100644 --- a/korge-sandbox/src/commonMain/kotlin/samples/MainOnScreenController.kt +++ b/korge-sandbox/src/commonMain/kotlin/samples/MainOnScreenController.kt @@ -5,7 +5,6 @@ import com.soywiz.kmem.* import com.soywiz.korev.* import com.soywiz.korge.component.* import com.soywiz.korge.input.* -import com.soywiz.korge.scene.ScaledScene import com.soywiz.korge.view.* import com.soywiz.korim.color.* import com.soywiz.korio.util.toStringDecimal @@ -79,7 +78,7 @@ class MainOnScreenController : Scene() { } var dragging = false - val start = Point(0, 0) + val start = MPoint(0, 0) view.addComponent(object : MouseComponent { override val view: View = view diff --git a/korge-sandbox/src/commonMain/kotlin/samples/MainRotatedTexture.kt b/korge-sandbox/src/commonMain/kotlin/samples/MainRotatedTexture.kt index 92a869af61..60e6dc9cf1 100644 --- a/korge-sandbox/src/commonMain/kotlin/samples/MainRotatedTexture.kt +++ b/korge-sandbox/src/commonMain/kotlin/samples/MainRotatedTexture.kt @@ -3,10 +3,9 @@ package samples import com.soywiz.korge.scene.Scene import com.soywiz.korge.view.SContainer import com.soywiz.korge.view.image -import com.soywiz.korim.bitmap.* import com.soywiz.korim.format.readBitmapSlice import com.soywiz.korio.file.std.resourcesVfs -import com.soywiz.korma.geom.Matrix +import com.soywiz.korma.geom.MMatrix import com.soywiz.korma.geom.degrees import com.soywiz.korma.geom.slice.* @@ -16,7 +15,7 @@ class MainRotatedTexture : Scene() { //val tex = resourcesVfs["korim.png"].readBitmapSlice().flipY() //val tex = resourcesVfs["korim.png"].readBitmapSlice().transformed(Matrix().scale(.5f, .5f)).sliceWithSize(0, 0, 10, 10) //val tex = resourcesVfs["korim.png"].readBitmapSlice().transformed(Matrix().scale(.5f, .5f)) - val tex = resourcesVfs["korim.png"].readBitmapSlice().transformed(Matrix().skew(30.degrees, 0.degrees)).flippedX().rotatedRight() + val tex = resourcesVfs["korim.png"].readBitmapSlice().transformed(MMatrix().skew(30.degrees, 0.degrees)).flippedX().rotatedRight() println("tex=$tex") println("size=${tex.width},${tex.height}") image(tex) diff --git a/korge-sandbox/src/commonMain/kotlin/samples/MainSDF.kt b/korge-sandbox/src/commonMain/kotlin/samples/MainSDF.kt index 6db10b2477..d7b4043221 100644 --- a/korge-sandbox/src/commonMain/kotlin/samples/MainSDF.kt +++ b/korge-sandbox/src/commonMain/kotlin/samples/MainSDF.kt @@ -24,7 +24,7 @@ class MainSDF : Scene() { open class CircleSDFView(width: Double = 100.0, height: Double = 100.0) : ShadedView(PROGRAM, width, height) { var radius = 0.49 var feather = 0.005 - var center = Point(0.5, 0.5) + var center = MPoint(0.5, 0.5) var time = 0.0 init { diff --git a/korge-sandbox/src/commonMain/kotlin/samples/MainStrokesExperiment3.kt b/korge-sandbox/src/commonMain/kotlin/samples/MainStrokesExperiment3.kt index b6b9161a4d..36f3cb451d 100644 --- a/korge-sandbox/src/commonMain/kotlin/samples/MainStrokesExperiment3.kt +++ b/korge-sandbox/src/commonMain/kotlin/samples/MainStrokesExperiment3.kt @@ -279,8 +279,8 @@ class MainStrokesExperiment : Scene() { val circle = circle(16.0, Colors.PURPLE).centered launchImmediately { while (true) { - circle.tween(circle::pos.get(path, includeLastPoint = true, reversed = false), time = 5.seconds, easing = Easing.LINEAR) - circle.tween(circle::pos.get(path, includeLastPoint = true, reversed = true), time = 5.seconds, easing = Easing.LINEAR) + circle.tween(circle::ipos.get(path, includeLastPoint = true, reversed = false), time = 5.seconds, easing = Easing.LINEAR) + circle.tween(circle::ipos.get(path, includeLastPoint = true, reversed = true), time = 5.seconds, easing = Easing.LINEAR) } } diff --git a/korge-sandbox/src/commonMain/kotlin/samples/MainTextMetrics.kt b/korge-sandbox/src/commonMain/kotlin/samples/MainTextMetrics.kt index 729311543c..965a053167 100644 --- a/korge-sandbox/src/commonMain/kotlin/samples/MainTextMetrics.kt +++ b/korge-sandbox/src/commonMain/kotlin/samples/MainTextMetrics.kt @@ -70,7 +70,7 @@ class MainTextMetrics : Scene() { val baseAscent = solidRect(960 + 1200, 1, Colors.BLUE) val baseDescent = solidRect(960 + 1200, 1, Colors.PURPLE) - var cachedBounds: Rectangle? = null + var cachedBounds: MRectangle? = null fun updateBounds() { val currentBounds = text1.getLocalBounds() if (cachedBounds != currentBounds) { diff --git a/korge-sandbox/src/commonMain/kotlin/samples/MainTilemapTest.kt b/korge-sandbox/src/commonMain/kotlin/samples/MainTilemapTest.kt index c492ccab2a..0cf3be0d15 100644 --- a/korge-sandbox/src/commonMain/kotlin/samples/MainTilemapTest.kt +++ b/korge-sandbox/src/commonMain/kotlin/samples/MainTilemapTest.kt @@ -12,7 +12,7 @@ import com.soywiz.korim.color.* import com.soywiz.korim.tiles.* import com.soywiz.korio.util.* import com.soywiz.korma.geom.* -import com.soywiz.korma.geom.Point.Companion.Zero +import com.soywiz.korma.geom.MPoint.Companion.Zero import kotlin.math.* import kotlin.random.* @@ -55,9 +55,9 @@ class MainTilemapTest : Scene() { var wasDown = false val downVals = object { - var mouse: Point = Point() + var mouse: MPoint = MPoint() var camAngle: Angle = 0.degrees - var camPos: Point = Point() + var camPos: MPoint = MPoint() } addUpdater { @@ -68,7 +68,7 @@ class MainTilemapTest : Scene() { wasDown = true downVals.mouse.copyFrom(input.mouse) downVals.camAngle = cameraContainer.cameraAngle - downVals.camPos = Point(cameraContainer.cameraX, cameraContainer.cameraY) + downVals.camPos = MPoint(cameraContainer.cameraX, cameraContainer.cameraY) } else { val rightMouse = (mouseButtons and 4) != 0 if (rightMouse) { @@ -106,9 +106,9 @@ class MainTilemapTest : Scene() { ): IntArray2 { val rand = Random(3) val mapValues2 = IntArray2(mapWidth, mapWidth, 0) - val center = Point(mapWidth / 2, mapWidth / 2) + val center = MPoint(mapWidth / 2, mapWidth / 2) for (x in 0 until mapWidth) for (y in 0 until mapWidth) { - val p = Point(x, y) + val p = MPoint(x, y) val dist = (p - center).length val onDisc = dist < mapWidth / 2 val tooClose = dist < (mapWidth / 2) * 0.7 diff --git a/korge-sandbox/src/commonMain/kotlin/samples/MainTriangulation.kt b/korge-sandbox/src/commonMain/kotlin/samples/MainTriangulation.kt index f83bc2e932..24d37d03c2 100644 --- a/korge-sandbox/src/commonMain/kotlin/samples/MainTriangulation.kt +++ b/korge-sandbox/src/commonMain/kotlin/samples/MainTriangulation.kt @@ -8,13 +8,12 @@ import com.soywiz.korge.view.graphics import com.soywiz.korge.view.position import com.soywiz.korge.view.textOld import com.soywiz.korim.color.Colors -import com.soywiz.korma.geom.Point +import com.soywiz.korma.geom.MPoint import com.soywiz.korma.geom.vector.StrokeInfo import com.soywiz.korma.geom.vector.circle import com.soywiz.korma.geom.vector.line import com.soywiz.korma.geom.vector.lineTo import com.soywiz.korma.geom.vector.moveTo -import com.soywiz.korma.triangle.poly2tri.Poly2Tri import com.soywiz.korma.triangle.triangulate.triangulate class MainTriangulation : Scene() { @@ -25,9 +24,9 @@ class MainTriangulation : Scene() { //val g = cpuGraphics() g.position(100, 100) - val points = arrayListOf() + val points = arrayListOf() - var additionalPoint: Point? = null + var additionalPoint: MPoint? = null fun repaint(finished: Boolean) { g.updateShape { @@ -54,9 +53,9 @@ class MainTriangulation : Scene() { if (points.size >= 3) { for (triangle in points.triangulate()) { fill(Colors.GREEN.withAd(0.2)) { - val p0 = Point(triangle.p0) - val p1 = Point(triangle.p1) - val p2 = Point(triangle.p2) + val p0 = MPoint(triangle.p0) + val p1 = MPoint(triangle.p1) + val p2 = MPoint(triangle.p2) moveTo(p0) lineTo(p1) lineTo(p2) @@ -65,9 +64,9 @@ class MainTriangulation : Scene() { } stroke(Colors.GREEN, StrokeInfo(thickness = 1.0)) { for (triangle in points.triangulate()) { - val p0 = Point(triangle.p0) - val p1 = Point(triangle.p1) - val p2 = Point(triangle.p2) + val p0 = MPoint(triangle.p0) + val p1 = MPoint(triangle.p1) + val p2 = MPoint(triangle.p2) line(p0, p1) line(p1, p2) line(p2, p0) @@ -76,8 +75,8 @@ class MainTriangulation : Scene() { } for (n in 0 until edges.size - 1) { - val e0 = Point(edges[n]) - val e1 = Point(edges[n + 1]) + val e0 = MPoint(edges[n]) + val e1 = MPoint(edges[n + 1]) val last = n == edges.size - 2 stroke(if (last) Colors.RED else Colors.BLUE, StrokeInfo(thickness = 2.0)) { line(e0, e1) diff --git a/korge-sandbox/src/commonMain/kotlin/samples/MainTweenPoint.kt b/korge-sandbox/src/commonMain/kotlin/samples/MainTweenPoint.kt index 870709b1a3..7f462048c2 100644 --- a/korge-sandbox/src/commonMain/kotlin/samples/MainTweenPoint.kt +++ b/korge-sandbox/src/commonMain/kotlin/samples/MainTweenPoint.kt @@ -42,7 +42,7 @@ class MainTweenPoint : Scene() { image(tex).scale(0.2) launch { while (true) { - tween(circle::pos[path, false], time = 1.0.seconds, easing = Easing.LINEAR) + tween(circle::ipos[path, false], time = 1.0.seconds, easing = Easing.LINEAR) //circle.xy(0.0, 0.0) } } diff --git a/korge-sandbox/src/commonMain/kotlin/samples/MainVector.kt b/korge-sandbox/src/commonMain/kotlin/samples/MainVector.kt index b656f9c3d1..9327b47c2b 100644 --- a/korge-sandbox/src/commonMain/kotlin/samples/MainVector.kt +++ b/korge-sandbox/src/commonMain/kotlin/samples/MainVector.kt @@ -15,7 +15,7 @@ import com.soywiz.korim.paint.LinearGradientPaint import com.soywiz.korim.paint.RadialGradientPaint import com.soywiz.korio.async.launchImmediately import com.soywiz.korio.file.std.resourcesVfs -import com.soywiz.korma.geom.Matrix +import com.soywiz.korma.geom.MMatrix import com.soywiz.korma.geom.cosine import com.soywiz.korma.geom.degrees import com.soywiz.korma.geom.sine @@ -82,7 +82,7 @@ class MainVector : ScaledScene(1280, 720) { } keep { translate(356, 320) - fill(BitmapPaint(image, Matrix().scale(0.25, 0.25))) { + fill(BitmapPaint(image, MMatrix().scale(0.25, 0.25))) { rect(0, 0, 128, 128) } } diff --git a/korge-sandbox/src/commonMain/kotlin/samples/MainVectorFill.kt b/korge-sandbox/src/commonMain/kotlin/samples/MainVectorFill.kt index 175d6b7370..253a9e57d7 100644 --- a/korge-sandbox/src/commonMain/kotlin/samples/MainVectorFill.kt +++ b/korge-sandbox/src/commonMain/kotlin/samples/MainVectorFill.kt @@ -13,7 +13,7 @@ import com.soywiz.korim.paint.toPaint import com.soywiz.korim.vector.EmptyShape import com.soywiz.korim.vector.ShapeBuilder import com.soywiz.korio.file.std.resourcesVfs -import com.soywiz.korma.geom.Matrix +import com.soywiz.korma.geom.MMatrix import com.soywiz.korma.geom.vector.rect class MainVectorFill : Scene() { @@ -32,7 +32,7 @@ class MainVectorFill : Scene() { rect(0, 0, 512, 512) } - fill(bitmap.toPaint(Matrix().pretranslate(0, 100).prescale(100.0 / 512.0))) { + fill(bitmap.toPaint(MMatrix().pretranslate(0, 100).prescale(100.0 / 512.0))) { rect(0, 100, 100, 100) } diff --git a/korge-sandbox/src/commonMain/kotlin/samples/MainVectorRendering.kt b/korge-sandbox/src/commonMain/kotlin/samples/MainVectorRendering.kt index 59ff0c5d5b..153582951b 100644 --- a/korge-sandbox/src/commonMain/kotlin/samples/MainVectorRendering.kt +++ b/korge-sandbox/src/commonMain/kotlin/samples/MainVectorRendering.kt @@ -19,7 +19,7 @@ class MainVectorRendering : Scene() { translate(100, 100) scale(2.0) globalAlpha = 0.75 - fillStyle = BitmapPaint(korgeBitmap, Matrix().translate(50, 50), cycleX = CycleMethod.REPEAT, cycleY = CycleMethod.REPEAT) + fillStyle = BitmapPaint(korgeBitmap, MMatrix().translate(50, 50), cycleX = CycleMethod.REPEAT, cycleY = CycleMethod.REPEAT) /* fillStyle = createLinearGradient(0.0, 0.0, 200.0, 200.0, transform = Matrix().scale(0.5).pretranslate(30, 30)) .addColorStop(0.0, Colors.RED) diff --git a/korge-sandbox/src/commonMain/kotlin/samples/asteroids/Game.kt b/korge-sandbox/src/commonMain/kotlin/samples/asteroids/Game.kt index 5c202afc14..c108aec2f6 100644 --- a/korge-sandbox/src/commonMain/kotlin/samples/asteroids/Game.kt +++ b/korge-sandbox/src/commonMain/kotlin/samples/asteroids/Game.kt @@ -146,7 +146,7 @@ class Game(val scene: MainAsteroids) { } } -fun View.distanceTo(other: View) = Point.distance(x, y, other.x, other.y) +fun View.distanceTo(other: View) = MPoint.distance(x, y, other.x, other.y) fun View.advance(amount: Double, rot: Angle = (-90).degrees) = this.apply { x += (this.rotation + rot).cosine * amount diff --git a/korge-sandbox/src/commonMain/kotlin/samples/connect4/main.kt b/korge-sandbox/src/commonMain/kotlin/samples/connect4/main.kt index 06e715fbc5..d8c6a6afa1 100644 --- a/korge-sandbox/src/commonMain/kotlin/samples/connect4/main.kt +++ b/korge-sandbox/src/commonMain/kotlin/samples/connect4/main.kt @@ -14,16 +14,13 @@ import com.soywiz.korge.view.container import com.soywiz.korge.view.image import com.soywiz.korge.view.position import com.soywiz.korge.view.solidRect -import com.soywiz.korge.view.tween.* import com.soywiz.korim.bitmap.Bitmap32 import com.soywiz.korim.bitmap.context2d import com.soywiz.korim.color.ColorAdd import com.soywiz.korim.color.Colors import com.soywiz.korio.async.AsyncThread import com.soywiz.korio.async.launchImmediately -import com.soywiz.korma.geom.Anchor -import com.soywiz.korma.geom.Point -import com.soywiz.korma.geom.ScaleMode +import com.soywiz.korma.geom.MPoint import com.soywiz.korma.geom.vector.circle import com.soywiz.korma.geom.vector.rect @@ -66,8 +63,8 @@ class MainConnect4 : ScaledScene(448, 384) { } image(skeleton) - fun getPosition(column: Int, row: Int): Point { - return Point(column * 64.0 + 32.0, row * 64.0 + 32.0) + fun getPosition(column: Int, row: Int): MPoint { + return MPoint(column * 64.0 + 32.0, row * 64.0 + 32.0) } fun createChip(column: Int, row: Int, chip: Chip): Image { diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/Korge.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/Korge.kt index 8b5c0a21ab..c17661c2ea 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/Korge.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/Korge.kt @@ -63,7 +63,7 @@ import com.soywiz.korio.resources.Resources import com.soywiz.korio.util.OS import com.soywiz.korma.geom.Anchor import com.soywiz.korma.geom.ISizeInt -import com.soywiz.korma.geom.Point +import com.soywiz.korma.geom.MPoint import com.soywiz.korma.geom.ScaleMode import com.soywiz.korma.geom.SizeInt import kotlinx.coroutines.CompletableDeferred @@ -307,8 +307,8 @@ object Korge { val input = views.input val ag = views.ag - val downPos = Point() - val upPos = Point() + val downPos = MPoint() + val upPos = MPoint() var downTime = DateTime.EPOCH var moveTime = DateTime.EPOCH var upTime = DateTime.EPOCH @@ -316,9 +316,9 @@ object Korge { val mouseTouchId = -1 views.forceRenderEveryFrame = forceRenderEveryFrame - val tempXY: Point = Point() + val tempXY: MPoint = MPoint() // devicePixelRatio might change at runtime by changing the resolution or changing the screen of the window - fun getRealXY(x: Double, y: Double, scaleCoords: Boolean, out: Point = tempXY): Point { + fun getRealXY(x: Double, y: Double, scaleCoords: Boolean, out: MPoint = tempXY): MPoint { return views.windowToGlobalCoords(x, y, out) } diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/animate/Animator.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/animate/Animator.kt index 1a75db2bc1..f11e49c053 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/animate/Animator.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/animate/Animator.kt @@ -413,11 +413,11 @@ fun Animator.moveToWithSpeed(view: View, x: Double, y: Double, speed: Double = t fun Animator.moveToWithSpeed(view: View, x: Float, y: Float, speed: Number = this.defaultSpeed, easing: Easing = this.defaultEasing) = moveToWithSpeed(view, x.toDouble(), y.toDouble(), speed.toDouble(), easing) fun Animator.moveToWithSpeed(view: View, x: Int, y: Int, speed: Number = this.defaultSpeed, easing: Easing = this.defaultEasing) = moveToWithSpeed(view, x.toDouble(), y.toDouble(), speed.toDouble(), easing) -fun Animator.moveInPath(view: View, path: VectorPath, includeLastPoint: Boolean = true, time: TimeSpan = this.defaultTime, lazyTime: (() -> TimeSpan)? = null, easing: Easing = this.defaultEasing) = __tween({ view::pos.get(path, includeLastPoint = includeLastPoint) }, time = time, lazyTime = lazyTime, easing = easing, name = "moveInPath") -fun Animator.moveInPath(view: View, points: IPointArrayList, time: TimeSpan = this.defaultTime, lazyTime: (() -> TimeSpan)? = null, easing: Easing = this.defaultEasing) = __tween({ view::pos[points] }, time = time, lazyTime = lazyTime, easing = easing, name = "moveInPath") +fun Animator.moveInPath(view: View, path: VectorPath, includeLastPoint: Boolean = true, time: TimeSpan = this.defaultTime, lazyTime: (() -> TimeSpan)? = null, easing: Easing = this.defaultEasing) = __tween({ view::ipos.get(path, includeLastPoint = includeLastPoint) }, time = time, lazyTime = lazyTime, easing = easing, name = "moveInPath") +fun Animator.moveInPath(view: View, points: IPointArrayList, time: TimeSpan = this.defaultTime, lazyTime: (() -> TimeSpan)? = null, easing: Easing = this.defaultEasing) = __tween({ view::ipos[points] }, time = time, lazyTime = lazyTime, easing = easing, name = "moveInPath") -fun Animator.moveInPathWithSpeed(view: View, path: VectorPath, includeLastPoint: Boolean = true, speed: () -> Number = { this.defaultSpeed }, easing: Easing = this.defaultEasing) = __tween({ view::pos.get(path, includeLastPoint = includeLastPoint) }, lazyTime = { (path.length / speed().toDouble()).seconds }, easing = easing, name = "moveInPathWithSpeed") -fun Animator.moveInPathWithSpeed(view: View, points: IPointArrayList, speed: () -> Number = { this.defaultSpeed }, easing: Easing = this.defaultEasing) = __tween({ view::pos[points] }, lazyTime = { (points.length / speed().toDouble()).seconds }, easing = easing, name = "moveInPathWithSpeed") +fun Animator.moveInPathWithSpeed(view: View, path: VectorPath, includeLastPoint: Boolean = true, speed: () -> Number = { this.defaultSpeed }, easing: Easing = this.defaultEasing) = __tween({ view::ipos.get(path, includeLastPoint = includeLastPoint) }, lazyTime = { (path.length / speed().toDouble()).seconds }, easing = easing, name = "moveInPathWithSpeed") +fun Animator.moveInPathWithSpeed(view: View, points: IPointArrayList, speed: () -> Number = { this.defaultSpeed }, easing: Easing = this.defaultEasing) = __tween({ view::ipos[points] }, lazyTime = { (points.length / speed().toDouble()).seconds }, easing = easing, name = "moveInPathWithSpeed") fun Animator.alpha(view: View, alpha: Double, time: TimeSpan = this.defaultTime, easing: Easing = this.defaultEasing) = __tween(view::alpha[alpha], time = time, easing = easing, name = "alpha") fun Animator.alpha(view: View, alpha: Float, time: TimeSpan = this.defaultTime, easing: Easing = this.defaultEasing) = alpha(view, alpha.toDouble(), time, easing) @@ -432,7 +432,7 @@ fun Animator.hide(view: View, time: TimeSpan = this.defaultTime, easing: Easing private val VectorPath.length: Double get() = getCurves().length private val IPointArrayList.length: Double get() { var sum = 0.0 - for (n in 1 until size) sum += Point.distance(getX(n - 1), getY(n - 1), getX(n), getY(n)) + for (n in 1 until size) sum += MPoint.distance(getX(n - 1), getY(n - 1), getX(n), getY(n)) return sum } diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/bitmapfont/BitmapFontExt.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/bitmapfont/BitmapFontExt.kt index fec8254f69..4e31910bee 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/bitmapfont/BitmapFontExt.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/bitmapfont/BitmapFontExt.kt @@ -9,11 +9,11 @@ import com.soywiz.korim.color.RGBA import com.soywiz.korim.font.BitmapFont import com.soywiz.korim.font.Font import com.soywiz.korim.font.GlyphMetrics -import com.soywiz.korma.geom.Matrix -import com.soywiz.korma.geom.Rectangle +import com.soywiz.korma.geom.MMatrix +import com.soywiz.korma.geom.MRectangle import kotlin.math.max -fun Font.getBounds(text: String, format: Html.Format, out: Rectangle = Rectangle()): Rectangle { +fun Font.getBounds(text: String, format: Html.Format, out: MRectangle = MRectangle()): MRectangle { //val font = getBitmapFont(format.computedFace, format.computedSize) val font = this val textSize = format.computedSize.toDouble() @@ -46,16 +46,16 @@ fun Font.getBounds(text: String, format: Html.Format, out: Rectangle = Rectangle } fun BitmapFont.drawText( - ctx: RenderContext, - textSize: Double, - str: String, - x: Int, - y: Int, - m: Matrix = Matrix(), - colMul: RGBA = Colors.WHITE, - colAdd: ColorAdd = ColorAdd.NEUTRAL, - blendMode: BlendMode = BlendMode.INHERIT, - filtering: Boolean = true + ctx: RenderContext, + textSize: Double, + str: String, + x: Int, + y: Int, + m: MMatrix = MMatrix(), + colMul: RGBA = Colors.WHITE, + colAdd: ColorAdd = ColorAdd.NEUTRAL, + blendMode: BlendMode = BlendMode.INHERIT, + filtering: Boolean = true ) { val m2 = m.clone() val scale = textSize / fontSize.toDouble() @@ -95,16 +95,16 @@ fun BitmapFont.drawText( } fun RenderContext.drawText( - font: BitmapFont, - textSize: Double, - str: String, - x: Int, - y: Int, - m: Matrix = Matrix(), - colMul: RGBA = Colors.WHITE, - colAdd: ColorAdd = ColorAdd.NEUTRAL, - blendMode: BlendMode = BlendMode.INHERIT, - filtering: Boolean = true + font: BitmapFont, + textSize: Double, + str: String, + x: Int, + y: Int, + m: MMatrix = MMatrix(), + colMul: RGBA = Colors.WHITE, + colAdd: ColorAdd = ColorAdd.NEUTRAL, + blendMode: BlendMode = BlendMode.INHERIT, + filtering: Boolean = true ) { font.drawText(this, textSize, str, x, y, m, colMul, colAdd, blendMode, filtering) } diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/component/docking/DockingComponent.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/component/docking/DockingComponent.kt index 67a11a27e2..8d42b809e4 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/component/docking/DockingComponent.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/component/docking/DockingComponent.kt @@ -6,13 +6,13 @@ import com.soywiz.korge.view.View import com.soywiz.korge.view.Views import com.soywiz.korge.view.position import com.soywiz.korma.geom.Anchor -import com.soywiz.korma.geom.Point +import com.soywiz.korma.geom.MPoint import com.soywiz.korma.geom.ScaleMode -import com.soywiz.korma.geom.Size +import com.soywiz.korma.geom.MSize import com.soywiz.korma.interpolation.interpolate -fun T.dockedTo(anchor: Anchor, scaleMode: ScaleMode = ScaleMode.NO_SCALE, offset: Point = Point(), hook: (View) -> Unit = {}): T { - DockingComponent(this, anchor, scaleMode, Point().copyFrom(offset), hook).attach() +fun T.dockedTo(anchor: Anchor, scaleMode: ScaleMode = ScaleMode.NO_SCALE, offset: MPoint = MPoint(), hook: (View) -> Unit = {}): T { + DockingComponent(this, anchor, scaleMode, MPoint().copyFrom(offset), hook).attach() return this } @@ -20,13 +20,13 @@ class DockingComponent( override val view: View, var anchor: Anchor, var scaleMode: ScaleMode = ScaleMode.NO_SCALE, - val offset: Point = Point(), + val offset: MPoint = MPoint(), val hook: (View) -> Unit ) : ResizeComponent { - val initialViewSize = Size(view.width, view.height) - private val actualVirtualSize = Size(0, 0) - private val targetSize = Size(0, 0) + val initialViewSize = MSize(view.width, view.height) + private val actualVirtualSize = MSize(0, 0) + private val targetSize = MSize(0, 0) init { view.deferWithViews { views -> diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/component/length/BindLengthComponent.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/component/length/BindLengthComponent.kt index 8b8d12fc15..69dcf41e84 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/component/length/BindLengthComponent.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/component/length/BindLengthComponent.kt @@ -125,7 +125,7 @@ internal class BindLengthComponent(override val view: BaseView) : UpdateComponen } } - private val tempTransform = Matrix.Transform() + private val tempTransform = MMatrix.Transform() override fun update(views: Views, dt: TimeSpan) { this.views = views val container = (view as? View?)?.parent ?: views.stage diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/html/Html.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/html/Html.kt index b63e626f44..b64e354540 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/html/Html.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/html/Html.kt @@ -6,11 +6,9 @@ import com.soywiz.kds.cacheLazyNullable import com.soywiz.kds.iterators.fastForEach import com.soywiz.korge.bitmapfont.getBounds import com.soywiz.korge.scene.debugBmpFontSync -import com.soywiz.korge.ui.DefaultUIFont import com.soywiz.korim.color.Colors import com.soywiz.korim.color.RGBA import com.soywiz.korim.font.BitmapFont -import com.soywiz.korim.font.DefaultFontRegistry import com.soywiz.korim.font.Font import com.soywiz.korim.font.SystemFont import com.soywiz.korim.font.toBitmapFont @@ -57,7 +55,7 @@ object Html { font?.toBitmapFont(32.0) } as? BitmapFont? ?: defaultFont } - override fun getBounds(text: String, format: Format, out: Rectangle) { + override fun getBounds(text: String, format: Format, out: MRectangle) { val font = format.computedFace getBitmapFont(font?.name, font).getBounds(text, format, out) } @@ -103,24 +101,24 @@ object Html { } interface MetricsProvider { - fun getBounds(text: String, format: Format, out: Rectangle): Unit + fun getBounds(text: String, format: Format, out: MRectangle): Unit object Identity : MetricsProvider { - override fun getBounds(text: String, format: Format, out: Rectangle) { + override fun getBounds(text: String, format: Format, out: MRectangle) { out.setTo(0.0, 0.0, text.length.toDouble(), 1.0) } } } data class PositionContext( - val provider: MetricsProvider, - val bounds: Rectangle, - var x: Double = 0.0, - var y: Double = 0.0 + val provider: MetricsProvider, + val bounds: MRectangle, + var x: Double = 0.0, + var y: Double = 0.0 ) data class Span(val format: Format, var text: String) : Extra by Extra.Mixin() { - val bounds = Rectangle() + val bounds = MRectangle() fun doPositioning(ctx: PositionContext) { ctx.provider.getBounds(text, format, bounds) @@ -132,7 +130,7 @@ object Html { data class Line(val spans: ArrayList = arrayListOf()) : Extra by Extra.Mixin() { var format: Format = Format() val firstNonEmptySpan get() = spans.firstOrNull { it.text.isNotEmpty() } - val bounds = Rectangle() + val bounds = MRectangle() fun doPositioning(ctx: PositionContext) { ctx.x = ctx.bounds.x @@ -162,7 +160,7 @@ object Html { data class Paragraph(val lines: ArrayList = arrayListOf()) : Extra by Extra.Mixin() { val firstNonEmptyLine get() = lines.firstOrNull { it.firstNonEmptySpan != null } - val bounds = Rectangle() + val bounds = MRectangle() fun doPositioning(ctx: PositionContext) { lines.fastForEach { v -> @@ -178,13 +176,13 @@ object Html { val defaultFormat = Html.Format() var xml = Xml("") val text: String get() = xml.text.trim() - val bounds = Rectangle() + val bounds = MRectangle() val firstNonEmptyParagraph get() = paragraphs.firstOrNull { it.firstNonEmptyLine != null } val firstNonEmptySpan get() = firstNonEmptyParagraph?.firstNonEmptyLine?.firstNonEmptySpan val firstFormat get() = firstNonEmptySpan?.format ?: Format() val allSpans get() = paragraphs.flatMap { it.lines }.flatMap { it.spans } - fun doPositioning(gp: MetricsProvider, bounds: Rectangle) { + fun doPositioning(gp: MetricsProvider, bounds: MRectangle) { val ctx = PositionContext(gp, bounds) paragraphs.fastForEach { v -> v.doPositioning(ctx) diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/input/Input.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/input/Input.kt index bc38545683..ecb8a8a061 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/input/Input.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/input/Input.kt @@ -17,7 +17,7 @@ import com.soywiz.korev.Touch import com.soywiz.korev.TouchEvent import com.soywiz.korge.internal.KorgeInternal import com.soywiz.korma.geom.IPoint -import com.soywiz.korma.geom.Point +import com.soywiz.korma.geom.MPoint //@Singleton @OptIn(KorgeInternal::class) @@ -57,8 +57,8 @@ class Input : Extra by Extra.Mixin() { var clickDistance = 20.0 // @TODO: We should take into account pointSize/DPI // Mouse coordinates relative to the Stage - private val _mouse: Point = Point(-1000.0, -1000.0) - private val _mouseDown: Point = Point(-1000.0, -1000.0) + private val _mouse: MPoint = MPoint(-1000.0, -1000.0) + private val _mouseDown: MPoint = MPoint(-1000.0, -1000.0) val mouse: IPoint get() = _mouse val mouseDown: IPoint get() = _mouseDown diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/input/MouseDragComponent.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/input/MouseDragComponent.kt index ed7e37c7c8..bd4ce5d9f5 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/input/MouseDragComponent.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/input/MouseDragComponent.kt @@ -7,7 +7,7 @@ import com.soywiz.korge.view.View import com.soywiz.korge.view.Views import com.soywiz.korge.view.xy import com.soywiz.korio.lang.Closeable -import com.soywiz.korma.geom.Point +import com.soywiz.korma.geom.MPoint open class MouseDragInfo( val view: View, @@ -104,7 +104,7 @@ private fun T.onMouseDragInternal( var cy = 0.0 val view = this - val mousePos = Point() + val mousePos = MPoint() fun views() = view.stage!!.views @@ -167,7 +167,7 @@ fun T.onMouseDrag( ): T = onMouseDragInternal(timeProvider, info, callback).first open class DraggableInfo(view: View) : MouseDragInfo(view) { - val viewStartXY = Point() + val viewStartXY = MPoint() var viewStartX: Double get() = viewStartXY.x; @@ -180,7 +180,7 @@ open class DraggableInfo(view: View) : MouseDragInfo(view) { viewStartXY.y = value } - val viewPrevXY = Point() + val viewPrevXY = MPoint() var viewPrevX: Double get() = viewPrevXY.x; @@ -193,7 +193,7 @@ open class DraggableInfo(view: View) : MouseDragInfo(view) { viewPrevXY.y = value } - val viewNextXY = Point() + val viewNextXY = MPoint() var viewNextX: Double get() = viewNextXY.x; @@ -206,7 +206,7 @@ open class DraggableInfo(view: View) : MouseDragInfo(view) { viewNextXY.y = value } - val viewDeltaXY = Point() + val viewDeltaXY = MPoint() var viewDeltaX: Double get() = viewDeltaXY.x; @@ -237,10 +237,10 @@ private fun T.draggableInternal( val info = DraggableInfo(view) val onMouseDragCloseable = selector.onMouseDragCloseable(info = info) { if (info.start) { - info.viewStartXY.copyFrom(view.pos) + info.viewStartXY.copyFrom(view.ipos) } //println("localDXY=${info.localDX(view)},${info.localDY(view)}") - info.viewPrevXY.copyFrom(view.pos) + info.viewPrevXY.copyFrom(view.ipos) info.viewNextXY.setTo( info.viewStartX + info.localDX(view), info.viewStartY + info.localDY(view) diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/input/MouseEvents.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/input/MouseEvents.kt index b015eb87ef..2a4716446e 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/input/MouseEvents.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/input/MouseEvents.kt @@ -295,26 +295,26 @@ class MouseEvents(override val view: View) : MouseComponent, Extra by Extra.Mixi // Global variants (Not related to the STAGE! but to the window coordinates, so can't be translated directly use *Stage variants instead or directly Stage.mouseXY!) @KorgeInternal - var downPosGlobal = Point() + var downPosGlobal = MPoint() @KorgeInternal - var upPosGlobal = Point() + var upPosGlobal = MPoint() @KorgeInternal - val startedPosGlobal = Point() + val startedPosGlobal = MPoint() @KorgeInternal - val lastPosGlobal = Point() + val lastPosGlobal = MPoint() @KorgeInternal - val currentPosGlobal = Point() + val currentPosGlobal = MPoint() // Local variants - private val _downPosLocal: Point = Point() - private val _upPosLocal: Point = Point() - private val _startedPosLocal = Point() - private val _lastPosLocal = Point() - private val _currentPosLocal = Point() + private val _downPosLocal: MPoint = MPoint() + private val _upPosLocal: MPoint = MPoint() + private val _startedPosLocal = MPoint() + private val _lastPosLocal = MPoint() + private val _currentPosLocal = MPoint() val startedPosLocal get() = view.globalToLocal(startedPosGlobal, _startedPosLocal) val lastPosLocal get() = view.globalToLocal(lastPosGlobal, _lastPosLocal) @@ -323,11 +323,11 @@ class MouseEvents(override val view: View) : MouseComponent, Extra by Extra.Mixi val upPosLocal get() = view.globalToLocal(upPosGlobal, _upPosLocal) // Stage-based variants - private val _downPosStage: Point = Point() - private val _upPosStage: Point = Point() - private val _startedPosStage = Point() - private val _lastPosStage = Point() - private val _currentPosStage = Point() + private val _downPosStage: MPoint = MPoint() + private val _upPosStage: MPoint = MPoint() + private val _startedPosStage = MPoint() + private val _lastPosStage = MPoint() + private val _currentPosStage = MPoint() val startedPosStage get() = views.stage.globalToLocal(startedPosGlobal, _startedPosStage) val lastPosStage get() = views.stage.globalToLocal(lastPosGlobal, _lastPosStage) diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/input/SwipeComponent.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/input/SwipeComponent.kt index 21939998e5..cdc2630d47 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/input/SwipeComponent.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/input/SwipeComponent.kt @@ -2,7 +2,7 @@ package com.soywiz.korge.input import com.soywiz.korge.view.View import com.soywiz.korge.view.Views -import com.soywiz.korma.geom.Point +import com.soywiz.korma.geom.MPoint import kotlin.math.abs data class SwipeInfo( @@ -47,7 +47,7 @@ fun T.onSwipe( var movedBottom = false val view = this - val mousePos = Point() + val mousePos = MPoint() val swipeInfo = SwipeInfo(0.0, 0.0, SwipeDirection.TOP) fun views() = view.stage!!.views diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/input/TouchEvents.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/input/TouchEvents.kt index 794dd531c6..8c163424f0 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/input/TouchEvents.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/input/TouchEvents.kt @@ -13,11 +13,11 @@ class TouchEvents(override val view: View) : TouchComponent { data class Info( var index: Int = -1, var id: Int = 0, - var local: Point = Point(), - var startLocal: Point = Point(), + var local: MPoint = MPoint(), + var startLocal: MPoint = MPoint(), var startTime: DateTime = DateTime.EPOCH, - var global: Point = Point(), - var startGlobal: Point = Point(), + var global: MPoint = MPoint(), + var startGlobal: MPoint = MPoint(), var time: DateTime = DateTime.EPOCH, ) : Extra by Extra.Mixin() { val elapsedTime get() = time - startTime @@ -181,7 +181,7 @@ fun View.singleTouch(removeTouch: Boolean = false, supportStartAnywhere: Boolean handler.end(it) } handler.endAnywhere(it) - if ((Point.distance(it.startGlobal, it.global) <= it.views.input.clickDistance) && (it.elapsedTime <= it.views.input.clickTime)) { + if ((MPoint.distance(it.startGlobal, it.global) <= it.views.input.clickDistance) && (it.elapsedTime <= it.views.input.clickTime)) { if (info.startedInside && hitTest) { //println("TOUCH END: TAP!") handler.tap(it) diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/input/TouchEventsRecognizers.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/input/TouchEventsRecognizers.kt index 426a859347..536175c9c6 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/input/TouchEventsRecognizers.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/input/TouchEventsRecognizers.kt @@ -1,7 +1,7 @@ package com.soywiz.korge.input import com.soywiz.korma.geom.Angle -import com.soywiz.korma.geom.Point +import com.soywiz.korma.geom.MPoint import com.soywiz.korma.geom.degrees import com.soywiz.korma.geom.minus @@ -27,7 +27,7 @@ fun TouchEvents.swipeRecognizer( if (!completed) { val i = it.infos[0] - val distance = Point.distance(i.startGlobal, i.global) + val distance = MPoint.distance(i.startGlobal, i.global) if (distance >= thresold) { val angle = Angle.between(i.startGlobal, i.global) completed = true @@ -69,8 +69,8 @@ fun TouchEvents.scaleRecognizer( val i1 = it.infos[1] info.started = info.completed info.completed = false - info.start = Point.distance(i0.startGlobal, i1.startGlobal) - info.current = Point.distance(i0.global, i1.global) + info.start = MPoint.distance(i0.startGlobal, i1.startGlobal) + info.current = MPoint.distance(i0.global, i1.global) if (info.started) { start(info) } diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/particle/ParticleEmitter.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/particle/ParticleEmitter.kt index ecded405e2..d99e2861b7 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/particle/ParticleEmitter.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/particle/ParticleEmitter.kt @@ -8,7 +8,7 @@ import com.soywiz.korim.bitmap.BmpSlice import com.soywiz.korim.color.RGBAf import com.soywiz.korma.geom.Angle import com.soywiz.korma.geom.IPoint -import com.soywiz.korma.geom.Point +import com.soywiz.korma.geom.MPoint import com.soywiz.korma.geom.degrees //e: java.lang.UnsupportedOperationException: Class literal annotation arguments are not yet supported: Factory @@ -21,9 +21,9 @@ class ParticleEmitter() { var textureName: String? = null var texture: BmpSlice? = null @ViewProperty - var sourcePosition = Point() + var sourcePosition = MPoint() @ViewProperty - var sourcePositionVariance = Point() + var sourcePositionVariance = MPoint() @ViewProperty var speed = 100.0 @ViewProperty @@ -37,7 +37,7 @@ class ParticleEmitter() { @ViewProperty var angleVariance: Angle = 360.0.degrees @ViewProperty - var gravity = Point() + var gravity = MPoint() @ViewProperty var radialAcceleration = 0.0 @ViewProperty diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/particle/ParticleEmitterRead.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/particle/ParticleEmitterRead.kt index f29c7c7056..7928404e0f 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/particle/ParticleEmitterRead.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/particle/ParticleEmitterRead.kt @@ -11,7 +11,7 @@ import com.soywiz.korim.format.readBitmapSlice import com.soywiz.korio.file.VfsFile import com.soywiz.korio.lang.FileNotFoundException import com.soywiz.korio.serialization.xml.readXml -import com.soywiz.korma.geom.Point +import com.soywiz.korma.geom.MPoint import com.soywiz.korma.geom.degrees import com.soywiz.korma.geom.vector.circle @@ -24,7 +24,7 @@ suspend fun VfsFile.readParticleEmitter(): ParticleEmitter { //var blendFuncDestination = AGBlendFactor.ONE particleXml.allChildrenNoComments.fastForEach { item -> - fun point() = Point(item.double("x"), item.double("y")) + fun point() = MPoint(item.double("x"), item.double("y")) fun scalar() = item.double("value") fun blendFactor() = ParticleEmitter.blendFactorMap[scalar().toInt()] ?: AGBlendFactor.ONE fun type() = ParticleEmitter.typeMap[scalar().toInt()] ?: ParticleEmitter.Type.GRAVITY diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/particle/ParticleEmitterSimulator.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/particle/ParticleEmitterSimulator.kt index 44f428ec98..47377c59c9 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/particle/ParticleEmitterSimulator.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/particle/ParticleEmitterSimulator.kt @@ -3,7 +3,7 @@ package com.soywiz.korge.particle import com.soywiz.klock.TimeSpan import com.soywiz.klock.seconds import com.soywiz.korma.geom.Angle -import com.soywiz.korma.geom.Point +import com.soywiz.korma.geom.MPoint import com.soywiz.korma.geom.cos import com.soywiz.korma.geom.degrees import com.soywiz.korma.geom.div @@ -17,7 +17,7 @@ import kotlin.random.Random class ParticleEmitterSimulator( private val emitter: ParticleEmitter, - var emitterPos: Point = Point(), + var emitterPos: MPoint = MPoint(), val random: Random = Random ) { var totalElapsedTime = 0.seconds @@ -135,8 +135,8 @@ class ParticleEmitterSimulator( ParticleEmitter.Type.RADIAL -> { particle.emitRotation += particle.emitRotationDelta * elapsedTime.toDouble() particle.emitRadius += (particle.emitRadiusDelta * elapsedTime).toFloat() - particle.x = emitter.sourcePosition.xf - cos(particle.emitRotation).toFloat() * particle.emitRadius - particle.y = emitter.sourcePosition.yf - sin(particle.emitRotation).toFloat() * particle.emitRadius + particle.x = emitter.sourcePosition.x.toFloat() - cos(particle.emitRotation).toFloat() * particle.emitRadius + particle.y = emitter.sourcePosition.y.toFloat() - sin(particle.emitRotation).toFloat() * particle.emitRadius } ParticleEmitter.Type.GRAVITY -> { val distanceX = particle.x - particle.startX diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/particle/ParticleEmitterView.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/particle/ParticleEmitterView.kt index 83d81aa75b..13a4d33679 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/particle/ParticleEmitterView.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/particle/ParticleEmitterView.kt @@ -13,8 +13,8 @@ import com.soywiz.korim.format.* import com.soywiz.korio.async.* import com.soywiz.korio.file.* import com.soywiz.korma.geom.IPoint -import com.soywiz.korma.geom.Point -import com.soywiz.korma.geom.Rectangle +import com.soywiz.korma.geom.MPoint +import com.soywiz.korma.geom.MRectangle import kotlinx.coroutines.* import kotlin.random.* @@ -50,7 +50,7 @@ class ParticleEmitterView( localCoords: Boolean = false, random: Random = Random, ) : View(), ViewFileRef by ViewFileRef.Mixin() { - var simulator = ParticleEmitterSimulator(emitter, Point(emitterPos), random) + var simulator = ParticleEmitterSimulator(emitter, MPoint(emitterPos), random) var timeUntilStop by simulator::timeUntilStop var emitting by simulator::emitting @@ -61,12 +61,12 @@ class ParticleEmitterView( min = -1000.0, max = +1000.0, ) - var emitterPos: Point + var emitterPos: MPoint get() = simulator.emitterPos set(value) { simulator.emitterPos.copyFrom(value) } - var emitterXY: Point + var emitterXY: MPoint get() = emitterPos set(value) { emitterPos = value @@ -85,7 +85,7 @@ class ParticleEmitterView( @ViewProperty var localCoords: Boolean = localCoords - private val lastPosition = Point(globalX, globalY) + private val lastPosition = MPoint(globalX, globalY) //override fun setXY(x: Double, y: Double) { // if (localCoords) { @@ -189,7 +189,7 @@ class ParticleEmitterView( private var fsprites: FSprites? = null private val fviewInfo = FSprites.FViewInfo(1) - override fun getLocalBoundsInternal(out: Rectangle) { + override fun getLocalBoundsInternal(out: MRectangle) { out.setBounds(-30, -30, +30, +30) } diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/render/BatchBuilder2D.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/render/BatchBuilder2D.kt index f614ac775c..95205c8572 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/render/BatchBuilder2D.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/render/BatchBuilder2D.kt @@ -44,9 +44,9 @@ class BatchBuilder2D constructor( val maxTextures = BB_MAX_TEXTURES @KorgeInternal - val viewMat: Matrix3D get() = ctx.viewMat + val viewMat: MMatrix3D get() = ctx.viewMat @KorgeInternal - val viewMat2D: Matrix get() = ctx.viewMat2D + val viewMat2D: MMatrix get() = ctx.viewMat2D @KorgeInternal val uniforms: AGUniformValues get() = ctx.uniforms @@ -167,22 +167,22 @@ class BatchBuilder2D constructor( } - private val identity = Matrix() + private val identity = MMatrix() init { logger.trace { "BatchBuilder2D[7]" } } - private val ptt1 = Point() - private val ptt2 = Point() + private val ptt1 = MPoint() + private val ptt2 = MPoint() - private val pt1 = Point() - private val pt2 = Point() - private val pt3 = Point() - private val pt4 = Point() - private val pt5 = Point() + private val pt1 = MPoint() + private val pt2 = MPoint() + private val pt3 = MPoint() + private val pt4 = MPoint() + private val pt5 = MPoint() - private val pt6 = Point() - private val pt7 = Point() - private val pt8 = Point() + private val pt6 = MPoint() + private val pt7 = MPoint() + private val pt8 = MPoint() init { logger.trace { "BatchBuilder2D[8]" } } @@ -385,7 +385,7 @@ class BatchBuilder2D constructor( */ fun drawVertices( array: TexturedVertexArray, - matrix: Matrix?, + matrix: MMatrix?, vcount: Int = array.vcount, icount: Int = array.icount, texIndex: Int = currentTexIndex, @@ -427,7 +427,7 @@ class BatchBuilder2D constructor( indexPos += icount } - private fun applyMatrix(matrix: Matrix, idx: Int, vcount: Int) { + private fun applyMatrix(matrix: MMatrix, idx: Int, vcount: Int) { val f32 = vertices.f32 var idx = idx @@ -441,8 +441,8 @@ class BatchBuilder2D constructor( for (n in 0 until vcount) { val x = f32[idx + 0] val y = f32[idx + 1] - f32[idx + 0] = Matrix.transformXf(ma, mb, mc, md, mtx, mty, x, y) - f32[idx + 1] = Matrix.transformYf(ma, mb, mc, md, mtx, mty, x, y) + f32[idx + 0] = MMatrix.transformXf(ma, mb, mc, md, mtx, mty, x, y) + f32[idx + 1] = MMatrix.transformYf(ma, mb, mc, md, mtx, mty, x, y) idx += VERTEX_INDEX_SIZE } } @@ -452,7 +452,7 @@ class BatchBuilder2D constructor( */ inline fun drawVertices( array: TexturedVertexArray, tex: TextureBase, smoothing: Boolean, blendMode: BlendMode, - vcount: Int = array.vcount, icount: Int = array.icount, program: Program? = null, matrix: Matrix? = null, + vcount: Int = array.vcount, icount: Int = array.icount, program: Program? = null, matrix: MMatrix? = null, premultiplied: Boolean = tex.premultiplied, wrap: Boolean = false ) { setStateFast(tex.base, smoothing, blendMode, program, icount, vcount) @@ -551,7 +551,7 @@ class BatchBuilder2D constructor( /** * Draws/buffers a 9-patch image with the texture [tex] at [x], [y] with the total size of [width] and [height]. - * [posCuts] and [texCuts] are [Point] an array of 4 points describing ratios (values between 0 and 1) inside the width/height of the area to be drawn, + * [posCuts] and [texCuts] are [MPoint] an array of 4 points describing ratios (values between 0 and 1) inside the width/height of the area to be drawn, * and the positions inside the texture. * * The 9-patch looks like this (dividing the image in 9 parts). @@ -581,9 +581,9 @@ class BatchBuilder2D constructor( y: Float, width: Float, height: Float, - posCuts: Array, - texCuts: Array, - m: Matrix = identity, + posCuts: Array, + texCuts: Array, + m: MMatrix = identity, filtering: Boolean = true, colorMul: RGBA = Colors.WHITE, colorAdd: ColorAdd = ColorAdd.NEUTRAL, @@ -659,7 +659,7 @@ class BatchBuilder2D constructor( y: Float = 0f, width: Float = tex.width.toFloat(), height: Float = tex.height.toFloat(), - m: Matrix = identity, + m: MMatrix = identity, filtering: Boolean = true, colorMul: RGBA = Colors.WHITE, colorAdd: ColorAdd = ColorAdd.NEUTRAL, @@ -682,7 +682,7 @@ class BatchBuilder2D constructor( y: Float, width: Float, height: Float, - m: Matrix = identity, + m: MMatrix = identity, filtering: Boolean = true, colorMul: RGBA = Colors.WHITE, colorAdd: ColorAdd = ColorAdd.NEUTRAL, @@ -698,7 +698,7 @@ class BatchBuilder2D constructor( fun drawQuadFast( x: Float, y: Float, width: Float, height: Float, - m: Matrix, + m: MMatrix, tex: BmpCoords, colorMul: RGBA, colorAdd: ColorAdd, premultiplied: Boolean = tex.premultiplied, @@ -963,7 +963,7 @@ class BatchBuilder2D constructor( /** * Executes [callback] while setting temporarily the view matrix to [matrix] */ - inline fun setViewMatrixTemp(matrix: Matrix, crossinline callback: () -> Unit) = ctx.setViewMatrixTemp(matrix, callback) + inline fun setViewMatrixTemp(matrix: MMatrix, crossinline callback: () -> Unit) = ctx.setViewMatrixTemp(matrix, callback) /** * Executes [callback] while restoring [uniform] to its current value after [callback] is exexcuted. diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/render/LineRenderBatcher.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/render/LineRenderBatcher.kt index 4574c9d202..6264c2b283 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/render/LineRenderBatcher.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/render/LineRenderBatcher.kt @@ -21,7 +21,7 @@ import kotlin.native.concurrent.ThreadLocal val RenderContext.debugLineRenderContext: LineRenderBatcher by Extra.PropertyThis { LineRenderBatcher(this) } @Suppress("DEPRECATION") -inline fun RenderContext.useLineBatcher(matrix: Matrix? = null, block: (LineRenderBatcher) -> Unit) = debugLineRenderContext.use { batcher -> +inline fun RenderContext.useLineBatcher(matrix: MMatrix? = null, block: (LineRenderBatcher) -> Unit) = debugLineRenderContext.use { batcher -> debugLineRenderContext.drawWithGlobalMatrix(matrix) { block(batcher) } @@ -82,28 +82,28 @@ class LineRenderBatcher( private val program = Program(VERTEX, FRAGMENT) private val maxVertexCount = 1024 private val vertices = Buffer.allocDirect(6 * 4 * maxVertexCount) - private val tempRect = Rectangle() + private val tempRect = MRectangle() @PublishedApi - internal val viewMat = Matrix3D() + internal val viewMat = MMatrix3D() @PublishedApi - internal val tempViewMat = Pool { Matrix3D() } + internal val tempViewMat = Pool { MMatrix3D() } @PublishedApi internal var vertexCount = 0 @PublishedApi internal var vertexPos = 0 /** Draw a line from [x0],[y0] to [x1],[y1] */ - fun line(x0: Float, y0: Float, x1: Float, y1: Float, color0: RGBA = color, color1: RGBA = color0, m: Matrix = currentMatrix) { + fun line(x0: Float, y0: Float, x1: Float, y1: Float, color0: RGBA = color, color1: RGBA = color0, m: MMatrix = currentMatrix) { if (vertexCount >= maxVertexCount - 2) { flush() } addVertex(x0, y0, color0, m) addVertex(x1, y1, color1, m) } - fun line(x0: Double, y0: Double, x1: Double, y1: Double, color0: RGBA = color, color1: RGBA = color0, m: Matrix = currentMatrix) = line(x0.toFloat(), y0.toFloat(), x1.toFloat(), y1.toFloat(), color0, color1, m) - fun line(x0: Int, y0: Int, x1: Int, y1: Int, color0: RGBA = color, color1: RGBA = color0, m: Matrix = currentMatrix) = line(x0.toFloat(), y0.toFloat(), x1.toFloat(), y1.toFloat(), color0, color1, m) + fun line(x0: Double, y0: Double, x1: Double, y1: Double, color0: RGBA = color, color1: RGBA = color0, m: MMatrix = currentMatrix) = line(x0.toFloat(), y0.toFloat(), x1.toFloat(), y1.toFloat(), color0, color1, m) + fun line(x0: Int, y0: Int, x1: Int, y1: Int, color0: RGBA = color, color1: RGBA = color0, m: MMatrix = currentMatrix) = line(x0.toFloat(), y0.toFloat(), x1.toFloat(), y1.toFloat(), color0, color1, m) - fun drawVector(path: VectorPath, m: Matrix = currentMatrix) { + fun drawVector(path: VectorPath, m: MMatrix = currentMatrix) { var lastX = 0.0 var lastY = 0.0 path.emitPoints2 { x, y, move -> @@ -115,18 +115,18 @@ class LineRenderBatcher( } } - inline fun drawVector(m: Matrix = currentMatrix, block: VectorBuilder.() -> Unit) { + inline fun drawVector(m: MMatrix = currentMatrix, block: VectorBuilder.() -> Unit) { drawVector(VectorPath().apply(block), m = m) } - inline fun drawVector(color: RGBA, m: Matrix = currentMatrix, block: VectorBuilder.() -> Unit) { + inline fun drawVector(color: RGBA, m: MMatrix = currentMatrix, block: VectorBuilder.() -> Unit) { color(color) { drawVector(m, block) } } /** Prepares for drawing a set of lines with the specified [matrix]. It flushes all other contexts, and the set [matrix]. */ - inline fun draw(matrix: Matrix, body: () -> T): T { + inline fun draw(matrix: MMatrix, body: () -> T): T { ctx.flush() return tempViewMat.alloc { temp -> temp.copyFrom(viewMat) @@ -184,14 +184,14 @@ class LineRenderBatcher( } @PublishedApi - internal val currentMatrix: Matrix = Matrix() + internal val currentMatrix: MMatrix = MMatrix() - inline fun drawWithGlobalMatrix(matrix: Matrix?, block: () -> T): T = currentMatrix.keepMatrix { + inline fun drawWithGlobalMatrix(matrix: MMatrix?, block: () -> T): T = currentMatrix.keepMatrix { if (matrix != null) it.copyFrom(matrix) block() } - private fun addVertex(x: Float, y: Float, color: RGBA = this.color, m: Matrix = currentMatrix) { + private fun addVertex(x: Float, y: Float, color: RGBA = this.color, m: MMatrix = currentMatrix) { vertices.setFloat32(vertexPos + 0, m.transformXf(x, y)) vertices.setFloat32(vertexPos + 1, m.transformYf(x, y)) vertices.setInt32(vertexPos + 2, color.value) diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/render/RenderContext.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/render/RenderContext.kt index 15375b21d2..19a6ea3030 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/render/RenderContext.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/render/RenderContext.kt @@ -52,13 +52,13 @@ class RenderContext constructor( DeviceDimensionsProvider by deviceDimensionsProvider, Closeable { - val projectionMatrixTransform = Matrix() - val projectionMatrixTransformInv = Matrix() - private val projMat: Matrix3D = Matrix3D() + val projectionMatrixTransform = MMatrix() + val projectionMatrixTransformInv = MMatrix() + private val projMat: MMatrix3D = MMatrix3D() @KorgeInternal - val viewMat: Matrix3D = Matrix3D() + val viewMat: MMatrix3D = MMatrix3D() @KorgeInternal - val viewMat2D: Matrix = Matrix() + val viewMat2D: MMatrix = MMatrix() @KorgeInternal val uniforms: AGUniformValues by lazy { @@ -68,7 +68,7 @@ class RenderContext constructor( } } - inline fun setTemporalProjectionMatrixTransform(m: Matrix, block: () -> T): T = + inline fun setTemporalProjectionMatrixTransform(m: MMatrix, block: () -> T): T = this.projectionMatrixTransform.keepMatrix { flush() this.projectionMatrixTransform.copyFrom(m) @@ -81,8 +81,8 @@ class RenderContext constructor( var flipRenderTexture = true //var flipRenderTexture = false - private val tempRect = Rectangle() - private val tempMat3d = Matrix3D() + private val tempRect = MRectangle() + private val tempMat3d = MMatrix3D() val tempTexturePool: Pool = Pool { AGTexture() } @@ -101,7 +101,7 @@ class RenderContext constructor( /** * Executes [callback] while setting temporarily the view matrix to [matrix] */ - inline fun setViewMatrixTemp(matrix: Matrix, crossinline callback: () -> Unit) { + inline fun setViewMatrixTemp(matrix: MMatrix, crossinline callback: () -> Unit) { matrix3DPool.alloc { temp -> matrixPool.alloc { temp2d -> flush() @@ -224,18 +224,18 @@ class RenderContext constructor( @OptIn(KorgeInternal::class) inline fun useCtx2d(block: (RenderContext2D) -> Unit) { useBatcher(batch) { block(ctx2d) } } - /** Pool of [Matrix] objects that could be used temporarily by renders */ - val matrixPool = Pool(reset = { it.identity() }, preallocate = 8) { Matrix() } - /** Pool of [Matrix3D] objects that could be used temporarily by renders */ - val matrix3DPool = Pool(reset = { it.identity() }, preallocate = 8) { Matrix3D() } - /** Pool of [Point] objects that could be used temporarily by renders */ - val pointPool = Pool(reset = { it.setTo(0, 0) }, preallocate = 8) { Point() } - /** Pool of [Rectangle] objects that could be used temporarily by renders */ - val rectPool = Pool(reset = { it.setTo(0, 0, 0, 0) }, preallocate = 8) { Rectangle() } + /** Pool of [MMatrix] objects that could be used temporarily by renders */ + val matrixPool = Pool(reset = { it.identity() }, preallocate = 8) { MMatrix() } + /** Pool of [MMatrix3D] objects that could be used temporarily by renders */ + val matrix3DPool = Pool(reset = { it.identity() }, preallocate = 8) { MMatrix3D() } + /** Pool of [MPoint] objects that could be used temporarily by renders */ + val pointPool = Pool(reset = { it.setTo(0, 0) }, preallocate = 8) { MPoint() } + /** Pool of [MRectangle] objects that could be used temporarily by renders */ + val rectPool = Pool(reset = { it.setTo(0, 0, 0, 0) }, preallocate = 8) { MRectangle() } - val tempMargin: MutableMarginInt = MutableMarginInt() + val tempMargin: MMarginInt = MMarginInt() - val identityMatrix = Matrix() + val identityMatrix = MMatrix() /** * Allows to toggle whether stencil-based masks are enabled or not. diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/render/RenderContext2D.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/render/RenderContext2D.kt index 48ac2790ca..8030237a24 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/render/RenderContext2D.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/render/RenderContext2D.kt @@ -21,7 +21,7 @@ import kotlin.native.concurrent.SharedImmutable private val logger = Logger("RenderContext2D") /** - * Helper class using [BatchBuilder2D] that keeps a chain of affine transforms [Matrix], [ColorTransform] and [blendMode] + * Helper class using [BatchBuilder2D] that keeps a chain of affine transforms [MMatrix], [ColorTransform] and [blendMode] * and allows to draw images and scissors with that transform. * * [keepMatrix], [keepBlendMode], [keepColor] and [keep] block methods allow to do transformations inside its blocks @@ -50,14 +50,14 @@ class RenderContext2D( inline fun getTexture(slice: BmpSlice): TextureCoords = agBitmapTextureManager.getTexture(slice) @KorgeInternal - val mpool = Pool { Matrix() } + val mpool = Pool { MMatrix() } val _tempProgramUniforms = AGUniformValues() init { logger.trace { "RenderContext2D[1]" } } @KorgeInternal - val m = Matrix() + val m = MMatrix() /** Blending mode to be used in the renders */ var blendMode = BlendMode.NORMAL @@ -67,7 +67,7 @@ class RenderContext2D( init { logger.trace { "RenderContext2D[2]" } } - /** Executes [callback] restoring the initial transformation [Matrix] at the end */ + /** Executes [callback] restoring the initial transformation [MMatrix] at the end */ inline fun keepMatrix(crossinline callback: () -> T) = mpool.alloc { matrix -> matrix.copyFrom(m) try { @@ -121,7 +121,7 @@ class RenderContext2D( } /** Sets the current transform [matrix] */ - fun setMatrix(matrix: Matrix) { + fun setMatrix(matrix: MMatrix) { this.m.copyFrom(matrix) } @@ -202,7 +202,7 @@ class RenderContext2D( texturedVertexArrayNoTransform(TexturedVertexArray.fromTriangles(triangles, color, matrix = m), filtering) } - fun texturedVertexArrayNoTransform(texturedVertexArray: TexturedVertexArray, filtering: Boolean = this.filtering, matrix: Matrix? = null) { + fun texturedVertexArrayNoTransform(texturedVertexArray: TexturedVertexArray, filtering: Boolean = this.filtering, matrix: MMatrix? = null) { batch.setStateFast(Bitmaps.white, filtering, blendMode, null, icount = texturedVertexArray.icount, vcount = texturedVertexArray.vcount) batch.drawVertices(texturedVertexArray, matrix, premultiplied = Bitmaps.white.premultiplied, wrap = false) } @@ -219,7 +219,7 @@ class RenderContext2D( height: Double, program: Program, uniforms: AGUniformValues, - padding: Margin = Margin.EMPTY, + padding: IMargin = IMargin.EMPTY, ) { val ctx = batch.ctx //programUniforms @@ -289,7 +289,7 @@ class RenderContext2D( inline fun scissor(x: Float, y: Float, width: Float, height: Float, block: () -> Unit) = scissor(x.toInt(), y.toInt(), width.toInt(), height.toInt(), block) /** Temporarily sets the [scissor] (visible rendering area) to [rect] is executed. */ - inline fun scissor(rect: Rectangle?, block: () -> Unit) = + inline fun scissor(rect: MRectangle?, block: () -> Unit) = scissor(AGScissor(rect), block) /** Temporarily sets the [scissor] (visible rendering area) to [scissor] is executed. */ diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/render/RenderContext2DExt.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/render/RenderContext2DExt.kt index 0ded96aa52..8b04b211e0 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/render/RenderContext2DExt.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/render/RenderContext2DExt.kt @@ -101,11 +101,11 @@ fun RenderContext2D.materialRoundRect( radius.bottomRight.toFloat(), radius.topRight.toFloat(), radius.bottomLeft.toFloat(), radius.topLeft.toFloat(), ) - _tempProgramUniforms[MaterialRender.u_Size] = Point(width, height) + _tempProgramUniforms[MaterialRender.u_Size] = MPoint(width, height) _tempProgramUniforms[MaterialRender.u_BackgroundColor] = color.premultipliedFast - _tempProgramUniforms[MaterialRender.u_HighlightPos] = Point(highlightPos.x * width, highlightPos.y * height) + _tempProgramUniforms[MaterialRender.u_HighlightPos] = MPoint(highlightPos.x * width, highlightPos.y * height) _tempProgramUniforms[MaterialRender.u_HighlightRadius] = highlightRadius * kotlin.math.max(width, height) * 1.25 _tempProgramUniforms[MaterialRender.u_HighlightColor] = highlightColor.premultipliedFast @@ -113,10 +113,10 @@ fun RenderContext2D.materialRoundRect( _tempProgramUniforms[MaterialRender.u_BorderColor] = borderColor.premultipliedFast _tempProgramUniforms[MaterialRender.u_ShadowColor] = shadowColor.premultipliedFast - _tempProgramUniforms[MaterialRender.u_ShadowOffset] = Point(shadowOffset.x, shadowOffset.y) + _tempProgramUniforms[MaterialRender.u_ShadowOffset] = MPoint(shadowOffset.x, shadowOffset.y) _tempProgramUniforms[MaterialRender.u_ShadowRadius] = shadowRadius - quadPaddedCustomProgram(x, y, width, height, MaterialRender.PROGRAM, _tempProgramUniforms, Margin(shadowRadius + shadowOffset.length)) + quadPaddedCustomProgram(x, y, width, height, MaterialRender.PROGRAM, _tempProgramUniforms, IMargin(shadowRadius + shadowOffset.length)) } @KorgeExperimental @@ -134,7 +134,7 @@ fun RenderContext2D.drawText( align: TextAlignment = TextAlignment.TOP_LEFT, includeFirstLineAlways: Boolean = true ) { - drawText(text.place(Rectangle(x, y, width, height), wordWrap, includePartialLines, ellipsis, fill, stroke, align, includeFirstLineAlways = includeFirstLineAlways)) + drawText(text.place(MRectangle(x, y, width, height), wordWrap, includePartialLines, ellipsis, fill, stroke, align, includeFirstLineAlways = includeFirstLineAlways)) } @KorgeExperimental diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/render/TextureWithBitmapSlice.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/render/TextureWithBitmapSlice.kt index 68f647f392..61b5109d36 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/render/TextureWithBitmapSlice.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/render/TextureWithBitmapSlice.kt @@ -1,10 +1,8 @@ package com.soywiz.korge.render import com.soywiz.korge.internal.KorgeInternal -import com.soywiz.korim.bitmap.Bitmap -import com.soywiz.korim.bitmap.BitmapSlice import com.soywiz.korim.bitmap.BmpSlice -import com.soywiz.korma.geom.Rectangle +import com.soywiz.korma.geom.MRectangle /** * A [texture] wrap that includes [scale] and [bounds] information. @@ -15,5 +13,5 @@ data class TextureWithBitmapSlice( val texture: BmpSlice, val bitmapSlice: BmpSlice, val scale: Double, - val bounds: Rectangle + val bounds: MRectangle ) diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/render/TexturedVertexArray.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/render/TexturedVertexArray.kt index 0b26a1b989..fd445ae749 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/render/TexturedVertexArray.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/render/TexturedVertexArray.kt @@ -9,8 +9,8 @@ import com.soywiz.korim.color.Colors import com.soywiz.korim.color.RGBA import com.soywiz.korma.geom.BoundsBuilder import com.soywiz.korma.geom.IPointArrayList -import com.soywiz.korma.geom.Matrix -import com.soywiz.korma.geom.Rectangle +import com.soywiz.korma.geom.MMatrix +import com.soywiz.korma.geom.MRectangle import com.soywiz.korma.geom.fastForEachWithIndex import com.soywiz.korma.geom.triangle.TriangleList import com.soywiz.korma.geom.vector.VectorPath @@ -67,20 +67,20 @@ class TexturedVertexArray(vcount: Int, val indices: ShortArray, icount: Int = in /** Builds indices for drawing triangles when the vertices information is stored as quads (4 vertices per quad primitive) */ inline fun quadIndices(quadCount: Int): ShortArray = TEXTURED_ARRAY_quadIndices(quadCount) - fun fromPath(path: VectorPath, colorMul: RGBA = Colors.WHITE, colorAdd: ColorAdd = ColorAdd.NEUTRAL, matrix: Matrix? = null, doClipper: Boolean = true): TexturedVertexArray { + fun fromPath(path: VectorPath, colorMul: RGBA = Colors.WHITE, colorAdd: ColorAdd = ColorAdd.NEUTRAL, matrix: MMatrix? = null, doClipper: Boolean = true): TexturedVertexArray { //return fromTriangles(path.triangulateEarCut(), colorMul, colorAdd, matrix) //return fromTriangles(path.triangulatePoly2tri(), colorMul, colorAdd, matrix) return fromTriangles(path.triangulateSafe(doClipper), colorMul, colorAdd, matrix) } - fun fromTriangles(triangles: TriangleList, colorMul: RGBA = Colors.WHITE, colorAdd: ColorAdd = ColorAdd.NEUTRAL, matrix: Matrix? = null): TexturedVertexArray { + fun fromTriangles(triangles: TriangleList, colorMul: RGBA = Colors.WHITE, colorAdd: ColorAdd = ColorAdd.NEUTRAL, matrix: MMatrix? = null): TexturedVertexArray { val tva = TexturedVertexArray(triangles.pointCount, triangles.indices, triangles.numIndices) tva.setSimplePoints(triangles.points, matrix, colorMul, colorAdd) return tva } /** This doesn't handle holes */ - fun fromPointArrayList(points: IPointArrayList, colorMul: RGBA = Colors.WHITE, colorAdd: ColorAdd = ColorAdd.NEUTRAL, matrix: Matrix? = null): TexturedVertexArray { + fun fromPointArrayList(points: IPointArrayList, colorMul: RGBA = Colors.WHITE, colorAdd: ColorAdd = ColorAdd.NEUTRAL, matrix: MMatrix? = null): TexturedVertexArray { val indices = ShortArray((points.size - 2) * 3) for (n in 0 until points.size - 2) { indices[n * 3 + 0] = (0).toShort() @@ -94,7 +94,7 @@ class TexturedVertexArray(vcount: Int, val indices: ShortArray, icount: Int = in } - fun setSimplePoints(points: IPointArrayList, matrix: Matrix?, colorMul: RGBA = Colors.WHITE, colorAdd: ColorAdd = ColorAdd.NEUTRAL) { + fun setSimplePoints(points: IPointArrayList, matrix: MMatrix?, colorMul: RGBA = Colors.WHITE, colorAdd: ColorAdd = ColorAdd.NEUTRAL) { if (matrix != null) { points.fastForEachWithIndex { index, x, y -> val xf = x.toFloat() @@ -152,7 +152,7 @@ class TexturedVertexArray(vcount: Int, val indices: ShortArray, icount: Int = in return this } /** Sets the [x] and [y] with the [matrix] transform applied of the vertex previously selected calling [select] */ - fun xy(x: Double, y: Double, matrix: Matrix) = setX(matrix.transformXf(x, y)).setY(matrix.transformYf(x, y)) + fun xy(x: Double, y: Double, matrix: MMatrix) = setX(matrix.transformXf(x, y)).setY(matrix.transformYf(x, y)) /** Sets the [x] and [y] of the vertex previously selected calling [select] */ fun xy(x: Double, y: Double) = setX(x.toFloat()).setY(y.toFloat()) /** Sets the [u] and [v] of the vertex previously selected calling [select] */ @@ -181,17 +181,17 @@ class TexturedVertexArray(vcount: Int, val indices: ShortArray, icount: Int = in * using the texture coords defined by [BmpSlice] and color transforms [colMul] and [colAdd] */ @OptIn(KorgeInternal::class) - fun quad(index: Int, x: Double, y: Double, width: Double, height: Double, matrix: Matrix, bmp: BmpCoords, colMul: RGBA, colAdd: ColorAdd) { + fun quad(index: Int, x: Double, y: Double, width: Double, height: Double, matrix: MMatrix, bmp: BmpCoords, colMul: RGBA, colAdd: ColorAdd) { quad(index, x.toFloat(), y.toFloat(), width.toFloat(), height.toFloat(), matrix, bmp, colMul, colAdd) } @OptIn(KorgeInternal::class) - fun quad(index: Int, x: Float, y: Float, width: Float, height: Float, matrix: Matrix, bmp: BmpCoords, colMul: RGBA, colAdd: ColorAdd) { + fun quad(index: Int, x: Float, y: Float, width: Float, height: Float, matrix: MMatrix, bmp: BmpCoords, colMul: RGBA, colAdd: ColorAdd) { quad(index, x, y, width, height, matrix, bmp.tlX, bmp.tlY, bmp.trX, bmp.trY, bmp.blX, bmp.blY, bmp.brX, bmp.brY, colMul, colAdd) } @OptIn(KorgeInternal::class) fun quad( - index: Int, x: Float, y: Float, width: Float, height: Float, matrix: Matrix, + index: Int, x: Float, y: Float, width: Float, height: Float, matrix: MMatrix, tl_x: Float, tl_y: Float, tr_x: Float, tr_y: Float, bl_x: Float, bl_y: Float, @@ -244,10 +244,10 @@ class TexturedVertexArray(vcount: Int, val indices: ShortArray, icount: Int = in private val bounds: BoundsBuilder = BoundsBuilder() /** - * Returns the bounds of the vertices defined in the indices from [min] to [max] (excluding) as [Rectangle] - * Allows to define the output as [out] to be allocation-free, setting the [out] [Rectangle] and returning it. + * Returns the bounds of the vertices defined in the indices from [min] to [max] (excluding) as [MRectangle] + * Allows to define the output as [out] to be allocation-free, setting the [out] [MRectangle] and returning it. */ - fun getBounds(min: Int = 0, max: Int = vcount, out: Rectangle = Rectangle()): Rectangle { + fun getBounds(min: Int = 0, max: Int = vcount, out: MRectangle = MRectangle()): MRectangle { bounds.reset() for (n in min until max) { select(n) @@ -287,7 +287,7 @@ class TexturedVertexArray(vcount: Int, val indices: ShortArray, icount: Int = in arraycopy(other.indices, 0, this.indices, 0, this.indices.size) } - fun applyMatrix(matrix: Matrix) { + fun applyMatrix(matrix: MMatrix) { for (n in 0 until vcount){ select(n) val x = this.x diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/render/VertexInfo.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/render/VertexInfo.kt index b8cc3f484c..86a5bb62d5 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/render/VertexInfo.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/render/VertexInfo.kt @@ -4,7 +4,7 @@ import com.soywiz.kmem.* import com.soywiz.korim.color.Colors import com.soywiz.korim.color.RGBA import com.soywiz.korio.util.niceStr -import com.soywiz.korma.geom.Point +import com.soywiz.korma.geom.MPoint data class VertexInfo( var x: Float = 0f, @@ -16,8 +16,8 @@ data class VertexInfo( ) { var texWidth: Int = -1 var texHeight: Int = -1 - val xy get() = Point(x, y) - val uv get() = Point(u, v) + val xy get() = MPoint(x, y) + val uv get() = MPoint(u, v) fun read(buffer: Buffer, n: Int) { val index = n * 6 this.x = buffer.getFloat32(index + 0) diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/scene/Scene.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/scene/Scene.kt index 9756acec42..b7f7428b51 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/scene/Scene.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/scene/Scene.kt @@ -30,9 +30,9 @@ import com.soywiz.korio.resources.Resources import com.soywiz.korio.resources.ResourcesContainer import com.soywiz.korma.geom.Anchor import com.soywiz.korma.geom.ISize -import com.soywiz.korma.geom.Rectangle +import com.soywiz.korma.geom.MRectangle import com.soywiz.korma.geom.ScaleMode -import com.soywiz.korma.geom.Size +import com.soywiz.korma.geom.MSize import kotlinx.coroutines.CancellationException import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Job @@ -244,7 +244,7 @@ abstract class ScaledScene( } private fun onSizeChanged(sceneView: SContainer, width: Double, height: Double) { - val out = Rectangle(0.0, 0.0, width, height).place(Size(sceneWidth, sceneHeight), sceneAnchor, sceneScaleMode) + val out = MRectangle(0.0, 0.0, width, height).place(MSize(sceneWidth, sceneHeight), sceneAnchor, sceneScaleMode) sceneView .size(sceneWidth, sceneHeight) .xy(out.x, out.y) diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/tests/ViewsForTesting.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/tests/ViewsForTesting.kt index 3e88f2f2f2..49cc534575 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/tests/ViewsForTesting.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/tests/ViewsForTesting.kt @@ -272,7 +272,7 @@ open class ViewsForTesting( val bounds = this.getGlobalBounds() if (bounds.area <= 0.0) return false val module = injector.get() - val visibleBounds = Rectangle(0, 0, module.windowSize.width, module.windowSize.height) + val visibleBounds = MRectangle(0, 0, module.windowSize.width, module.windowSize.height) if (!bounds.intersects(visibleBounds)) return false return true } diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/text/TextEditController.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/text/TextEditController.kt index 96147a7e43..fc0169b436 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/text/TextEditController.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/text/TextEditController.kt @@ -61,7 +61,7 @@ class TextEditController( it.visible = false } - var padding: Margin = Margin(3.0, 2.0, 2.0, 2.0) + var padding: IMargin = IMargin(3.0, 2.0, 2.0, 2.0) set(value) { field = value onSizeChanged(this) @@ -196,7 +196,7 @@ class TextEditController( fun getCaretAtIndex(index: Int): Bezier { val glyphPositions = textView.getGlyphMetrics().glyphs - if (glyphPositions.isEmpty()) return Bezier(Point(), Point()) + if (glyphPositions.isEmpty()) return Bezier(MPoint(), MPoint()) val glyph = glyphPositions[min(index, glyphPositions.size - 1)] return when { index < glyphPositions.size -> glyph.caretStart @@ -216,7 +216,7 @@ class TextEditController( } */ - fun getIndexAtPos(pos: Point): Int { + fun getIndexAtPos(pos: MPoint): Int { val glyphPositions = textView.getGlyphMetrics().glyphs var index = 0 diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/tween/tweenbase.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/tween/tweenbase.kt index 7d7d2cbe70..75815d430c 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/tween/tweenbase.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/tween/tweenbase.kt @@ -11,7 +11,6 @@ import com.soywiz.korim.color.ColorAdd import com.soywiz.korim.color.RGBA import com.soywiz.korma.geom.* import com.soywiz.korma.geom.bezier.getEquidistantPoints -import com.soywiz.korma.geom.bezier.getPoints import com.soywiz.korma.geom.vector.VectorPath import com.soywiz.korma.geom.vector.getCurves import com.soywiz.korma.interpolation.Easing @@ -86,8 +85,8 @@ fun V2Lazy(callback: () -> V2<*>): V2 { } fun KMutableProperty0.incr(dx: Double, dy: Double): V2 { - val start: Point = Point(0, 0) - val value: Point = Point(0, 0) + val start: MPoint = MPoint(0, 0) + val value: MPoint = MPoint(0, 0) return V2(this, start, value, { it, _, _ -> value.setTo(start.x + dx, start.y + dy) value @@ -166,7 +165,7 @@ inline operator fun KMutableProperty0.get(path: VectorPath, includeLastP }] inline operator fun KMutableProperty0.get(range: IPointArrayList): V2 { - val temp = Point() + val temp = MPoint() return V2( this, temp, temp, { ratio, _, _ -> val ratioIndex = ratio * (range.size - 1) diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/ui/NewUISkin.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/ui/NewUISkin.kt index d2001cc2ea..7984195875 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/ui/NewUISkin.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/ui/NewUISkin.kt @@ -77,7 +77,7 @@ open class UIBaseCheckBoxSkinMaterial( borderColor = item.checkedRatio.interpolate(unselectedColor, selectedColor), color = Colors.TRANSPARENT, highlightRadius = item.checkedRatio.interpolate(0.0, 0.2), - highlightPos = Point(0.5, 0.5), + highlightPos = MPoint(0.5, 0.5), highlightColor = selectedColor, ) } diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/ui/UIButton.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/ui/UIButton.kt index a86712e2f4..7a1ea15ab6 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/ui/UIButton.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/ui/UIButton.kt @@ -1,20 +1,16 @@ package com.soywiz.korge.ui -import com.soywiz.kds.iterators.* import com.soywiz.klock.* -import com.soywiz.kmem.* import com.soywiz.korev.* import com.soywiz.korge.animate.* import com.soywiz.korge.input.* import com.soywiz.korge.tween.* import com.soywiz.korge.view.* -import com.soywiz.korge.view.filter.* import com.soywiz.korge.view.property.* import com.soywiz.korgw.* import com.soywiz.korim.bitmap.* import com.soywiz.korim.color.* import com.soywiz.korim.font.* -import com.soywiz.korim.paint.* import com.soywiz.korim.text.* import com.soywiz.korio.async.* import com.soywiz.korma.geom.* @@ -22,7 +18,6 @@ import com.soywiz.korma.interpolation.* import com.soywiz.korma.length.* import com.soywiz.korma.length.LengthExtensions.Companion.pt import kotlin.math.* -import kotlin.reflect.* inline fun Container.uiButton( label: String, @@ -285,7 +280,7 @@ open class UIButton( } fun simulateClick(views: Views) { - touch.simulateTapAt(views, localToGlobal(Point(width * 0.5, height * 0.5))) + touch.simulateTapAt(views, localToGlobal(MPoint(width * 0.5, height * 0.5))) } open fun updatedUIButton(down: Boolean? = null, over: Boolean? = null, px: Double = 0.0, py: Double = 0.0, immediate: Boolean = false) { @@ -308,7 +303,7 @@ open class UIButton( // button::highlightAlpha[1.0], // button::highlightPos[Point(px / button.width, py / button.height), Point(px / button.width, py / button.height)], // )) - background.addHighlight(Point(px, py)) + background.addHighlight(MPoint(px, py)) /* button.highlightPos.setTo(px / button.width, py / button.height) button.animatorEffects.tween( diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/ui/UICheckBox.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/ui/UICheckBox.kt index e4ea0336ae..04a54b7baa 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/ui/UICheckBox.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/ui/UICheckBox.kt @@ -68,7 +68,7 @@ open class UIBaseCheckBox>( } private var pressing by uiObservable(false) { updateState() } - private val textBounds = Rectangle() + private val textBounds = MRectangle() override fun renderInternal(ctx: RenderContext) { updateState() @@ -112,7 +112,7 @@ open class UIBaseCheckBox>( onOut { this@UIBaseCheckBox.over = false } onDown { this@UIBaseCheckBox.pressing = true - highlights.addHighlight(Point(0.5, 0.5)) + highlights.addHighlight(MPoint(0.5, 0.5)) } onUpAnywhere { this@UIBaseCheckBox.pressing = false diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/ui/UIComboBox.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/ui/UIComboBox.kt index 3e6c0afa63..0645620e00 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/ui/UIComboBox.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/ui/UIComboBox.kt @@ -79,7 +79,7 @@ open class UIComboBox( private val selectedButton = uiButton("", width = width, height = height).also { it.textAlignment = TextAlignment.MIDDLE_LEFT - it.textView.padding = Margin(0.0, 8.0) + it.textView.padding = IMargin(0.0, 8.0) it.bgColorOut = Colors.WHITE it.bgColorOver = MaterialColors.GRAY_100 it.bgColorDisabled = MaterialColors.GRAY_100 @@ -128,7 +128,7 @@ open class UIComboBox( //val filter = "twe" val it = UIButton(richText = richText, width = width, height = itemHeight).apply { this.textAlignment = TextAlignment.MIDDLE_LEFT - this.textView.padding = Margin(0.0, 8.0) + this.textView.padding = IMargin(0.0, 8.0) this.radius = 0.pt this.bgColorOut = MaterialColors.GRAY_50 this.bgColorOver = MaterialColors.GRAY_400 @@ -154,7 +154,7 @@ open class UIComboBox( private fun ensureSelectedIsInVisibleArea(index: Int) { verticalList.updateList() itemsView.ensureRectIsVisible( - Rectangle( + MRectangle( 0.0, verticalList.provider.getItemY(index), width, verticalList.provider.getItemHeight(index) @@ -262,10 +262,10 @@ open class UIComboBox( //itemsView.size(width, viewportHeight.toDouble()).position(0.0, height) itemsView .size(width, viewportHeight.toDouble()) - .setGlobalXY(localToGlobal(Point(0.0, height + 8.0))) + .setGlobalXY(localToGlobal(MPoint(0.0, height + 8.0))) itemsViewBackground .size(width, itemsView.height + 16) - .setGlobalXY(localToGlobal(Point(0.0, height))) + .setGlobalXY(localToGlobal(MPoint(0.0, height))) verticalList .size(width, verticalList.height) diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/ui/UIEditableNumber.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/ui/UIEditableNumber.kt index 214cbf91ff..117aa8f2fc 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/ui/UIEditableNumber.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/ui/UIEditableNumber.kt @@ -12,7 +12,7 @@ import com.soywiz.korge.view.size import com.soywiz.korgw.GameWindow import com.soywiz.korio.async.Signal import com.soywiz.korio.util.toStringDecimal -import com.soywiz.korma.geom.Margin +import com.soywiz.korma.geom.IMargin import kotlin.math.absoluteValue @KorgeExperimental @@ -42,7 +42,7 @@ class UIEditableNumber(value: Double = 0.0, min: Double = 0.0, max: Double = 1.0 private val textView = uiText("", width, height) private val textInputView = uiTextInput("", width, height) .also { it.visible = false } - .also { it.padding = Margin(0.0) } + .also { it.padding = IMargin(0.0) } var min: Double = min var max: Double = max diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/ui/UIImage.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/ui/UIImage.kt index e3cffd5e6e..90e8585f86 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/ui/UIImage.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/ui/UIImage.kt @@ -23,7 +23,7 @@ class UIImage( scaleMode: ScaleMode = ScaleMode.NO_SCALE, contentAnchor: Anchor = Anchor.TOP_LEFT, ) : UIView(width, height) { - private val cachedGlobalMatrix = Matrix() + private val cachedGlobalMatrix = MMatrix() private var validCoords: Boolean = false @ViewProperty @@ -50,7 +50,7 @@ class UIImage( // @TODO: Can we generalize this to be placed in KorMA? val bitmapSize = RectangleInt(bitmap.bounds).size.size - val finalRect = bitmapSize.applyScaleMode(Rectangle(0.0, 0.0, width, height), scaleMode, contentAnchor) + val finalRect = bitmapSize.applyScaleMode(MRectangle(0.0, 0.0, width, height), scaleMode, contentAnchor) val realL = finalRect.left.clamp(0.0, width) val realT = finalRect.top.clamp(0.0, height) diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/ui/UIMaterialLayer.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/ui/UIMaterialLayer.kt index d4125608da..f1cd0e5e33 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/ui/UIMaterialLayer.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/ui/UIMaterialLayer.kt @@ -117,7 +117,7 @@ class UIMaterialLayer( @ViewProperty private fun addHighlightAction() { - addHighlight(Point(0.5, 0.5)) + addHighlight(MPoint(0.5, 0.5)) } fun addHighlight(pos: IPoint) { diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/ui/UIPropertyRow.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/ui/UIPropertyRow.kt index 849d2c618c..0013a6dfdc 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/ui/UIPropertyRow.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/ui/UIPropertyRow.kt @@ -8,7 +8,7 @@ import com.soywiz.korge.view.append import com.soywiz.korge.view.size import com.soywiz.korim.color.RGBAf import com.soywiz.korma.geom.Angle -import com.soywiz.korma.geom.Point +import com.soywiz.korma.geom.MPoint import com.soywiz.korma.geom.degrees import com.soywiz.korma.geom.unaryMinus import com.soywiz.korma.geom.unaryPlus @@ -91,7 +91,7 @@ fun UIEditableColorPropsList(prop: KProperty0): Array, min: Double = -1000.0, max: Double = +1000.0): Array { +fun UIEditablePointPropsList(prop: KProperty0, min: Double = -1000.0, max: Double = +1000.0): Array { return UIEditableNumberPropsList(prop.get()::x, prop.get()::y, min = min, max = max) } diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/ui/UIScrollBar.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/ui/UIScrollBar.kt index e9ebeb1c88..609511c82c 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/ui/UIScrollBar.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/ui/UIScrollBar.kt @@ -14,7 +14,7 @@ import com.soywiz.korge.view.position import com.soywiz.korge.view.size import com.soywiz.korge.view.solidRect import com.soywiz.korio.async.Signal -import com.soywiz.korma.geom.Point +import com.soywiz.korma.geom.MPoint import kotlin.math.sign @Deprecated("Use UINewScrollable") @@ -111,7 +111,7 @@ open class UIScrollBar( changeCurrent(pos.sign * 0.8 * this.pageSize) } - val tempP = Point() + val tempP = MPoint() var initRatio = 0.0 var startRatio = 0.0 thumb.onMouseDrag { diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/ui/UISkins.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/ui/UISkins.kt index f7bedeb75b..532d7ca3cb 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/ui/UISkins.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/ui/UISkins.kt @@ -13,7 +13,7 @@ import com.soywiz.korim.font.* import com.soywiz.korim.paint.* import com.soywiz.korim.text.TextAlignment import com.soywiz.korma.geom.IPoint -import com.soywiz.korma.geom.Point +import com.soywiz.korma.geom.MPoint import com.soywiz.korma.geom.degrees import com.soywiz.korma.geom.vector.LineCap import com.soywiz.korma.geom.vector.circle @@ -101,7 +101,7 @@ var UISkinable.textSize: Double get() = getSkinProperty("textSize") { 16.0 } ; s var UISkinable.textColor: RGBA get() = getSkinProperty("textColor") { Colors.WHITE } ; set(value) { setSkinProperty("textColor", value) } var UISkinable.textAlignment: TextAlignment get() = getSkinProperty("textAlignment") { TextAlignment.LEFT } ; set(value) { setSkinProperty("textAlignment", value) } var UISkinable.shadowColor: RGBA get() = getSkinProperty("shadowColor") { Colors.BLACK.withAd(0.3) } ; set(value) { setSkinProperty("shadowColor", value) } -var UISkinable.shadowPosition: IPoint get() = getSkinProperty("shadowPosition") { Point(1, 1) } ; set(value) { setSkinProperty("shadowPosition", value) } +var UISkinable.shadowPosition: IPoint get() = getSkinProperty("shadowPosition") { MPoint(1, 1) } ; set(value) { setSkinProperty("shadowPosition", value) } var UISkinable.buttonNormal: NinePatchBmpSlice get() = getSkinProperty("buttonNormal") { uiSkinBitmap.sliceWithSize(0, 0, 64, 64).asNinePatchSimple(16, 16, 48, 48) }; set(value) { setSkinProperty("buttonNormal", value) } var UISkinable.buttonOver: NinePatchBmpSlice get() = getSkinProperty("buttonOver") { uiSkinBitmap.sliceWithSize(64, 0, 64, 64).asNinePatchSimple(16, 16, 48, 48) }; set(value) { setSkinProperty("buttonOver", value) } diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/ui/UIText.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/ui/UIText.kt index ae331ddc76..3a3ae6a901 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/ui/UIText.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/ui/UIText.kt @@ -66,7 +66,7 @@ class UIText( bpressing = false } - private val textBounds = Rectangle() + private val textBounds = MRectangle() override fun renderInternal(ctx: RenderContext) { background.visible = bgcolor.a != 0 diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/ui/UITextInput.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/ui/UITextInput.kt index e6a148c9a9..75c3e5072b 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/ui/UITextInput.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/ui/UITextInput.kt @@ -53,7 +53,7 @@ class UITextInput(initialText: String = "", width: Double = 128.0, height: Doubl fun blur() = controller.blur() fun selectAll() = controller.selectAll() - var padding: Margin = Margin(3.0, 2.0, 2.0, 2.0) + var padding: IMargin = IMargin(3.0, 2.0, 2.0, 2.0) set(value) { field = value onSizeChanged() @@ -61,7 +61,7 @@ class UITextInput(initialText: String = "", width: Double = 128.0, height: Doubl override fun onSizeChanged() { bg.setSize(width, height) - container.bounds(Rectangle(0.0, 0.0, width, height).without(padding)) + container.bounds(MRectangle(0.0, 0.0, width, height).without(padding)) } init { diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/ui/UIVerticalList.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/ui/UIVerticalList.kt index 64b1cc6e1d..ba1969ae24 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/ui/UIVerticalList.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/ui/UIVerticalList.kt @@ -33,10 +33,10 @@ open class UIVerticalList(provider: Provider, width: Double = 200.0) : UIView(wi private var dirty = false private val viewsByIndex = LinkedHashMap() - private val lastArea = Rectangle() - private val lastPoint = Point() - private val tempRect = Rectangle() - private val tempPoint = Point() + private val lastArea = MRectangle() + private val lastPoint = MPoint() + private val tempRect = MRectangle() + private val tempPoint = MPoint() var provider: Provider = provider set(value) { field = value @@ -71,7 +71,7 @@ open class UIVerticalList(provider: Provider, width: Double = 200.0) : UIView(wi updateList() } - private val tempTransform = Matrix.Transform() + private val tempTransform = MMatrix.Transform() /** * Updates the list after size changes, but keeps its contents. diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/ui/UIView.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/ui/UIView.kt index 7ec5566e0a..d9dece6177 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/ui/UIView.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/ui/UIView.kt @@ -2,7 +2,6 @@ package com.soywiz.korge.ui import com.soywiz.kds.* import com.soywiz.klock.* -import com.soywiz.korev.* import com.soywiz.korge.baseview.* import com.soywiz.korge.component.* import com.soywiz.korge.input.* @@ -86,7 +85,7 @@ open class UIView( onSizeChanged() } - override fun getLocalBoundsInternal(out: Rectangle) { + override fun getLocalBoundsInternal(out: MRectangle) { out.setTo(0.0, 0.0, width, height) } diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/view/BaseGraphics.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/view/BaseGraphics.kt index dd3d1b1964..19cda3935c 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/view/BaseGraphics.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/view/BaseGraphics.kt @@ -8,7 +8,7 @@ import com.soywiz.korge.view.internal.InternalViewAutoscaling import com.soywiz.korim.bitmap.* import com.soywiz.korim.vector.Context2d import com.soywiz.korma.geom.BoundsBuilder -import com.soywiz.korma.geom.Rectangle +import com.soywiz.korma.geom.MRectangle abstract class BaseGraphics( var autoScaling: Boolean = false, @@ -152,23 +152,23 @@ abstract class BaseGraphics( internal val _sLeft get() = sLeft internal val _sTop get() = sTop - override fun getLocalBoundsInternal(out: Rectangle) { + override fun getLocalBoundsInternal(out: MRectangle) { _getLocalBoundsInternal(out) } - private val __localBounds: Rectangle = Rectangle() + private val __localBounds: MRectangle = MRectangle() //var boundsIncludeStrokes = false var boundsIncludeStrokes = true - private fun _getLocalBoundsInternal(out: Rectangle = __localBounds, strokes: Boolean = this.boundsIncludeStrokes): Rectangle { + private fun _getLocalBoundsInternal(out: MRectangle = __localBounds, strokes: Boolean = this.boundsIncludeStrokes): MRectangle { val bounds = boundsUnsafe(strokes = strokes) out.setTo(bounds.x - anchorDispX, bounds.y - anchorDispY, bounds.width, bounds.height) return out } - private val _localBoundsWithStrokes = Rectangle() - private val _localBounds = Rectangle() + private val _localBoundsWithStrokes = MRectangle() + private val _localBounds = MRectangle() - private fun boundsUnsafe(strokes: Boolean): Rectangle { + private fun boundsUnsafe(strokes: Boolean): MRectangle { if (_dirtyBounds) { _dirtyBounds = false bb.reset() @@ -189,7 +189,7 @@ abstract class BaseGraphics( return if (strokes) _localBoundsWithStrokes else _localBounds } - fun getLocalBoundsInternalNoAnchor(out: Rectangle, includeStrokes: Boolean) { + fun getLocalBoundsInternalNoAnchor(out: MRectangle, includeStrokes: Boolean) { out.copyFrom(boundsUnsafe(includeStrokes)) } } diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/view/CachedContainer.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/view/CachedContainer.kt index 85d04f701b..016f26b139 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/view/CachedContainer.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/view/CachedContainer.kt @@ -15,7 +15,7 @@ open class FixedSizeCachedContainer( override var height: Double = 100.0, cache: Boolean = true ) : CachedContainer(cache), View.Reference { - override fun getLocalBoundsInternal(out: Rectangle) { + override fun getLocalBoundsInternal(out: MRectangle) { out.setTo(0.0, 0.0, width, height) } } @@ -45,10 +45,10 @@ open class CachedContainer( } private var _cacheTex: CacheTexture? = null - private val tempMat2d = Matrix() + private val tempMat2d = MMatrix() private var dirty = true private var scaledCache = -1.0 - private var lbounds = Rectangle() + private var lbounds = MRectangle() override fun invalidateRender() { super.invalidateRender() diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/view/Camera.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/view/Camera.kt index c8140fb2e6..70019e01ad 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/view/Camera.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/view/Camera.kt @@ -4,8 +4,8 @@ import com.soywiz.klock.TimeSpan import com.soywiz.korge.tween.V2 import com.soywiz.korge.tween.get import com.soywiz.korge.tween.tween -import com.soywiz.korma.geom.Matrix -import com.soywiz.korma.geom.Rectangle +import com.soywiz.korma.geom.MMatrix +import com.soywiz.korma.geom.MRectangle import com.soywiz.korma.geom.setTo import com.soywiz.korma.interpolation.Easing @@ -35,13 +35,13 @@ class Camera : Container(), View.Reference { set(_) = Unit get() = referenceParent?.height ?: 100.0 - override fun getLocalBoundsInternal(out: Rectangle) { + override fun getLocalBoundsInternal(out: MRectangle) { out.setTo(0, 0, width, height) } - fun getLocalMatrixFittingGlobalRect(rect: Rectangle): Matrix { + fun getLocalMatrixFittingGlobalRect(rect: MRectangle): MMatrix { val destinationBounds = rect - val mat = this.parent?.globalMatrix?.clone() ?: Matrix() + val mat = this.parent?.globalMatrix?.clone() ?: MMatrix() mat.translate(-destinationBounds.x, -destinationBounds.y) mat.scale( width / destinationBounds.width, @@ -52,11 +52,11 @@ class Camera : Container(), View.Reference { return mat } - fun getLocalMatrixFittingView(view: View?): Matrix = - getLocalMatrixFittingGlobalRect((view ?: stage)?.globalBounds ?: Rectangle(0, 0, 100, 100)) + fun getLocalMatrixFittingView(view: View?): MMatrix = + getLocalMatrixFittingGlobalRect((view ?: stage)?.globalBounds ?: MRectangle(0, 0, 100, 100)) fun setTo(view: View?) { this.localMatrix = getLocalMatrixFittingView(view) } - fun setTo(rect: Rectangle) { this.localMatrix = getLocalMatrixFittingGlobalRect(rect) } + fun setTo(rect: MRectangle) { this.localMatrix = getLocalMatrixFittingGlobalRect(rect) } suspend fun tweenTo(view: View?, vararg vs: V2<*>, time: TimeSpan, easing: Easing = Easing.LINEAR) = this.tween( this::localMatrix[this.localMatrix.clone(), getLocalMatrixFittingView(view)], @@ -65,7 +65,7 @@ class Camera : Container(), View.Reference { easing = easing ) - suspend fun tweenTo(rect: Rectangle, vararg vs: V2<*>, time: TimeSpan, easing: Easing = Easing.LINEAR) = this.tween( + suspend fun tweenTo(rect: MRectangle, vararg vs: V2<*>, time: TimeSpan, easing: Easing = Easing.LINEAR) = this.tween( this::localMatrix[this.localMatrix.clone(), getLocalMatrixFittingGlobalRect(rect)], *vs, time = time, diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/view/Container.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/view/Container.kt index 482803b99d..0c32e4aa6d 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/view/Container.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/view/Container.kt @@ -266,7 +266,7 @@ open class Container( removeChild(view) } - private val tempMatrix = Matrix() + private val tempMatrix = MMatrix() override fun renderInternal(ctx: RenderContext) { if (!visible) return renderChildrenInternal(ctx) @@ -288,7 +288,7 @@ open class Container( //val bounds = this.getLocalBounds(Rectangle()) var renderedCount = 0 var culledCount = 0 - Rectangle.POOL.alloc2 { tempRect2, tempRect -> + MRectangle.POOL.alloc2 { tempRect2, tempRect -> val bounds = clippingContainer?.getGlobalBounds(tempRect2) fastForEachChildRender { child: View -> //if (bounds.intersects(child.getLocalBoundsOptimized(includeFilters = true))) { @@ -310,9 +310,9 @@ open class Container( } private val bb = BoundsBuilder() - private val tempRect = Rectangle() + private val tempRect = MRectangle() - override fun getLocalBoundsInternal(out: Rectangle) { + override fun getLocalBoundsInternal(out: MRectangle) { bb.reset() fastForEachChild { child: View -> child.getBounds(this, tempRect) diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/view/FixedSizeContainer.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/view/FixedSizeContainer.kt index 834a6f7a5a..04a7f412ca 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/view/FixedSizeContainer.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/view/FixedSizeContainer.kt @@ -36,7 +36,7 @@ open class FixedSizeContainer( open var clip: Boolean = false, ) : Container(), View.Reference { - override fun getLocalBoundsInternal(out: Rectangle) { + override fun getLocalBoundsInternal(out: MRectangle) { out.setTo(0.0, 0.0, width, height) } @@ -46,10 +46,10 @@ open class FixedSizeContainer( return out } - private val tempBounds = Rectangle() + private val tempBounds = MRectangle() private var renderingInternal = false - private val tempRect = Rectangle() + private val tempRect = MRectangle() @OptIn(KorgeInternal::class) override fun renderInternal(ctx: RenderContext) { @@ -112,7 +112,7 @@ open class FixedSizeContainer( } } -fun View.getVisibleLocalArea(out: Rectangle = Rectangle()): Rectangle { +fun View.getVisibleLocalArea(out: MRectangle = MRectangle()): MRectangle { getVisibleGlobalArea(out) val x0 = globalToLocalX(out.left, out.top) val x1 = globalToLocalX(out.right, out.top) @@ -136,14 +136,14 @@ fun View.getNextClippingView(): View { return this } -fun View.getVisibleGlobalArea(out: Rectangle = Rectangle()): Rectangle { +fun View.getVisibleGlobalArea(out: MRectangle = MRectangle()): MRectangle { forEachAscendant(includeThis = true) { if ((it is FixedSizeContainer && it.clip) || it is Stage) return@getVisibleGlobalArea it.getGlobalBounds(out) } return out.setTo(0.0, 0.0, 4096.0, 4096.0) } -fun View.getVisibleWindowArea(out: Rectangle = Rectangle()): Rectangle { +fun View.getVisibleWindowArea(out: MRectangle = MRectangle()): MRectangle { forEachAscendant(includeThis = true) { if ((it is FixedSizeContainer && it.clip) || it is Stage) return@getVisibleWindowArea it.getWindowBounds(out) } diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/view/HitTestable.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/view/HitTestable.kt index 410bd9e562..1a425a2894 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/view/HitTestable.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/view/HitTestable.kt @@ -1,18 +1,13 @@ package com.soywiz.korge.view import com.soywiz.kds.iterators.fastForEach -import com.soywiz.kmem.extract -import com.soywiz.kmem.insert import com.soywiz.korma.geom.Angle -import com.soywiz.korma.geom.Point -import com.soywiz.korma.geom.Vector2D -import com.soywiz.korma.geom.angleTo +import com.soywiz.korma.geom.MPoint +import com.soywiz.korma.geom.MVector2D import com.soywiz.korma.geom.cosine import com.soywiz.korma.geom.degrees -import com.soywiz.korma.geom.div import com.soywiz.korma.geom.plus import com.soywiz.korma.geom.times -import com.soywiz.korma.geom.vector.VectorPath @Deprecated("", replaceWith = ReplaceWith("com.soywiz.korma.geom.collider.HitTestable")) typealias HitTestable = com.soywiz.korma.geom.collider.HitTestable @@ -27,7 +22,7 @@ private val MOVE_SCALES = arrayOf(+1.0, -1.0) // @TODO: if dx & dy are big, we should check intermediary positions to ensure we are not jumping to the other side of the object fun View.moveWithHitTestable(collision: HitTestable, dx: Double, dy: Double, hitTestDirection: HitTestDirection? = null) { val char = this - val deltaXY = Point(dx, dy) + val deltaXY = MPoint(dx, dy) val angle = Angle.between(0.0, 0.0, deltaXY.x, deltaXY.y) val length = deltaXY.length val oldX = char.x @@ -36,7 +31,7 @@ fun View.moveWithHitTestable(collision: HitTestable, dx: Double, dy: Double, hit MOVE_SCALES.fastForEach { dscale -> val rangle = angle + dangle * dscale val lengthScale = dangle.cosine - val dpoint = Point.fromPolar(rangle, length * lengthScale) + val dpoint = MPoint.fromPolar(rangle, length * lengthScale) char.x = oldX + dpoint.x char.y = oldY + dpoint.y if (!collision.hitTestAny( @@ -51,13 +46,13 @@ fun View.moveWithHitTestable(collision: HitTestable, dx: Double, dy: Double, hit char.y = oldY } -fun View.moveWithCollisions(collision: List, delta: Vector2D, kind: CollisionKind = CollisionKind.SHAPE) { +fun View.moveWithCollisions(collision: List, delta: MVector2D, kind: CollisionKind = CollisionKind.SHAPE) { return moveWithCollisions(collision, delta.x, delta.y, kind) } fun View.moveWithCollisions(collision: List, dx: Double, dy: Double, kind: CollisionKind = CollisionKind.SHAPE) { val char = this - val deltaXY = Point(dx, dy) + val deltaXY = MPoint(dx, dy) val angle = Angle.between(0.0, 0.0, deltaXY.x, deltaXY.y) val length = deltaXY.length val oldX = char.x @@ -66,7 +61,7 @@ fun View.moveWithCollisions(collision: List, dx: Double, dy: Double, kind: MOVE_SCALES.fastForEach { dscale -> val rangle = angle + dangle * dscale val lengthScale = dangle.cosine - val dpoint = Point.fromPolar(rangle, length * lengthScale) + val dpoint = MPoint.fromPolar(rangle, length * lengthScale) char.x = oldX + dpoint.x char.y = oldY + dpoint.y //char.hitTestView(collision, kind) diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/view/Image.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/view/Image.kt index 8e7db038c3..cfe40f9bd7 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/view/Image.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/view/Image.kt @@ -111,7 +111,7 @@ open class BaseImage( override val anchorDispX get() = (anchorDispXNoOffset - frameOffsetX) override val anchorDispY get() = (anchorDispYNoOffset - frameOffsetY) - override fun getLocalBoundsInternal(out: Rectangle) { + override fun getLocalBoundsInternal(out: MRectangle) { out.setTo(-anchorDispXNoOffset, -anchorDispYNoOffset, frameWidth, frameHeight) } diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/view/Line.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/view/Line.kt index a01e210274..fcc5636671 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/view/Line.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/view/Line.kt @@ -4,9 +4,9 @@ import com.soywiz.korge.render.RenderContext import com.soywiz.korge.render.useLineBatcher import com.soywiz.korim.color.Colors import com.soywiz.korim.color.RGBA -import com.soywiz.korma.geom.Point +import com.soywiz.korma.geom.MPoint -inline fun Container.line(a: Point, b: Point, color: RGBA = Colors.WHITE, callback: @ViewDslMarker Line.() -> Unit = {}) +inline fun Container.line(a: MPoint, b: MPoint, color: RGBA = Colors.WHITE, callback: @ViewDslMarker Line.() -> Unit = {}) = Line(a.x, a.y, b.x, b.y, color).addTo(this, callback) inline fun Container.line(x0: Double, y0: Double, x1: Double, y1: Double, color: RGBA = Colors.WHITE, callback: @ViewDslMarker Line.() -> Unit = {}) @@ -28,7 +28,7 @@ class Line( colorMul = color } - fun setPoints(a: Point, b: Point) = setPoints(a.x, a.y, b.x, b.y) + fun setPoints(a: MPoint, b: MPoint) = setPoints(a.x, a.y, b.x, b.y) fun setPoints(x1: Double, y1: Double, x2: Double, y2: Double) { this.x1 = x1 diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/view/Mesh.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/view/Mesh.kt index 8f97750c63..21c0c7cdba 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/view/Mesh.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/view/Mesh.kt @@ -6,7 +6,7 @@ import com.soywiz.korge.render.TexturedVertexArray import com.soywiz.korim.bitmap.Bitmaps import com.soywiz.korim.bitmap.BmpSlice import com.soywiz.korma.geom.BoundsBuilder -import com.soywiz.korma.geom.Rectangle +import com.soywiz.korma.geom.MRectangle open class Mesh( var texture: BmpSlice? = null, @@ -30,7 +30,7 @@ open class Mesh( private var tva: TexturedVertexArray? = null private val bb = BoundsBuilder() - private val localBounds = Rectangle() + private val localBounds = MRectangle() private fun recomputeVerticesIfRequired() { if (!dirtyVertices) return @@ -80,7 +80,7 @@ open class Mesh( } } - override fun getLocalBoundsInternal(out: Rectangle) { + override fun getLocalBoundsInternal(out: MRectangle) { recomputeVerticesIfRequired() out.copyFrom(localBounds) } diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/view/NinePatch.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/view/NinePatch.kt index ff24837927..073c5d9fcb 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/view/NinePatch.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/view/NinePatch.kt @@ -2,8 +2,8 @@ package com.soywiz.korge.view import com.soywiz.korge.render.RenderContext import com.soywiz.korim.bitmap.BmpSlice -import com.soywiz.korma.geom.Point -import com.soywiz.korma.geom.Rectangle +import com.soywiz.korma.geom.MPoint +import com.soywiz.korma.geom.MRectangle import kotlin.math.min inline fun Container.ninePatch( @@ -26,17 +26,17 @@ class NinePatch( private val sTop = 0.0 val posCuts = arrayOf( - Point(0, 0), - Point(left, top), - Point(1.0 - right, 1.0 - bottom), - Point(1.0, 1.0) + MPoint(0, 0), + MPoint(left, top), + MPoint(1.0 - right, 1.0 - bottom), + MPoint(1.0, 1.0) ) val texCuts = arrayOf( - Point(0, 0), - Point(left, top), - Point(1.0 - right, 1.0 - bottom), - Point(1.0, 1.0) + MPoint(0, 0), + MPoint(left, top), + MPoint(1.0 - right, 1.0 - bottom), + MPoint(1.0, 1.0) ) override fun renderInternal(ctx: RenderContext) { @@ -81,7 +81,7 @@ class NinePatch( } } - override fun getLocalBoundsInternal(out: Rectangle) { + override fun getLocalBoundsInternal(out: MRectangle) { out.setTo(sLeft, sTop, width, height) } diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/view/NinePatchEx.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/view/NinePatchEx.kt index 8171417d23..dcde2bf257 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/view/NinePatchEx.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/view/NinePatchEx.kt @@ -76,7 +76,7 @@ class NinePatchEx( internal var renderedVersion = 0 private var tva: TexturedVertexArray? = null private var tvaCached: TexturedVertexArray? = null - private var cachedMatrix: Matrix = Matrix() + private var cachedMatrix: MMatrix = MMatrix() private var cachedRenderColorMul = Colors.WHITE private var cachedNinePatch: NinePatchBmpSlice? = null @@ -98,7 +98,7 @@ class NinePatchEx( val indices = TexturedVertexArray.quadIndices(numQuads) val tva = TexturedVertexArray(numQuads * 4, indices) var index = 0 - val matrix = Matrix() + val matrix = MMatrix() ninePatch.info.computeScale(viewBounds) { segment, x, y, width, height -> val bmpSlice = ninePatch.getSegmentBmpSlice(segment) tva.quad(index++ * 4, @@ -113,7 +113,7 @@ class NinePatchEx( renderedVersion++ } - override fun getLocalBoundsInternal(out: Rectangle) { + override fun getLocalBoundsInternal(out: MRectangle) { out.setTo(0.0, 0.0, width, height) } diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/view/NinePatchShapeView.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/view/NinePatchShapeView.kt index 479e50c4c7..95c8d5a0c5 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/view/NinePatchShapeView.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/view/NinePatchShapeView.kt @@ -32,6 +32,6 @@ class NinePatchShapeView( override fun onSizeChanged() { super.onSizeChanged() - graphics.shape = shape.transform(Size(width, height)) + graphics.shape = shape.transform(MSize(width, height)) } } diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/view/QView.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/view/QView.kt index 3cd40adcf1..adfa6689ed 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/view/QView.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/view/QView.kt @@ -21,7 +21,7 @@ class QView(val views: List) : List by views, BView { operator fun get(name: String): QView = QView(views.mapNotNull { it.firstDescendantWith { it.name == name } }) - fun position(): IPoint = first.pos + fun position(): IPoint = first.ipos fun setProperty(prop: KMutableProperty1, value: T) { views.fastForEach { prop.set(it, value) } diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/view/RectBase.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/view/RectBase.kt index fb53a3ff02..19de0f38ae 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/view/RectBase.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/view/RectBase.kt @@ -91,7 +91,7 @@ open class RectBase( vertices.quad(0, sLeft, sTop, bwidth, bheight, globalMatrix, baseBitmap, renderColorMul, renderColorAdd) } - override fun getLocalBoundsInternal(out: Rectangle) { + override fun getLocalBoundsInternal(out: MRectangle) { out.setTo(sLeft, sTop, bwidth, bheight) } diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/view/ShadedView.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/view/ShadedView.kt index 8d94c05c43..f9076f9306 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/view/ShadedView.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/view/ShadedView.kt @@ -25,7 +25,7 @@ open class ShadedView( this.program = program } - var padding: Margin = Margin(0.0) + var padding: IMargin = IMargin(0.0) set(value) { field = value dirtyVertices = true diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/view/Stage.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/view/Stage.kt index 62b87aa89b..c58a46aa2c 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/view/Stage.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/view/Stage.kt @@ -8,7 +8,6 @@ import com.soywiz.korge.input.* import com.soywiz.korge.view.property.* import com.soywiz.korgw.* import com.soywiz.korinject.* -import com.soywiz.korio.annotations.* import com.soywiz.korio.resources.* import com.soywiz.korma.annotations.* import com.soywiz.korma.geom.* @@ -50,7 +49,7 @@ open class Stage internal constructor(override val views: Views) : FixedSizeCont gameWindow.runBlockingNoJs(this.coroutineContext, block) /** Mouse coordinates relative to the [Stage] singleton */ - val mouseXY: Point = Point(0.0, 0.0) + val mouseXY: MPoint = MPoint(0.0, 0.0) get() { field.setTo(mouseX, mouseY) return field @@ -81,7 +80,7 @@ open class Stage internal constructor(override val views: Views) : FixedSizeCont @Suppress("unused") @ViewProperty(min = 0.0, max = 2000.0, groupName = "Stage") private var virtualSize: IPoint - get() = Point(views.virtualWidthDouble, views.virtualHeightDouble) + get() = MPoint(views.virtualWidthDouble, views.virtualHeightDouble) set(value) { views.virtualWidthDouble = value.x views.virtualHeightDouble = value.y diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/view/Text.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/view/Text.kt index b10aa5978f..935e232307 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/view/Text.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/view/Text.kt @@ -176,10 +176,10 @@ open class Text( } } - private val _textBounds = Rectangle(0, 0, 2048, 2048) + private val _textBounds = MRectangle(0, 0, 2048, 2048) var autoSize = true private var boundsVersion = -1 - val textBounds: Rectangle + val textBounds: MRectangle get() { getLocalBounds(_textBounds) return _textBounds @@ -213,7 +213,7 @@ open class Text( invalidate() } - override fun getLocalBoundsInternal(out: Rectangle) { + override fun getLocalBoundsInternal(out: MRectangle) { _renderInternal(null) if (filter != null || backdropFilter != null) { super.getLocalBoundsInternal(out) // This is required for getting proper bounds when glyphs are transformed @@ -222,7 +222,7 @@ open class Text( } } - private val tempMatrix = Matrix() + private val tempMatrix = MMatrix() override fun renderInternal(ctx: RenderContext) { _renderInternal(ctx) @@ -261,7 +261,7 @@ open class Text( private var lastSmoothing: Boolean? = null private var lastNativeRendering: Boolean? = null private var tva: TexturedVertexArray? = null - private val identityMat = Matrix() + private val identityMat = MMatrix() var graphicsRenderer: GraphicsRenderer = GraphicsRenderer.SYSTEM set(value) { diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/view/TextBlock.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/view/TextBlock.kt index aed47154f0..29b877d651 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/view/TextBlock.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/view/TextBlock.kt @@ -47,7 +47,7 @@ class TextBlock( @ViewProperty var ellipsis: String? = "..."; set(value) { field = value; invalidProps() } @ViewProperty - var padding: Margin = Margin.EMPTY; set(value) { field = value; invalidProps() } + var padding: IMargin = IMargin.EMPTY; set(value) { field = value; invalidProps() } @ViewProperty var autoSize: Boolean = false; set(value) { field = value; invalidateText() } //@ViewProperty(min = 0.0, max = 10.0, clampMin = true) @@ -102,7 +102,7 @@ class TextBlock( bmp.context2d { drawRichText( text, - bounds = Rectangle.fromBounds(padding.left, padding.top, width - padding.right, height - padding.bottom), + bounds = MRectangle.fromBounds(padding.left, padding.top, width - padding.right, height - padding.bottom), includePartialLines = includePartialLines, wordWrap = wordWrap, ellipsis = ellipsis, align = align, fill = fill, stroke = stroke, includeFirstLineAlways = true, textRangeStart = textRangeStart, textRangeEnd = textRangeEnd @@ -116,7 +116,7 @@ class TextBlock( if (allBitmap == true) { if (dirty || placements == null) { dirty = false - placements = text.place(Rectangle(padding.left, padding.top, width - padding.right, height - padding.bottom), wordWrap, includePartialLines, ellipsis, fill, stroke, align, includeFirstLineAlways = includeFirstLineAlways) + placements = text.place(MRectangle(padding.left, padding.top, width - padding.right, height - padding.bottom), wordWrap, includePartialLines, ellipsis, fill, stroke, align, includeFirstLineAlways = includeFirstLineAlways) } image?.removeFromParent() image = null diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/view/TextOld.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/view/TextOld.kt index d8e659ac6a..a4e3e7b03e 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/view/TextOld.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/view/TextOld.kt @@ -11,7 +11,7 @@ import com.soywiz.korim.color.Colors import com.soywiz.korim.color.RGBA import com.soywiz.korim.font.BitmapFont import com.soywiz.korim.font.Font -import com.soywiz.korma.geom.Rectangle +import com.soywiz.korma.geom.MRectangle @KorgeDeprecated inline fun Container.textOld( @@ -41,8 +41,8 @@ class TextOld : View(), IText, IHtml { //var verticalAlign: Html.VerticalAlignment = Html.VerticalAlignment.TOP var fontsCatalog: Html.FontsCatalog = Html.DefaultFontCatalogWithoutSystemFonts - val textBounds = Rectangle(0, 0, 1024, 1024) - private val tempRect = Rectangle() + val textBounds = MRectangle(0, 0, 1024, 1024) + private val tempRect = MRectangle() var _text: String = "" var _html: String = "" var document: Html.Document? = null @@ -71,7 +71,7 @@ class TextOld : View(), IText, IHtml { } } - fun setTextBounds(rect: Rectangle) { + fun setTextBounds(rect: MRectangle) { this.textBounds.copyFrom(rect) autoSize = false } @@ -213,7 +213,7 @@ class TextOld : View(), IText, IHtml { if (autoSize) recalculateBounds() } - override fun getLocalBoundsInternal(out: Rectangle) { + override fun getLocalBoundsInternal(out: MRectangle) { if (document != null) { out.copyFrom(document!!.bounds) } else { diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/view/View.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/view/View.kt index 0c3abf36ab..e04e85254c 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/view/View.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/view/View.kt @@ -59,7 +59,6 @@ abstract class View internal constructor( ) : BaseView(), Renderable , Extra , BView - , XY , HitTestable , WithHitShape2d //, EventDispatcher by EventDispatcher.Mixin() @@ -270,7 +269,7 @@ abstract class View internal constructor( private var _skewY: Angle = Angle.ZERO private var _rotation: Angle = Angle.ZERO - private val _pos = Point() + private val _pos = MPoint() protected open fun setXY(x: Double, y: Double) { ensureTransform() @@ -281,19 +280,25 @@ abstract class View internal constructor( } } - fun getPosition(out: Point = Point()): Point { + @Deprecated("Use pos instead") + fun getPosition(out: MPoint = MPoint()): MPoint { out.copyFrom(out) return out } - /** Position of the view. **@NOTE**: If [pos] coordinates are manually changed, you should call [View.invalidateMatrix] later to keep the matrix in sync */ + /** Position of the view. **@NOTE**: If [ipos] coordinates are manually changed, you should call [View.invalidateMatrix] later to keep the matrix in sync */ //uiEditableValue(Pair(view::x, view::y), min = -1000.0, max = +1000.0, clamp = false, name = "position") @ViewProperty(min = -1000.0, max = +1000.0, name = "position") - var pos: IPoint + var ipos: IPoint + get() = MPoint(x, y) + set(value) = setXY(value.x, value.y) + + @ViewProperty(min = -1000.0, max = +1000.0, name = "position") + var pos: Point get() = Point(x, y) set(value) = setXY(value.x, value.y) - var posOpt: Point + var posOpt: MPoint get() { _pos.setTo(x, y) return _pos @@ -303,7 +308,7 @@ abstract class View internal constructor( } /** Local X position of this view */ - override var x: Double + var x: Double get() { ensureTransform() return _x @@ -311,7 +316,7 @@ abstract class View internal constructor( set(v) { setXY(v, y) } /** Local Y position of this view */ - override var y: Double + var y: Double get() { ensureTransform() return _y @@ -411,7 +416,7 @@ abstract class View internal constructor( setGlobalXY(globalX, value) } - fun setGlobalXY(pos: Point) = setGlobalXY(pos.x, pos.y) + fun setGlobalXY(pos: MPoint) = setGlobalXY(pos.x, pos.y) fun setGlobalXY(x: Double, y: Double) { setXY( @@ -420,8 +425,8 @@ abstract class View internal constructor( ) } - fun globalXY(out: Point = Point()): Point = out.setTo(globalX, globalY) - fun localXY(out: Point = Point()): Point = out.setTo(x, y) + fun globalXY(out: MPoint = MPoint()): MPoint = out.setTo(globalX, globalY) + fun localXY(out: MPoint = MPoint()): MPoint = out.setTo(x, y) /** * Changes the [width] and [height] to match the parameters. @@ -552,7 +557,7 @@ abstract class View internal constructor( this.colorMul = value } - private val tempTransform = Matrix.Transform() + private val tempTransform = MMatrix.Transform() //private val tempMatrix = Matrix2d() protected fun ensureTransform() { @@ -590,26 +595,26 @@ abstract class View internal constructor( } } - /** Sets the local transform matrix that includes [x], [y], [scaleX], [scaleY], [rotation], [skewX] and [skewY] encoded into a [Matrix] */ - fun setMatrix(matrix: Matrix) { + /** Sets the local transform matrix that includes [x], [y], [scaleX], [scaleY], [rotation], [skewX] and [skewY] encoded into a [MMatrix] */ + fun setMatrix(matrix: MMatrix) { this._localMatrix.copyFrom(matrix) this.validLocalProps = false invalidate() } /** Like [setMatrix] but directly sets an interpolated version of the [l] and [r] matrices with the [ratio] */ - fun setMatrixInterpolated(ratio: Double, l: Matrix, r: Matrix) { + fun setMatrixInterpolated(ratio: Double, l: MMatrix, r: MMatrix) { this._localMatrix.setToInterpolated(ratio, l, r) this.validLocalProps = false invalidate() } /** - * Sets the computed transform [Matrix] and all the decomposed transform properties at once. + * Sets the computed transform [MMatrix] and all the decomposed transform properties at once. * Normally this is used by animation libraries to set Views in a way that are fast to update * and to access. */ - fun setComputedTransform(transform: Matrix.Computed) { + fun setComputedTransform(transform: MMatrix.Computed) { _localMatrix.copyFrom(transform.matrix) _setTransform(transform.transform) invalidate() @@ -618,10 +623,10 @@ abstract class View internal constructor( } /** - * Sets the [Matrix.Transform] decomposed version of the transformation, + * Sets the [MMatrix.Transform] decomposed version of the transformation, * that directly includes [x], [y], [scaleX], [scaleY], [rotation], [skewX] and [skewY]. */ - fun setTransform(transform: Matrix.Transform) { + fun setTransform(transform: MMatrix.Transform) { _setTransform(transform) invalidate() validLocalProps = true @@ -632,7 +637,7 @@ abstract class View internal constructor( * Like [setTransform] but without invalidation. If used at all, should be used with care and invalidate when required. */ @KorgeInternal - fun _setTransform(t: Matrix.Transform) { + fun _setTransform(t: MMatrix.Transform) { //transform.toMatrix(_localMatrix) _x = t.x; _y = t.y _scaleX = t.scaleX; _scaleY = t.scaleY @@ -647,13 +652,13 @@ abstract class View internal constructor( internal var validLocalProps = true internal var validLocalMatrix = true - private val _localMatrix = Matrix() + private val _localMatrix = MMatrix() /** - * Local transform [Matrix]. If you plan to change its components manually + * Local transform [MMatrix]. If you plan to change its components manually * instead of setting it directly, you should call the [View.invalidate] method. */ - var localMatrix: Matrix + var localMatrix: MMatrix get() { if (!validLocalMatrix) { validLocalMatrix = true @@ -667,14 +672,14 @@ abstract class View internal constructor( invalidate() } - private var _globalMatrix = Matrix() + private var _globalMatrix = MMatrix() private var _globalMatrixVersion = -1 /** - * Global transform [Matrix]. + * Global transform [MMatrix]. * Matrix that concatenates all the affine transforms of this view and its ancestors. */ - var globalMatrix: Matrix + var globalMatrix: MMatrix get() { if (_globalMatrixVersion != this._version) { _globalMatrixVersion = this._version @@ -696,13 +701,13 @@ abstract class View internal constructor( } } - private val _globalMatrixInv = Matrix() + private val _globalMatrixInv = MMatrix() private var _globalMatrixInvVersion = -1 /** * The inverted version of the [globalMatrix] */ - val globalMatrixInv: Matrix + val globalMatrixInv: MMatrix get() { if (_globalMatrixInvVersion != this._version) { _globalMatrixInvVersion = this._version @@ -808,12 +813,12 @@ abstract class View internal constructor( /** Computes the local Y coordinate of the mouse using the coords from the [Views] object */ fun localMouseY(views: Views): Double = this.globalMatrixInv.transformY(views.input.mouse) - /** Computes the local X and Y coordinate of the mouse using the coords from the [Views] object. You can use the [target] parameter to specify a target [Point] to avoid allocation. */ - fun localMouseXY(views: Views, target: Point = Point()): Point = + /** Computes the local X and Y coordinate of the mouse using the coords from the [Views] object. You can use the [target] parameter to specify a target [MPoint] to avoid allocation. */ + fun localMouseXY(views: Views, target: MPoint = MPoint()): MPoint = target.setTo(localMouseX(views), localMouseY(views)) /** - * Invalidates the [localMatrix] [Matrix], so it gets updated from the decomposed properties: [x], [y], [scaleX], [scaleY], [rotation], [skewX] and [skewY]. + * Invalidates the [localMatrix] [MMatrix], so it gets updated from the decomposed properties: [x], [y], [scaleX], [scaleY], [rotation], [skewX] and [skewY]. */ fun invalidateMatrix() { validLocalMatrix = false @@ -942,10 +947,10 @@ abstract class View internal constructor( } } lines.drawVector(Colors.RED) { - moveTo(localToGlobal(Point(local.left, local.top))) - lineTo(localToGlobal(Point(local.right, local.top))) - lineTo(localToGlobal(Point(local.right, local.bottom))) - lineTo(localToGlobal(Point(local.left, local.bottom))) + moveTo(localToGlobal(MPoint(local.left, local.top))) + lineTo(localToGlobal(MPoint(local.right, local.top))) + lineTo(localToGlobal(MPoint(local.right, local.bottom))) + lineTo(localToGlobal(MPoint(local.left, local.bottom))) close() } lines.drawVector(Colors.YELLOW) { @@ -993,10 +998,10 @@ abstract class View internal constructor( // Version with root-most object as reference /** Converts the global point [p] (using root/stage as reference) into the local coordinate system. Allows to define [out] to avoid allocation. */ - fun globalToLocal(p: IPoint, out: Point = Point()): Point = globalToLocalXY(p.x, p.y, out) + fun globalToLocal(p: IPoint, out: MPoint = MPoint()): MPoint = globalToLocalXY(p.x, p.y, out) /** Converts the global point [x] [y] (using root/stage as reference) into the local coordinate system. Allows to define [out] to avoid allocation. */ - fun globalToLocalXY(x: Double, y: Double, out: Point = Point()): Point = this.globalMatrixInv.transform(x, y, out) + fun globalToLocalXY(x: Double, y: Double, out: MPoint = MPoint()): MPoint = this.globalMatrixInv.transform(x, y, out) /** Converts the global point [x], [y] (using root/stage as reference) into the X in the local coordinate system. */ fun globalToLocalX(x: Double, y: Double): Double = this.globalMatrixInv.transformX(x, y) @@ -1006,17 +1011,17 @@ abstract class View internal constructor( fun globalToLocalDX(x0: Double, y0: Double, x1: Double, y1: Double): Double = globalToLocalX(x1, y1) - globalToLocalX(x0, y0) fun globalToLocalDY(x0: Double, y0: Double, x1: Double, y1: Double): Double = globalToLocalY(x1, y1) - globalToLocalY(x0, y0) - fun globalToLocalDXY(x0: Double, y0: Double, x1: Double, y1: Double, out: Point = Point()): Point = out.setTo( + fun globalToLocalDXY(x0: Double, y0: Double, x1: Double, y1: Double, out: MPoint = MPoint()): MPoint = out.setTo( globalToLocalDX(x0, y0, x1, y1), globalToLocalDY(x0, y0, x1, y1), ) - fun globalToLocalDXY(p0: IPoint, p1: IPoint, out: Point = Point()): Point = globalToLocalDXY(p0.x, p0.y, p1.x, p1.y, out) + fun globalToLocalDXY(p0: IPoint, p1: IPoint, out: MPoint = MPoint()): MPoint = globalToLocalDXY(p0.x, p0.y, p1.x, p1.y, out) /** Converts the local point [p] into a global point (using root/stage as reference). Allows to define [out] to avoid allocation. */ - fun localToGlobal(p: IPoint, out: Point = Point()): Point = localToGlobalXY(p.x, p.y, out) + fun localToGlobal(p: IPoint, out: MPoint = MPoint()): MPoint = localToGlobalXY(p.x, p.y, out) /** Converts the local point [x], [y] into a global point (using root/stage as reference). Allows to define [out] to avoid allocation. */ - fun localToGlobalXY(x: Double, y: Double, out: Point = Point()): Point = this.globalMatrix.transform(x, y, out) + fun localToGlobalXY(x: Double, y: Double, out: MPoint = MPoint()): MPoint = this.globalMatrix.transform(x, y, out) /** Converts the local point [x], [y] into a global X coordinate (using root/stage as reference). */ fun localToGlobalX(x: Double, y: Double): Double = this.globalMatrix.transformX(x, y) @@ -1027,10 +1032,10 @@ abstract class View internal constructor( // Version with View.Reference as reference /** Converts a point [p] in the nearest ancestor marked as [View.Reference] into the local coordinate system. Allows to define [out] to avoid allocation. */ - fun renderToLocal(p: IPoint, out: Point = Point()): Point = renderToLocalXY(p.x, p.y, out) + fun renderToLocal(p: IPoint, out: MPoint = MPoint()): MPoint = renderToLocalXY(p.x, p.y, out) /** Converts a point [x], [y] in the nearest ancestor marked as [View.Reference] into the local coordinate system. Allows to define [out] to avoid allocation. */ - fun renderToLocalXY(x: Double, y: Double, out: Point = Point()): Point = this.globalMatrixInv.transform(x, y, out) + fun renderToLocalXY(x: Double, y: Double, out: MPoint = MPoint()): MPoint = this.globalMatrixInv.transform(x, y, out) /** Converts a point [x], [y] in the nearest ancestor marked as [View.Reference] into the local X coordinate. */ fun renderToLocalX(x: Double, y: Double): Double = this.globalMatrixInv.transformX(x, y) @@ -1041,11 +1046,11 @@ abstract class View internal constructor( /** Converts the local point [p] into a point in the nearest ancestor masked as [View.Reference]. Allows to define [out] to avoid allocation. */ @Deprecated("") - fun localToRender(p: IPoint, out: Point = Point()): Point = localToRenderXY(p.x, p.y, out) + fun localToRender(p: IPoint, out: MPoint = MPoint()): MPoint = localToRenderXY(p.x, p.y, out) /** Converts the local point [x],[y] into a point in the nearest ancestor masked as [View.Reference]. Allows to define [out] to avoid allocation. */ @Deprecated("") - fun localToRenderXY(x: Double, y: Double, out: Point = Point()): Point = this.globalMatrix.transform(x, y, out) + fun localToRenderXY(x: Double, y: Double, out: MPoint = MPoint()): MPoint = this.globalMatrix.transform(x, y, out) /** Converts the local point [x],[y] into a X coordinate in the nearest ancestor masked as [View.Reference]. */ @Deprecated("") @@ -1058,20 +1063,20 @@ abstract class View internal constructor( /** Converts the local point [p] into a point in window coordinates. */ - fun localToWindow(views: Views, p: IPoint, out: Point = Point()): Point = localToWindowXY(views, p.x, p.y, out) + fun localToWindow(views: Views, p: IPoint, out: MPoint = MPoint()): MPoint = localToWindowXY(views, p.x, p.y, out) /** Converts the local point [x], [y] into a point in window coordinates. */ - fun localToWindowXY(views: Views, x: Double, y: Double, out: Point = Point()): Point { + fun localToWindowXY(views: Views, x: Double, y: Double, out: MPoint = MPoint()): MPoint { this.globalMatrix.transform(x, y, out) views.globalToWindowMatrix.transform(out, out) return out } /** Converts the local point [x], [y] into a X coordinate in window coordinates. */ - fun localToWindowX(views: Views, x: Double, y: Double): Double = Point.POOL { localToWindowXY(views, x, y, it).x } + fun localToWindowX(views: Views, x: Double, y: Double): Double = MPoint.POOL { localToWindowXY(views, x, y, it).x } /** Converts the local point [x], [y] into a Y coordinate in window coordinates. */ - fun localToWindowY(views: Views, x: Double, y: Double): Double = Point.POOL { localToWindowXY(views, x, y, it).y } + fun localToWindowY(views: Views, x: Double, y: Double): Double = MPoint.POOL { localToWindowXY(views, x, y, it).y } var hitTestEnabled = true @@ -1122,14 +1127,14 @@ abstract class View internal constructor( } } } - val res = Matrix.POOL.alloc { tempMatrix1 -> + val res = MMatrix.POOL.alloc { tempMatrix1 -> hitTestShapeInternal(view.hitShape2d, view.getGlobalMatrixWithAnchor(tempMatrix1), direction) } if (res != null) return res return if (this is Stage) this else null } - fun hitTestShape(shape: Shape2d, matrix: Matrix, direction: HitTestDirection = HitTestDirection.ANY): View? { + fun hitTestShape(shape: Shape2d, matrix: MMatrix, direction: HitTestDirection = HitTestDirection.ANY): View? { if (!hitTestEnabled) return null if (!visible) return null if (_hitShape2d == null) { @@ -1145,9 +1150,9 @@ abstract class View internal constructor( } open val customHitShape get() = false - protected open fun hitTestShapeInternal(shape: Shape2d, matrix: Matrix, direction: HitTestDirection): View? { + protected open fun hitTestShapeInternal(shape: Shape2d, matrix: MMatrix, direction: HitTestDirection): View? { //println("View.hitTestShapeInternal: $this, $shape") - if (Matrix.POOL.alloc2 { tempMatrix2, tempMatrix -> Shape2d.intersects(this.hitShape2d, getGlobalMatrixWithAnchor(tempMatrix2), shape, matrix, tempMatrix) }) { + if (MMatrix.POOL.alloc2 { tempMatrix2, tempMatrix -> Shape2d.intersects(this.hitShape2d, getGlobalMatrixWithAnchor(tempMatrix2), shape, matrix, tempMatrix) }) { //println(" -> true") return this } @@ -1170,7 +1175,7 @@ abstract class View internal constructor( hitTestInternal(x, y)?.let { view -> // @TODO: This should not be required if we compute bounds - Rectangle.POOL { tempRect -> + MRectangle.POOL { tempRect -> val area = getClippingAreaInternal(tempRect) if (area != null && !area.contains(x, y)) return null return view @@ -1180,10 +1185,10 @@ abstract class View internal constructor( } @KorgeInternal - fun getClippingAreaInternal(out: Rectangle): Rectangle? { + fun getClippingAreaInternal(out: MRectangle): MRectangle? { out.setTo(Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY) var count = 0 - Rectangle.POOL { _localBounds -> + MRectangle.POOL { _localBounds -> forEachAscendant(true) { if (it !is Stage && it is FixedSizeContainer && it.clip) { it.getGlobalBounds(_localBounds) @@ -1367,11 +1372,11 @@ abstract class View internal constructor( //fun getConcatMatrix(target: View, out: Matrix = Matrix()): Matrix = getConcatMatrix(target, false, out) /** - * Gets the concatenated [Matrix] of this [View] up to the [target] view. + * Gets the concatenated [MMatrix] of this [View] up to the [target] view. * If [inclusive] is true, the concatenated matrix will include the [target] view too. * Allows to define an [out] matrix that will hold the result to prevent allocations. */ - fun getConcatMatrix(target: View, out: Matrix = Matrix(), inclusive: Boolean = false): Matrix { + fun getConcatMatrix(target: View, out: MMatrix = MMatrix(), inclusive: Boolean = false): MMatrix { when { target === parent -> out.copyFrom(this.localMatrix) target === this -> out.identity() @@ -1396,7 +1401,7 @@ abstract class View internal constructor( return out } - fun getConcatMatrixAccurateSlow(target: View, out: Matrix = Matrix(), inclusive: Boolean = false): Matrix { + fun getConcatMatrixAccurateSlow(target: View, out: MMatrix = MMatrix(), inclusive: Boolean = false): MMatrix { out.identity() if (target !== this) { var current: View? = this @@ -1410,36 +1415,36 @@ abstract class View internal constructor( } /** Returns the global bounds of this object. Note this incurs in allocations. Use [getGlobalBounds] (out) to avoid it */ - val windowBounds: Rectangle get() = getWindowBounds() + val windowBounds: MRectangle get() = getWindowBounds() - /** Returns the global bounds of this object. Allows to specify an [out] [Rectangle] to prevent allocations. */ + /** Returns the global bounds of this object. Allows to specify an [out] [MRectangle] to prevent allocations. */ @Deprecated("") - fun getWindowBounds(out: Rectangle = Rectangle()): Rectangle = getWindowBoundsOrNull(out) ?: getGlobalBounds(out) + fun getWindowBounds(out: MRectangle = MRectangle()): MRectangle = getWindowBoundsOrNull(out) ?: getGlobalBounds(out) - fun getWindowBoundsOrNull(out: Rectangle = Rectangle()): Rectangle? { + fun getWindowBoundsOrNull(out: MRectangle = MRectangle()): MRectangle? { val stage = root if (stage !is Stage) return null //return getBounds(stage, out, inclusive = true).applyTransform(stage.views.globalToWindowMatrix) return getWindowBounds(stage, out) } - fun getWindowBounds(bp: BoundsProvider, out: Rectangle = Rectangle()): Rectangle = + fun getWindowBounds(bp: BoundsProvider, out: MRectangle = MRectangle()): MRectangle = getGlobalBounds(out).applyTransform(bp.globalToWindowMatrix) - fun getRenderTargetBounds(ctx: RenderContext, out: Rectangle = Rectangle()): Rectangle { + fun getRenderTargetBounds(ctx: RenderContext, out: MRectangle = MRectangle()): MRectangle { //println("ctx.ag.isRenderingToWindow=${ctx.ag.isRenderingToWindow}") return if (ctx.isRenderingToWindow) getWindowBounds(ctx, out) else getGlobalBounds(out) } - fun getClippingBounds(ctx: RenderContext, out: Rectangle = Rectangle()): Rectangle = + fun getClippingBounds(ctx: RenderContext, out: MRectangle = MRectangle()): MRectangle = getRenderTargetBounds(ctx, out) /** Returns the global bounds of this object. Note this incurs in allocations. Use [getGlobalBounds] (out) to avoid it */ - val globalBounds: Rectangle get() = getGlobalBounds() + val globalBounds: MRectangle get() = getGlobalBounds() - /** Returns the global bounds of this object. Allows to specify an [out] [Rectangle] to prevent allocations. */ + /** Returns the global bounds of this object. Allows to specify an [out] [MRectangle] to prevent allocations. */ //fun getGlobalBounds(out: Rectangle = Rectangle()): Rectangle = getBounds(root, out, inclusive = false) - fun getGlobalBounds(out: Rectangle = Rectangle(), includeFilters: Boolean = false): Rectangle = getBounds(root, out, inclusive = true, includeFilters = includeFilters) + fun getGlobalBounds(out: MRectangle = MRectangle(), includeFilters: Boolean = false): MRectangle = getBounds(root, out, inclusive = true, includeFilters = includeFilters) /** Tries to set the global bounds of the object. If there are rotations in the ancestors, this might not work as expected. */ @KorgeUntested @@ -1455,12 +1460,12 @@ abstract class View internal constructor( // @TODO: Would not include strokes //fun getRect(target: View? = this, out: Rectangle = Rectangle()): Rectangle = TODO() - /** Get the bounds of this view, using the [target] view as coordinate system. Not providing a [target] will return the local bounds. Allows to specify [out] [Rectangle] to prevent allocations. */ - fun getBoundsNoAnchoring(target: View? = this, out: Rectangle = Rectangle(), inclusive: Boolean = false, includeFilters: Boolean = false): Rectangle { + /** Get the bounds of this view, using the [target] view as coordinate system. Not providing a [target] will return the local bounds. Allows to specify [out] [MRectangle] to prevent allocations. */ + fun getBoundsNoAnchoring(target: View? = this, out: MRectangle = MRectangle(), inclusive: Boolean = false, includeFilters: Boolean = false): MRectangle { return getBounds(target, out, false, inclusive, includeFilters) } - protected fun _getBounds(concat: Matrix?, out: Rectangle = Rectangle(), doAnchoring: Boolean = true, includeFilters: Boolean = false): Rectangle { + protected fun _getBounds(concat: MMatrix?, out: MRectangle = MRectangle(), doAnchoring: Boolean = true, includeFilters: Boolean = false): MRectangle { getLocalBounds(out, doAnchoring, includeFilters) if (concat != null && !concat.isIdentity()) { @@ -1487,8 +1492,8 @@ abstract class View internal constructor( return out } - fun getBounds(target: View? = this, out: Rectangle = Rectangle(), doAnchoring: Boolean = true, inclusive: Boolean = false, includeFilters: Boolean = false): Rectangle { - return Matrix.POOL { boundsTemp -> _getBounds(this.getConcatMatrix(target ?: this, boundsTemp, inclusive), out, doAnchoring, includeFilters) } + fun getBounds(target: View? = this, out: MRectangle = MRectangle(), doAnchoring: Boolean = true, inclusive: Boolean = false, includeFilters: Boolean = false): MRectangle { + return MMatrix.POOL { boundsTemp -> _getBounds(this.getConcatMatrix(target ?: this, boundsTemp, inclusive), out, doAnchoring, includeFilters) } } ///** Kind of bounds we are checking */ @@ -1500,19 +1505,19 @@ abstract class View internal constructor( //} /** - * **NOTE:** that if [out] is not provided, the [Rectangle] returned shouldn't stored and modified since it is owned by this class. + * **NOTE:** that if [out] is not provided, the [MRectangle] returned shouldn't stored and modified since it is owned by this class. */ - fun getLocalBoundsOptimized(includeFilters: Boolean = false): Rectangle = getLocalBounds(_localBounds, includeFilters = includeFilters) + fun getLocalBoundsOptimized(includeFilters: Boolean = false): MRectangle = getLocalBounds(_localBounds, includeFilters = includeFilters) - fun getLocalBoundsOptimizedAnchored(includeFilters: Boolean = false): Rectangle = getLocalBounds(_localBounds, doAnchoring = true, includeFilters = includeFilters) + fun getLocalBoundsOptimizedAnchored(includeFilters: Boolean = false): MRectangle = getLocalBounds(_localBounds, doAnchoring = true, includeFilters = includeFilters) @Deprecated("Allocates") - fun getLocalBounds(doAnchoring: Boolean = true, includeFilters: Boolean = false): Rectangle = getLocalBounds(Rectangle(), doAnchoring, includeFilters) + fun getLocalBounds(doAnchoring: Boolean = true, includeFilters: Boolean = false): MRectangle = getLocalBounds(MRectangle(), doAnchoring, includeFilters) /** - * Get local bounds of the view. Allows to specify [out] [Rectangle] if you want to reuse an object. + * Get local bounds of the view. Allows to specify [out] [MRectangle] if you want to reuse an object. */ - fun getLocalBounds(out: Rectangle, doAnchoring: Boolean = true, includeFilters: Boolean = false): Rectangle { + fun getLocalBounds(out: MRectangle, doAnchoring: Boolean = true, includeFilters: Boolean = false): MRectangle { getLocalBoundsInternal(out) val it = out if (!doAnchoring) { @@ -1525,8 +1530,8 @@ abstract class View internal constructor( return it } - private val _localBounds: Rectangle = Rectangle() - open fun getLocalBoundsInternal(out: Rectangle) { + private val _localBounds: MRectangle = MRectangle() + open fun getLocalBoundsInternal(out: MRectangle) { out.clear() } @@ -1566,16 +1571,16 @@ abstract class View internal constructor( this@apply.copyPropsFrom(this@View) } - fun globalLocalBoundsPointRatio(anchor: Anchor, out: Point = Point()): Point = globalLocalBoundsPointRatio(anchor.sx, anchor.sy, out) + fun globalLocalBoundsPointRatio(anchor: Anchor, out: MPoint = MPoint()): MPoint = globalLocalBoundsPointRatio(anchor.sx, anchor.sy, out) - fun globalLocalBoundsPointRatio(ratioX: Double, ratioY: Double, out: Point = Point()): Point { + fun globalLocalBoundsPointRatio(ratioX: Double, ratioY: Double, out: MPoint = MPoint()): MPoint { val bounds = getLocalBoundsOptimizedAnchored() val x = ratioX.interpolate(bounds.left, bounds.right) val y = ratioY.interpolate(bounds.top, bounds.bottom) return out.setTo(localToGlobalX(x, y), localToGlobalY(x, y)) } - fun getGlobalMatrixWithAnchor(out: Matrix = Matrix()): Matrix { + fun getGlobalMatrixWithAnchor(out: MMatrix = MMatrix()): MMatrix { val view = this out.copyFrom(view.localMatrix) out.pretranslate(-view.anchorDispX, -view.anchorDispY) @@ -1993,7 +1998,7 @@ fun T.position(x: Float, y: Float): T = xy(x.toDouble(), y.toDouble() fun T.position(x: Int, y: Int): T = xy(x.toDouble(), y.toDouble()) fun T.bounds(left: Double, top: Double, right: Double, bottom: Double): T = xy(left, top).size(right - left, bottom - top) -fun T.bounds(rect: Rectangle): T = bounds(rect.left, rect.top, rect.right, rect.bottom) +fun T.bounds(rect: MRectangle): T = bounds(rect.left, rect.top, rect.right, rect.bottom) fun T.positionX(x: Double): T { this.x = x @@ -2009,12 +2014,12 @@ fun T.positionY(y: Double): T { fun T.positionY(y: Float): T = positionY(y.toDouble()) fun T.positionY(y: Int): T = positionY(y.toDouble()) -fun View.getPositionRelativeTo(view: View, out: Point = Point()): Point { +fun View.getPositionRelativeTo(view: View, out: MPoint = MPoint()): MPoint { val mat = this.parent!!.getConcatMatrix(view, inclusive = false) return mat.transform(x, y, out) } -fun View.setPositionRelativeTo(view: View, pos: Point) { +fun View.setPositionRelativeTo(view: View, pos: MPoint) { val mat = this.parent!!.getConcatMatrix(view, inclusive = false) val matInv = mat.inverted() val out = matInv.transform(pos) @@ -2022,12 +2027,12 @@ fun View.setPositionRelativeTo(view: View, pos: Point) { this.y = out.y } -fun View.getPointRelativeTo(pos: Point, view: View, out: Point = Point()): Point { +fun View.getPointRelativeTo(pos: MPoint, view: View, out: MPoint = MPoint()): MPoint { val mat = this.getConcatMatrix(view, inclusive = false) return mat.transform(pos, out) } -fun View.getPointRelativeToInv(pos: Point, view: View, out: Point = Point()): Point { +fun View.getPointRelativeToInv(pos: MPoint, view: View, out: MPoint = MPoint()): MPoint { val mat = this.getConcatMatrix(view, inclusive = false) val matInv = mat.inverted() matInv.transform(pos, out) diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/view/ViewCollision.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/view/ViewCollision.kt index d09515f5a5..c55ef94153 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/view/ViewCollision.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/view/ViewCollision.kt @@ -3,8 +3,8 @@ package com.soywiz.korge.view import com.soywiz.kds.iterators.fastForEach import com.soywiz.korio.lang.Cancellable import com.soywiz.korio.lang.threadLocal -import com.soywiz.korma.geom.Matrix -import com.soywiz.korma.geom.Rectangle +import com.soywiz.korma.geom.MMatrix +import com.soywiz.korma.geom.MRectangle import com.soywiz.korma.geom.shape.Shape2d import com.soywiz.korma.geom.vector.VectorPath import com.soywiz.korma.geom.vector.rect @@ -16,15 +16,15 @@ import kotlin.collections.set @PublishedApi internal class ViewCollisionContext { - val tempMat = Matrix() - val tempRect1 = Rectangle() - val tempRect2 = Rectangle() + val tempMat = MMatrix() + val tempRect1 = MRectangle() + val tempRect2 = MRectangle() val tempVectorPath1 = listOf(VectorPath()) val tempVectorPath2 = listOf(VectorPath()) - val ident = Matrix() - val lmat = Matrix() - val rmat = Matrix() + val ident = MMatrix() + val lmat = MMatrix() + val rmat = MMatrix() fun getVectorPath(view: View, out: List): List { val hitShape = view.hitShape diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/view/ViewExt.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/view/ViewExt.kt index 29a1ebbdce..22995de29a 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/view/ViewExt.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/view/ViewExt.kt @@ -4,7 +4,7 @@ import com.soywiz.klock.Frequency import com.soywiz.klock.timesPerSecond import com.soywiz.korio.lang.Cancellable import com.soywiz.korma.geom.IPoint -import com.soywiz.korma.geom.Point +import com.soywiz.korma.geom.MPoint val Double.fps get() = this.timesPerSecond val Int.fps get() = this.timesPerSecond @@ -17,10 +17,10 @@ fun T.addUpdater(referenceFps: Frequency, first: Boolean = true, upda } -fun View.Companion.convertViewSpace(src: View, srcPoint: IPoint, dst: View, dstPoint: Point = Point()): IPoint { +fun View.Companion.convertViewSpace(src: View, srcPoint: IPoint, dst: View, dstPoint: MPoint = MPoint()): IPoint { src.localToGlobal(srcPoint, dstPoint) return dst.globalToLocal(dstPoint, dstPoint) } -fun View.convertToSpace(srcPoint: IPoint, dst: View, dstPoint: Point = Point()): IPoint = +fun View.convertToSpace(srcPoint: IPoint, dst: View, dstPoint: MPoint = MPoint()): IPoint = View.Companion.convertViewSpace(this, srcPoint, dst, dstPoint) diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/view/ViewRenderToBitmap.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/view/ViewRenderToBitmap.kt index b6aae35e9c..30bbc4e995 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/view/ViewRenderToBitmap.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/view/ViewRenderToBitmap.kt @@ -14,7 +14,7 @@ private val logger = Logger("RenderToBitmap") * Asynchronously renders this [View] (with the provided [views]) to a [Bitmap32] and returns it. * The rendering will happen before the next frame. */ -suspend fun View.renderToBitmap(views: Views? = this.stage?.views, region: Rectangle? = null, scale: Double = 1.0, outPoint: Point = Point(), includeBackground: Boolean = false): Bitmap32 { +suspend fun View.renderToBitmap(views: Views? = this.stage?.views, region: MRectangle? = null, scale: Double = 1.0, outPoint: MPoint = MPoint(), includeBackground: Boolean = false): Bitmap32 { if (views == null) { logger.warn { "View.renderToBitmap Views not specified" } return Bitmap32(1, 1, Colors.TRANSPARENT.premultiplied) @@ -37,9 +37,9 @@ suspend fun View.renderToBitmap(views: Views? = this.stage?.views, region: Recta @KorgeExperimental fun View.unsafeRenderToBitmapSync( ctx: RenderContext, - region: Rectangle? = null, + region: MRectangle? = null, scale: Double = 1.0, - outPoint: Point = Point(), + outPoint: MPoint = MPoint(), useTexture: Boolean = true, bgcolor: RGBA = Colors.TRANSPARENT ): Bitmap32 { diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/view/Views.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/view/Views.kt index 171f318343..005cdedf0a 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/view/Views.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/view/Views.kt @@ -17,9 +17,7 @@ import com.soywiz.korge.internal.* import com.soywiz.korge.render.* import com.soywiz.korge.scene.* import com.soywiz.korge.stat.* -import com.soywiz.korge.view.property.* import com.soywiz.korgw.* -import com.soywiz.korim.bitmap.* import com.soywiz.korim.color.* import com.soywiz.korim.font.* import com.soywiz.korim.format.* @@ -171,7 +169,7 @@ class Views constructor( @KorgeInternal val windowMouseY: Double get() = bp.globalToWindowCoordsY(input.mouse) @KorgeInternal - val windowMouseXY: Point get() = bp.globalToWindowCoords(input.mouse) + val windowMouseXY: MPoint get() = bp.globalToWindowCoords(input.mouse) /** Mouse coordinates relative to the native window. Can't be used directly. Use [globalMouseX] instead */ @KorgeInternal @@ -183,7 +181,7 @@ class Views constructor( val nativeMouseY: Double get() = windowMouseY @KorgeInternal @Deprecated("Use windowMouseXY instead") - val nativeMouseXY: Point get() = windowMouseXY + val nativeMouseXY: MPoint get() = windowMouseXY /** Mouse coordinates relative to the [Stage] singleton */ val globalMouseXY get() = stage.mouseXY @@ -619,11 +617,11 @@ fun View.updateSingleViewWithViewsAll( } interface BoundsProvider { - val windowToGlobalMatrix: Matrix - val windowToGlobalTransform: Matrix.Transform - val globalToWindowMatrix: Matrix - val globalToWindowTransform: Matrix.Transform - val actualVirtualBounds: Rectangle + val windowToGlobalMatrix: MMatrix + val windowToGlobalTransform: MMatrix.Transform + val globalToWindowMatrix: MMatrix + val globalToWindowTransform: MMatrix.Transform + val actualVirtualBounds: MRectangle @KorgeExperimental val actualVirtualLeft: Int get() = actualVirtualBounds.left.toIntRound() @KorgeExperimental val actualVirtualTop: Int get() = actualVirtualBounds.top.toIntRound() @@ -642,7 +640,7 @@ interface BoundsProvider { @KorgeExperimental val actualVirtualBottom: Double get() = actualVirtualBounds.bottom - fun globalToWindowBounds(bounds: Rectangle, out: Rectangle = Rectangle()): Rectangle = + fun globalToWindowBounds(bounds: MRectangle, out: MRectangle = MRectangle()): MRectangle = out.copyFrom(bounds).applyTransform(globalToWindowMatrix) val windowToGlobalScaleX: Double get() = windowToGlobalTransform.scaleX @@ -653,26 +651,26 @@ interface BoundsProvider { val globalToWindowScaleY: Double get() = globalToWindowTransform.scaleY val globalToWindowScaleAvg: Double get() = globalToWindowTransform.scaleAvg - fun windowToGlobalCoords(pos: IPoint, out: Point = Point()): Point = windowToGlobalMatrix.transform(pos, out) - fun windowToGlobalCoords(x: Double, y: Double, out: Point = Point()): Point = windowToGlobalMatrix.transform(x, y, out) + fun windowToGlobalCoords(pos: IPoint, out: MPoint = MPoint()): MPoint = windowToGlobalMatrix.transform(pos, out) + fun windowToGlobalCoords(x: Double, y: Double, out: MPoint = MPoint()): MPoint = windowToGlobalMatrix.transform(x, y, out) fun windowToGlobalCoordsX(x: Double, y: Double): Double = windowToGlobalMatrix.transformX(x, y) fun windowToGlobalCoordsY(x: Double, y: Double): Double = windowToGlobalMatrix.transformY(x, y) fun windowToGlobalCoordsX(pos: IPoint): Double = windowToGlobalCoordsX(pos.x, pos.y) fun windowToGlobalCoordsY(pos: IPoint): Double = windowToGlobalCoordsY(pos.x, pos.y) - fun globalToWindowCoords(pos: IPoint, out: Point = Point()): Point = globalToWindowMatrix.transform(pos, out) - fun globalToWindowCoords(x: Double, y: Double, out: Point = Point()): Point = globalToWindowMatrix.transform(x, y, out) + fun globalToWindowCoords(pos: IPoint, out: MPoint = MPoint()): MPoint = globalToWindowMatrix.transform(pos, out) + fun globalToWindowCoords(x: Double, y: Double, out: MPoint = MPoint()): MPoint = globalToWindowMatrix.transform(x, y, out) fun globalToWindowCoordsX(x: Double, y: Double): Double = globalToWindowMatrix.transformX(x, y) fun globalToWindowCoordsY(x: Double, y: Double): Double = globalToWindowMatrix.transformY(x, y) fun globalToWindowCoordsX(pos: IPoint): Double = globalToWindowCoordsX(pos.x, pos.y) fun globalToWindowCoordsY(pos: IPoint): Double = globalToWindowCoordsY(pos.x, pos.y) open class Base : BoundsProvider { - override val windowToGlobalMatrix: Matrix = Matrix() - override val windowToGlobalTransform: Matrix.Transform = Matrix.Transform() - override val globalToWindowMatrix: Matrix = Matrix() - override val globalToWindowTransform: Matrix.Transform = Matrix.Transform() - override val actualVirtualBounds: Rectangle = Rectangle(0, 0, DefaultViewport.WIDTH, DefaultViewport.HEIGHT) + override val windowToGlobalMatrix: MMatrix = MMatrix() + override val windowToGlobalTransform: MMatrix.Transform = MMatrix.Transform() + override val globalToWindowMatrix: MMatrix = MMatrix() + override val globalToWindowTransform: MMatrix.Transform = MMatrix.Transform() + override val actualVirtualBounds: MRectangle = MRectangle(0, 0, DefaultViewport.WIDTH, DefaultViewport.HEIGHT) } } diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/view/camera/Camera.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/view/camera/Camera.kt index bdacc84427..02b4bb60ae 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/view/camera/Camera.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/view/camera/Camera.kt @@ -15,8 +15,8 @@ import com.soywiz.korio.async.invoke import com.soywiz.korio.async.waitOne import com.soywiz.korma.geom.Anchor import com.soywiz.korma.geom.Angle -import com.soywiz.korma.geom.Point -import com.soywiz.korma.geom.Rectangle +import com.soywiz.korma.geom.MPoint +import com.soywiz.korma.geom.MRectangle import com.soywiz.korma.geom.ScaleMode import com.soywiz.korma.geom.degrees import com.soywiz.korma.geom.interpolate @@ -45,12 +45,12 @@ class CameraContainer( block: @ViewDslMarker CameraContainer.() -> Unit = {} ) : FixedSizeContainer(width, height, clip), View.Reference { var clampToBounds: Boolean = false - val cameraViewportBounds: Rectangle = Rectangle(0, 0, 4096, 4096) + val cameraViewportBounds: MRectangle = MRectangle(0, 0, 4096, 4096) private val contentContainer = Container() class ContentContainer(val cameraContainer: CameraContainer) : FixedSizeContainer(cameraContainer.width, cameraContainer.height), Reference { - override fun getLocalBoundsInternal(out: Rectangle) { + override fun getLocalBoundsInternal(out: MRectangle) { //out.setTo(0, 0, cameraContainer.width, cameraContainer.height) out.setTo(0, 0, width, height) } @@ -121,8 +121,8 @@ class CameraContainer( fun getDefaultCamera(out: Camera = Camera()): Camera = out.setTo(x = width / 2.0, y = height / 2.0, anchorX = 0.5, anchorY = 0.5) companion object { - fun getCameraRect(rect: Rectangle, scaleMode: ScaleMode = ScaleMode.SHOW_ALL, cameraWidth: Double, cameraHeight: Double, cameraAnchorX: Double, cameraAnchorY: Double, out: Camera = Camera()): Camera { - val size = Rectangle(0.0, 0.0, cameraWidth, cameraHeight).place(rect.size, Anchor.TOP_LEFT, scale = scaleMode).size + fun getCameraRect(rect: MRectangle, scaleMode: ScaleMode = ScaleMode.SHOW_ALL, cameraWidth: Double, cameraHeight: Double, cameraAnchorX: Double, cameraAnchorY: Double, out: Camera = Camera()): Camera { + val size = MRectangle(0.0, 0.0, cameraWidth, cameraHeight).place(rect.size, Anchor.TOP_LEFT, scale = scaleMode).size val scaleX = size.width / rect.width val scaleY = size.height / rect.height return out.setTo( @@ -136,9 +136,9 @@ class CameraContainer( } } - fun getCameraRect(rect: Rectangle, scaleMode: ScaleMode = ScaleMode.SHOW_ALL, out: Camera = Camera()): Camera = getCameraRect(rect, scaleMode, width, height, cameraAnchorX, cameraAnchorY, out) - fun getCameraToFit(rect: Rectangle, out: Camera = Camera()): Camera = getCameraRect(rect, ScaleMode.SHOW_ALL, out) - fun getCameraToCover(rect: Rectangle, out: Camera = Camera()): Camera = getCameraRect(rect, ScaleMode.COVER, out) + fun getCameraRect(rect: MRectangle, scaleMode: ScaleMode = ScaleMode.SHOW_ALL, out: Camera = Camera()): Camera = getCameraRect(rect, scaleMode, width, height, cameraAnchorX, cameraAnchorY, out) + fun getCameraToFit(rect: MRectangle, out: Camera = Camera()): Camera = getCameraRect(rect, ScaleMode.SHOW_ALL, out) + fun getCameraToCover(rect: MRectangle, out: Camera = Camera()): Camera = getCameraRect(rect, ScaleMode.COVER, out) private var transitionTime = 1.0.seconds private var elapsedTime = 0.0.milliseconds @@ -189,7 +189,7 @@ class CameraContainer( onCompletedTransition.waitOne() } - fun getFollowingXY(out: Point = Point()): Point { + fun getFollowingXY(out: MPoint = MPoint()): MPoint { val followGlobalX = following!!.globalX val followGlobalY = following!!.globalY val localToContentX = content!!.globalToLocalX(followGlobalX, followGlobalY) @@ -197,7 +197,7 @@ class CameraContainer( return out.setTo(localToContentX, localToContentY) } - private val tempPoint = Point() + private val tempPoint = MPoint() init { block(this) contentContainer.addTo(this) @@ -259,7 +259,7 @@ class CameraContainer( contentContainer.scaleY = realScaleY } - fun setZoomAt(anchor: Point, zoom: Double) { + fun setZoomAt(anchor: MPoint, zoom: Double) { setAnchorPosKeepingPos(anchor.x, anchor.y) cameraZoom = zoom } @@ -269,7 +269,7 @@ class CameraContainer( cameraZoom = zoom } - fun setAnchorPosKeepingPos(anchor: Point) { + fun setAnchorPosKeepingPos(anchor: MPoint) { setAnchorPosKeepingPos(anchor.x, anchor.y) } diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/view/camera/CameraOld.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/view/camera/CameraOld.kt index a4ae192ba5..1c183c56fa 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/view/camera/CameraOld.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/view/camera/CameraOld.kt @@ -15,7 +15,7 @@ import com.soywiz.korge.view.hasAncestor import com.soywiz.korio.lang.Cancellable import com.soywiz.korio.lang.cancel import com.soywiz.korma.geom.Angle -import com.soywiz.korma.geom.Rectangle +import com.soywiz.korma.geom.MRectangle import com.soywiz.korma.geom.degrees import com.soywiz.korma.geom.interpolate import com.soywiz.korma.geom.plus @@ -47,7 +47,7 @@ class CameraContainerOld( private val contentContainer = Container() val content: Container = object : Container(), Reference { - override fun getLocalBoundsInternal(out: Rectangle) { + override fun getLocalBoundsInternal(out: MRectangle) { out.setTo(0, 0, this@CameraContainerOld.width, this@CameraContainerOld.height) } } diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/view/debug/DebugVertexView.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/view/debug/DebugVertexView.kt index 50a632459c..892a2d2677 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/view/debug/DebugVertexView.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/view/debug/DebugVertexView.kt @@ -14,7 +14,7 @@ import com.soywiz.korim.color.Colors import com.soywiz.korim.color.RGBA import com.soywiz.korma.geom.BoundsBuilder import com.soywiz.korma.geom.IVectorArrayList -import com.soywiz.korma.geom.Rectangle +import com.soywiz.korma.geom.MRectangle import com.soywiz.korma.geom.VectorArrayList import com.soywiz.korma.geom.fastForEachGeneric import com.soywiz.korma.geom.toMatrix3D @@ -98,7 +98,7 @@ class DebugVertexView(pointsList: List, color: RGBA = Colors.W private val uniforms: AGUniformValues = AGUniformValues() - override fun getLocalBoundsInternal(out: Rectangle) { + override fun getLocalBoundsInternal(out: MRectangle) { bb.getBounds(out) //println("DebugVertexView.getLocalBoundsInternal:$out") } diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/view/fast/FSprites.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/view/fast/FSprites.kt index ae62e6036b..fb7e6c2fb6 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/view/fast/FSprites.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/view/fast/FSprites.kt @@ -18,7 +18,7 @@ import com.soywiz.korim.bitmap.* import com.soywiz.korim.color.Colors import com.soywiz.korim.color.RGBA import com.soywiz.korma.geom.Angle -import com.soywiz.korma.geom.Matrix +import com.soywiz.korma.geom.MMatrix import com.soywiz.korma.geom.radians @PublishedApi @@ -137,7 +137,7 @@ open class FSprites(val maxSize: Int) { sprites: FSprites, info: FViewInfo, smoothing: Boolean, - globalMatrix: Matrix, + globalMatrix: MMatrix, blending: BlendMode ) { if (!ctx.isInstancedSupported) { diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/view/filter/ColorMatrixFilter.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/view/filter/ColorMatrixFilter.kt index c6327128e2..ad8204b41a 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/view/filter/ColorMatrixFilter.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/view/filter/ColorMatrixFilter.kt @@ -15,20 +15,20 @@ import com.soywiz.korma.geom.* * - [ColorMatrixFilter.GRAYSCALE_MATRIX] - Used to make the colors grey * - [ColorMatrixFilter.IDENTITY_MATRIX] - Doesn't modify the colors at all */ -class ColorMatrixFilter(colorMatrix: Matrix3D, blendRatio: Double = 1.0) : ShaderFilter() { +class ColorMatrixFilter(colorMatrix: MMatrix3D, blendRatio: Double = 1.0) : ShaderFilter() { companion object : BaseProgramProvider() { private val u_ColorMatrix = Uniform("colorMatrix", VarType.Mat4) private val u_BlendRatio = Uniform("blendRatio", VarType.Float1) /** A Matrix usable for [colorMatrix] that will transform any color into grayscale */ - val GRAYSCALE_MATRIX = Matrix3D.fromColumns( + val GRAYSCALE_MATRIX = MMatrix3D.fromColumns( 0.33f, 0.33f, 0.33f, 0f, 0.59f, 0.59f, 0.59f, 0f, 0.11f, 0.11f, 0.11f, 0f, 0f, 0f, 0f, 1f ) - val SEPIA_MATRIX = Matrix3D.fromColumns( + val SEPIA_MATRIX = MMatrix3D.fromColumns( 0.393f, 0.349f, 0.272f, 0f, 0.769f, 0.686f, 0.534f, 0f, 0.189f, 0.168f, 0.131f, 0f, @@ -36,7 +36,7 @@ class ColorMatrixFilter(colorMatrix: Matrix3D, blendRatio: Double = 1.0) : Shade ) /** A Matrix usable for [colorMatrix] that will preserve the original color */ - val IDENTITY_MATRIX = Matrix3D.fromColumns( + val IDENTITY_MATRIX = MMatrix3D.fromColumns( 1f, 0f, 0f, 0f, 0f, 1f, 0f, 0f, 0f, 0f, 1f, 0f, @@ -55,9 +55,9 @@ class ColorMatrixFilter(colorMatrix: Matrix3D, blendRatio: Double = 1.0) : Shade } } - /** The 4x4 [Matrix3D] that will be used for transforming each pixel components [r, g, b, a] */ + /** The 4x4 [MMatrix3D] that will be used for transforming each pixel components [r, g, b, a] */ @ViewProperty - var colorMatrix: Matrix3D by uniforms.storageForMatrix3D(u_ColorMatrix, colorMatrix) + var colorMatrix: MMatrix3D by uniforms.storageForMatrix3D(u_ColorMatrix, colorMatrix) /** * Ratio for blending the original color with the transformed color. diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/view/filter/ComposedFilter.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/view/filter/ComposedFilter.kt index 09513987de..cafeb7538b 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/view/filter/ComposedFilter.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/view/filter/ComposedFilter.kt @@ -50,7 +50,7 @@ open class ComposedFilter private constructor( return out } - override fun computeBorder(out: MutableMarginInt, texWidth: Int, texHeight: Int) { + override fun computeBorder(out: MMarginInt, texWidth: Int, texHeight: Int) { var sumLeft = 0 var sumTop = 0 var sumRight = 0 @@ -70,7 +70,7 @@ open class ComposedFilter private constructor( final override fun render( ctx: RenderContext, - matrix: Matrix, + matrix: MMatrix, texture: Texture, texWidth: Int, texHeight: Int, diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/view/filter/Convolute3Filter.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/view/filter/Convolute3Filter.kt index 74dfc1a5f0..b7e5c4a950 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/view/filter/Convolute3Filter.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/view/filter/Convolute3Filter.kt @@ -13,7 +13,7 @@ import com.soywiz.korma.geom.* */ class Convolute3Filter( /** 3x3 matrix representing a convolution kernel */ - var kernel: Matrix3D, + var kernel: MMatrix3D, /** Distance between the origin pixel for sampling for edges */ dist: Double = 1.0, applyAlpha: Boolean = false @@ -23,36 +23,36 @@ class Convolute3Filter( private val u_Dist = Uniform("dist", VarType.Float1) private val u_Weights = Uniform("weights", VarType.Mat3) - /** A Gaussian Blur Kernel. This [Matrix3D] can be used as [kernel] for [Convolute3Filter] */ - val KERNEL_GAUSSIAN_BLUR: Matrix3D = Matrix3D.fromRows3x3( + /** A Gaussian Blur Kernel. This [MMatrix3D] can be used as [kernel] for [Convolute3Filter] */ + val KERNEL_GAUSSIAN_BLUR: MMatrix3D = MMatrix3D.fromRows3x3( 1f, 2f, 1f, 2f, 4f, 2f, 1f, 2f, 1f ) * (1f / 16f) - /** A Box Blur Kernel. This [Matrix3D] can be used as [kernel] for [Convolute3Filter] */ - val KERNEL_BOX_BLUR: Matrix3D = Matrix3D.fromRows3x3( + /** A Box Blur Kernel. This [MMatrix3D] can be used as [kernel] for [Convolute3Filter] */ + val KERNEL_BOX_BLUR: MMatrix3D = MMatrix3D.fromRows3x3( 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f ) * (1f / 9f) - /** An Identity Kernel (doesn't perform any operation). This [Matrix3D] can be used as [kernel] for [Convolute3Filter] */ - val KERNEL_IDENTITY: Matrix3D = Matrix3D.fromRows3x3( + /** An Identity Kernel (doesn't perform any operation). This [MMatrix3D] can be used as [kernel] for [Convolute3Filter] */ + val KERNEL_IDENTITY: MMatrix3D = MMatrix3D.fromRows3x3( 0f, 0f, 0f, 0f, 1f, 0f, 0f, 0f, 0f ) - /** An Edge Detection Kernel. This [Matrix3D] can be used as [kernel] for [Convolute3Filter] */ - val KERNEL_EDGE_DETECTION: Matrix3D = Matrix3D.fromRows3x3( + /** An Edge Detection Kernel. This [MMatrix3D] can be used as [kernel] for [Convolute3Filter] */ + val KERNEL_EDGE_DETECTION: MMatrix3D = MMatrix3D.fromRows3x3( -1f, -1f, -1f, -1f, +8f, -1f, -1f, -1f, -1f ) - /** A Sharpen Kernel. This [Matrix3D] can be used as [kernel] for [Convolute3Filter] */ - val KERNEL_SHARPEN: Matrix3D = Matrix3D.fromRows3x3( + /** A Sharpen Kernel. This [MMatrix3D] can be used as [kernel] for [Convolute3Filter] */ + val KERNEL_SHARPEN: MMatrix3D = MMatrix3D.fromRows3x3( -1f, -1f, -1f, -1f, +9f, -1f, -1f, -1f, -1f @@ -93,7 +93,7 @@ class Convolute3Filter( /** 3x3 matrix representing a convolution kernel */ @ViewProperty - var weights: Matrix3D by uniforms.storageForMatrix3D(u_Weights, kernel) + var weights: MMatrix3D by uniforms.storageForMatrix3D(u_Weights, kernel) /** Distance between the origin pixel for sampling for edges */ @ViewProperty var dist: Double by uniforms.storageFor(u_Dist).doubleDelegateX(dist) @@ -103,7 +103,7 @@ class Convolute3Filter( override val programProvider: ProgramProvider get() = Convolute3Filter - override fun computeBorder(out: MutableMarginInt, texWidth: Int, texHeight: Int) { + override fun computeBorder(out: MMarginInt, texWidth: Int, texHeight: Int) { out.setTo(dist.toIntCeil()) } diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/view/filter/DirectionalBlurFilter.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/view/filter/DirectionalBlurFilter.kt index de665adc97..a418bf59f2 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/view/filter/DirectionalBlurFilter.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/view/filter/DirectionalBlurFilter.kt @@ -63,7 +63,7 @@ class DirectionalBlurFilter( // @TODO: Here we cannot do this, but we should be able to do this trick: https://www.rastergrid.com/blog/2010/09/efficient-gaussian-blur-with-linear-sampling/ //override val recommendedFilterScale: Double get() = if (rradius <= 2.0) 1.0 else 1.0 / log2(rradius.coerceAtLeast(1.0)) - override fun computeBorder(out: MutableMarginInt, texWidth: Int, texHeight: Int) { + override fun computeBorder(out: MMarginInt, texWidth: Int, texHeight: Int) { if (!expandBorder) return out.setTo(0) val radius = this.rradius out.setTo( diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/view/filter/DropShadowFilter.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/view/filter/DropShadowFilter.kt index 094cd9b413..f86c78cac4 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/view/filter/DropShadowFilter.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/view/filter/DropShadowFilter.kt @@ -21,7 +21,7 @@ open class DropshadowFilter( ) : Filter { private val blur = BlurFilter(16.0) - override fun computeBorder(out: MutableMarginInt, texWidth: Int, texHeight: Int) { + override fun computeBorder(out: MMarginInt, texWidth: Int, texHeight: Int) { blur.computeBorder(out, texWidth, texHeight) if (dropX >= 0.0) out.right += dropX.toIntCeil() else out.left -= dropX.toIntCeil() if (dropY >= 0.0) out.bottom += dropY.toIntCeil() else out.top -= dropY.toIntCeil() @@ -29,7 +29,7 @@ open class DropshadowFilter( override fun render( ctx: RenderContext, - matrix: Matrix, + matrix: MMatrix, texture: Texture, texWidth: Int, texHeight: Int, diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/view/filter/Filter.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/view/filter/Filter.kt index 285767718d..b5fb335d14 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/view/filter/Filter.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/view/filter/Filter.kt @@ -55,7 +55,7 @@ interface Filter { val recommendedFilterScale: Double get() = 1.0 - fun computeBorder(out: MutableMarginInt, texWidth: Int, texHeight: Int) { + fun computeBorder(out: MMarginInt, texWidth: Int, texHeight: Int) { out.setTo(border) } @@ -65,7 +65,7 @@ interface Filter { */ fun render( ctx: RenderContext, - matrix: Matrix, + matrix: MMatrix, texture: Texture, texWidth: Int, texHeight: Int, @@ -76,7 +76,7 @@ interface Filter { ) } -fun Filter.getBorder(texWidth: Int, texHeight: Int, out: MutableMarginInt = MutableMarginInt()): MarginInt { +fun Filter.getBorder(texWidth: Int, texHeight: Int, out: MMarginInt = MMarginInt()): IMarginInt { computeBorder(out, texWidth, texHeight) return out } @@ -84,12 +84,12 @@ fun Filter.getBorder(texWidth: Int, texHeight: Int, out: MutableMarginInt = Muta @Deprecated("") fun Filter.renderToTextureWithBorder( ctx: RenderContext, - matrix: Matrix, + matrix: MMatrix, texture: Texture, texWidth: Int, texHeight: Int, filterScale: Double, - block: (texture: Texture, matrix: Matrix) -> Unit, + block: (texture: Texture, matrix: MMatrix) -> Unit, ) { val filter = this val margin = filter.getBorder(texWidth, texHeight, ctx.tempMargin) @@ -126,12 +126,12 @@ class RenderToTextureResult() : Disposable { var borderLeft: Int = 0 var borderTop: Int = 0 var filterScale: Double = 1.0 - val matrix = Matrix() + val matrix = MMatrix() var texture: Texture? = null var fb: AGFrameBuffer? = null var newtex: Texture? = null var ctx: RenderContext? = null - private val tempMat = Matrix() + private val tempMat = MMatrix() fun render() { val fb = fb ?: return @@ -162,7 +162,7 @@ class RenderToTextureResult() : Disposable { @KoragExperimental fun Filter.renderToTextureWithBorderUnsafe( ctx: RenderContext, - matrix: Matrix, + matrix: MMatrix, texture: Texture, texWidth: Int, texHeight: Int, @@ -195,8 +195,8 @@ fun Filter.renderToTextureWithBorderUnsafe( return result } -fun Filter.expandBorderRectangle(out: Rectangle) { - MutableMarginInt.POOL { temp -> out.expand(getBorder(out.width.toIntCeil(), out.height.toIntCeil(), temp)) } +fun Filter.expandBorderRectangle(out: MRectangle) { + MMarginInt.POOL { temp -> out.expand(getBorder(out.width.toIntCeil(), out.height.toIntCeil(), temp)) } } @ThreadLocal diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/view/filter/FlagFilter.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/view/filter/FlagFilter.kt index bb03fd0dd0..115ad9c8aa 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/view/filter/FlagFilter.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/view/filter/FlagFilter.kt @@ -64,7 +64,7 @@ class FlagFilter( override val programProvider: ProgramProvider get() = FlagFilter - override fun computeBorder(out: MutableMarginInt, texWidth: Int, texHeight: Int) { + override fun computeBorder(out: MMarginInt, texWidth: Int, texHeight: Int) { out.setTo(amplitude.absoluteValue.toIntCeil()) } } diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/view/filter/IdentityFilter.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/view/filter/IdentityFilter.kt index 7fc3a2afb1..0e3ce99555 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/view/filter/IdentityFilter.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/view/filter/IdentityFilter.kt @@ -4,7 +4,7 @@ import com.soywiz.korge.render.* import com.soywiz.korge.view.BlendMode import com.soywiz.korim.color.ColorAdd import com.soywiz.korim.color.RGBA -import com.soywiz.korma.geom.Matrix +import com.soywiz.korma.geom.MMatrix /** * Simple [Filter] that draws the texture pixels without any kind of transformation @@ -16,7 +16,7 @@ open class IdentityFilter(val smoothing: Boolean) : Filter { override fun render( ctx: RenderContext, - matrix: Matrix, + matrix: MMatrix, texture: Texture, texWidth: Int, texHeight: Int, diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/view/filter/OldBlurFilter.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/view/filter/OldBlurFilter.kt index 9e35cdf9c7..02e3935bcc 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/view/filter/OldBlurFilter.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/view/filter/OldBlurFilter.kt @@ -21,13 +21,13 @@ class OldBlurFilter(radius: Double = 4.0) : Filter { var radius: Double = radius set(value) { field = value.clamp(0.0, 32.0) } //override val border: Int get() = composed.border - override fun computeBorder(out: MutableMarginInt, texWidth: Int, texHeight: Int) = composed.computeBorder(out, texWidth, texHeight) + override fun computeBorder(out: MMarginInt, texWidth: Int, texHeight: Int) = composed.computeBorder(out, texWidth, texHeight) override val recommendedFilterScale: Double get() = if (radius <= 2.0) 1.0 else 1.0 / log2(radius * 0.5) override fun render( ctx: RenderContext, - matrix: Matrix, + matrix: MMatrix, texture: Texture, texWidth: Int, texHeight: Int, @@ -40,7 +40,7 @@ class OldBlurFilter(radius: Double = 4.0) : Filter { val nsteps = (radius).toIntCeil() // Cache values while (gaussianBlurs.size < nsteps) { - gaussianBlurs.add(Convolute3Filter(Matrix3D(Convolute3Filter.KERNEL_GAUSSIAN_BLUR), gaussianBlurs.size.toDouble(), applyAlpha = true)) + gaussianBlurs.add(Convolute3Filter(MMatrix3D(Convolute3Filter.KERNEL_GAUSSIAN_BLUR), gaussianBlurs.size.toDouble(), applyAlpha = true)) } //println("border: $border") diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/view/filter/PageFilter.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/view/filter/PageFilter.kt index 3b554527e1..dec4ce289e 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/view/filter/PageFilter.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/view/filter/PageFilter.kt @@ -72,7 +72,7 @@ class PageFilter( override val programProvider: ProgramProvider get() = PageFilter - override fun computeBorder(out: MutableMarginInt, texWidth: Int, texHeight: Int) { + override fun computeBorder(out: MMarginInt, texWidth: Int, texHeight: Int) { out.setTo(max(max(abs(hamplitude0), abs(hamplitude1)), abs(hamplitude2)).toIntCeil()) } } diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/view/filter/ShaderFilter.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/view/filter/ShaderFilter.kt index 5d3849b02b..0f024cc7ed 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/view/filter/ShaderFilter.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/view/filter/ShaderFilter.kt @@ -86,7 +86,7 @@ abstract class ShaderFilter : Filter { it[u_StdTexDerivates] = textureStdTexDerivates } - override fun computeBorder(out: MutableMarginInt, texWidth: Int, texHeight: Int) { + override fun computeBorder(out: MMarginInt, texWidth: Int, texHeight: Int) { out.setTo(0) } @@ -127,7 +127,7 @@ abstract class ShaderFilter : Filter { override fun render( ctx: RenderContext, - matrix: Matrix, + matrix: MMatrix, texture: Texture, texWidth: Int, texHeight: Int, diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/view/filter/WaveFilter.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/view/filter/WaveFilter.kt index 2f9fe0346f..6d1e280eae 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/view/filter/WaveFilter.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/view/filter/WaveFilter.kt @@ -78,7 +78,7 @@ class WaveFilter( override val programProvider: ProgramProvider get() = WaveFilter - override fun computeBorder(out: MutableMarginInt, texWidth: Int, texHeight: Int) { + override fun computeBorder(out: MMarginInt, texWidth: Int, texHeight: Int) { out.setTo(amplitudeY.absoluteValue, amplitudeX.absoluteValue) } } diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/view/grid/Grid.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/view/grid/Grid.kt index c21db5b47b..5fadbfb17c 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/view/grid/Grid.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/view/grid/Grid.kt @@ -4,14 +4,14 @@ import com.soywiz.kmem.nearestAlignedTo import com.soywiz.korge.render.RenderContext import com.soywiz.korge.render.useLineBatcher import com.soywiz.korim.color.Colors -import com.soywiz.korma.geom.Matrix -import com.soywiz.korma.geom.Point +import com.soywiz.korma.geom.MMatrix +import com.soywiz.korma.geom.MPoint import com.soywiz.korma.geom.RectangleInt import com.soywiz.korma.geom.vector.rect interface Grid { - fun snap(point: Point, out: Point = Point()): Point - fun draw(ctx: RenderContext, width: Double, height: Double, m: Matrix) + fun snap(point: MPoint, out: MPoint = MPoint()): MPoint + fun draw(ctx: RenderContext, width: Double, height: Double, m: MMatrix) } open class OrthographicGrid( @@ -25,14 +25,14 @@ open class OrthographicGrid( height = value } - override fun snap(point: Point, out: Point): Point { + override fun snap(point: MPoint, out: MPoint): MPoint { return out.setTo( point.x.nearestAlignedTo(width.toDouble()), point.y.nearestAlignedTo(height.toDouble()), ) } - override fun draw(ctx: RenderContext, width: Double, height: Double, m: Matrix) { + override fun draw(ctx: RenderContext, width: Double, height: Double, m: MMatrix) { val gridWidth = this.width val gridHeight = this.height val width = width.toInt() diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/view/internal/InternalViewAutoscaling.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/view/internal/InternalViewAutoscaling.kt index 5e3780006f..a57f8882b5 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/view/internal/InternalViewAutoscaling.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/view/internal/InternalViewAutoscaling.kt @@ -1,6 +1,6 @@ package com.soywiz.korge.view.internal -import com.soywiz.korma.geom.Matrix +import com.soywiz.korma.geom.MMatrix import kotlin.math.abs import kotlin.math.max @@ -10,9 +10,9 @@ internal class InternalViewAutoscaling { var renderedAtScaleX = 1.0; private set var renderedAtScaleY = 1.0; private set var renderedAtScaleXY = 1.0; private set - private val matrixTransform = Matrix.Transform() + private val matrixTransform = MMatrix.Transform() - fun onRender(autoScaling: Boolean, autoScalingPrecise: Boolean, globalMatrix: Matrix): Boolean { + fun onRender(autoScaling: Boolean, autoScalingPrecise: Boolean, globalMatrix: MMatrix): Boolean { if (autoScaling) { matrixTransform.setMatrixNoReturn(globalMatrix) //val sx = kotlin.math.abs(matrixTransform.scaleX / this.scaleX) diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/view/tiles/TileMap.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/view/tiles/TileMap.kt index 08aa61cee6..6779fe569a 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/view/tiles/TileMap.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/view/tiles/TileMap.kt @@ -19,7 +19,7 @@ inline fun Container.tileMap( repeatX: TileMapRepeat = TileMapRepeat.NONE, repeatY: TileMapRepeat = repeatX, smoothing: Boolean = true, - tileSize: Size = Size(tileset.width.toDouble(), tileset.height.toDouble()), + tileSize: MSize = MSize(tileset.width.toDouble(), tileset.height.toDouble()), callback: @ViewDslMarker TileMap.() -> Unit = {}, ) = TileMap(map, tileset, smoothing, tileSize).repeat(repeatX, repeatY).addTo(this, callback) @@ -29,7 +29,7 @@ inline fun Container.tileMap( repeatX: TileMapRepeat = TileMapRepeat.NONE, repeatY: TileMapRepeat = repeatX, smoothing: Boolean = true, - tileSize: Size = Size(tileset.width.toDouble(), tileset.height.toDouble()), + tileSize: MSize = MSize(tileset.width.toDouble(), tileset.height.toDouble()), callback: @ViewDslMarker TileMap.() -> Unit = {}, ) = TileMap(map, tileset, smoothing, tileSize).repeat(repeatX, repeatY).addTo(this, callback) @@ -71,7 +71,7 @@ class TileMap( var stackedIntMap: IStackedIntArray2 = StackedIntArray2(1, 1, 0), tileset: TileSet = TileSet.EMPTY, var smoothing: Boolean = true, - var tileSize: Size = Size(tileset.width.toDouble(), tileset.height.toDouble()), + var tileSize: MSize = MSize(tileset.width.toDouble(), tileset.height.toDouble()), //) : BaseTileMap(intMap, smoothing, staggerAxis, staggerIndex, tileSize) { ) : View() { @Deprecated("Use stackedIntMap instead", level = DeprecationLevel.HIDDEN) @@ -104,11 +104,11 @@ class TileMap( var repeatX = TileMapRepeat.NONE var repeatY = TileMapRepeat.NONE - private val t0 = Point(0, 0) - private val tt0 = Point(0, 0) - private val tt1 = Point(0, 0) - private val tt2 = Point(0, 0) - private val tt3 = Point(0, 0) + private val t0 = MPoint(0, 0) + private val tt0 = MPoint(0, 0) + private val tt1 = MPoint(0, 0) + private val tt2 = MPoint(0, 0) + private val tt3 = MPoint(0, 0) protected var contentVersion = 0 private var cachedContentVersion = 0 @@ -170,8 +170,8 @@ class TileMap( } private val infosPool = Pool(reset = { it.reset() }) { Info(Bitmaps.transparent.bmpBase, ShrinkableTexturedVertexArray(TexturedVertexArray.EMPTY)) } - private var lastVirtualRect = Rectangle(-1, -1, -1, -1) - private var currentVirtualRect = Rectangle(-1, -1, -1, -1) + private var lastVirtualRect = MRectangle(-1, -1, -1, -1) + private var currentVirtualRect = MRectangle(-1, -1, -1, -1) private val indices = IntArray(4) private val tempX = FloatArray(4) @@ -434,7 +434,7 @@ class TileMap( tilesetTextures = Array(tileset.textures.size) { tileset.textures[it] } animationIndex = IntArray(tileset.textures.size) { 0 } animationElapsed = DoubleArray(tileset.textures.size) { 0.0 } - tileSize = Size(tileset.width.toDouble(), tileset.height.toDouble()) + tileSize = MSize(tileset.width.toDouble(), tileset.height.toDouble()) tileWidth = tileset.width.toDouble() tileHeight = tileset.height.toDouble() } @@ -443,14 +443,14 @@ class TileMap( map: IntArray2, tileset: TileSet, smoothing: Boolean = true, - tileSize: Size = Size(tileset.width.toDouble(), tileset.height.toDouble()), + tileSize: MSize = MSize(tileset.width.toDouble(), tileset.height.toDouble()), ) : this(map.toStacked(), tileset, smoothing, tileSize) constructor( map: Bitmap32, tileset: TileSet, smoothing: Boolean = true, - tileSize: Size = Size(tileset.width.toDouble(), tileset.height.toDouble()), + tileSize: MSize = MSize(tileset.width.toDouble(), tileset.height.toDouble()), ) : this(map.toIntArray2().toStacked(), tileset, smoothing, tileSize) fun pixelHitTest(x: Int, y: Int, direction: HitTestDirection): Boolean { @@ -491,7 +491,7 @@ class TileMap( } } - override fun getLocalBoundsInternal(out: Rectangle) { + override fun getLocalBoundsInternal(out: MRectangle) { out.setTo(0, 0, tileWidth * stackedIntMap.width, tileHeight * stackedIntMap.height) } diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/view/vector/GpuShapeView.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/view/vector/GpuShapeView.kt index eb803e1a84..0c48f21e7b 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/view/vector/GpuShapeView.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/view/vector/GpuShapeView.kt @@ -13,12 +13,12 @@ import com.soywiz.korim.vector.* import com.soywiz.korma.geom.Angle import com.soywiz.korma.geom.BoundsBuilder import com.soywiz.korma.geom.IPoint -import com.soywiz.korma.geom.Line -import com.soywiz.korma.geom.Matrix -import com.soywiz.korma.geom.Point +import com.soywiz.korma.geom.MLine +import com.soywiz.korma.geom.MMatrix +import com.soywiz.korma.geom.MPoint import com.soywiz.korma.geom.PointArrayList import com.soywiz.korma.geom.PointPool -import com.soywiz.korma.geom.Rectangle +import com.soywiz.korma.geom.MRectangle import com.soywiz.korma.geom.bezier.* import com.soywiz.korma.geom.degrees import com.soywiz.korma.geom.expand @@ -122,9 +122,9 @@ open class GpuShapeView( private var validShapeBounds = false private var validShapeBoundsStrokes = false private var renderCount = 0 - private val _shapeBounds: Rectangle = Rectangle() - private val _shapeBoundsStrokes: Rectangle = Rectangle() - private val shapeBounds: Rectangle + private val _shapeBounds: MRectangle = MRectangle() + private val _shapeBoundsStrokes: MRectangle = MRectangle() + private val shapeBounds: MRectangle get() { val _bounds = if (boundsIncludeStrokes) _shapeBoundsStrokes else _shapeBounds val valid = if (boundsIncludeStrokes) validShapeBoundsStrokes else validShapeBounds @@ -168,7 +168,7 @@ open class GpuShapeView( invalidateShape() } - override fun getLocalBoundsInternal(out: Rectangle) { + override fun getLocalBoundsInternal(out: MRectangle) { out.setTo( shapeBounds.x - anchorDispX, shapeBounds.y - anchorDispY, @@ -194,7 +194,7 @@ open class GpuShapeView( } } - private val globalTransform = Matrix.Transform() + private val globalTransform = MMatrix.Transform() private var globalScale: Double = 1.0 private var cachedScale: Double = Double.NaN @@ -239,7 +239,7 @@ open class GpuShapeView( //println("GPU RENDER IN: $time, doRequireTexture=$doRequireTexture") } - private val renderMat = Matrix() + private val renderMat = MMatrix() private fun renderCommands(ctx: RenderContext, doRequireTexture: Boolean) { val mat = if (doRequireTexture) globalMatrix * ctx.bp.globalToWindowMatrix else globalMatrix renderMat.copyFrom(mat) @@ -277,7 +277,7 @@ open class GpuShapeView( class SegmentInfo { lateinit var s: IPoint // start lateinit var e: IPoint // end - lateinit var line: Line + lateinit var line: MLine var angleSE: Angle = 0.degrees var angleSE0: Angle = 0.degrees var angleSE1: Angle = 0.degrees @@ -294,11 +294,11 @@ open class GpuShapeView( fun p0(index: Int) = if (index == 0) s0 else e0 fun p1(index: Int) = if (index == 0) s1 else e1 - fun setTo(s: Point, e: Point, lineWidth: Double, scope: PointPool) { + fun setTo(s: MPoint, e: MPoint, lineWidth: Double, scope: PointPool) { this.s = s this.e = e scope.apply { - line = Line(s, e) + line = MLine(s, e) angleSE = Angle.between(s, e) angleSE0 = angleSE - 90.degrees angleSE1 = angleSE + 90.degrees @@ -359,7 +359,7 @@ open class GpuShapeView( //private val strokeCache = HashMap() private fun renderStroke( - stateTransform: Matrix, + stateTransform: MMatrix, strokePath: VectorPath, paint: Paint, globalAlpha: Double, @@ -436,7 +436,7 @@ open class GpuShapeView( for (n in 0 until points.size + 1) { val x = points.getX(n % points.size) val y = points.getY(n % points.size) - val len = if (isStripAndAntialiased) Point.distance(x, y, xMid, yMid).toFloat() else 0f + val len = if (isStripAndAntialiased) MPoint.distance(x, y, xMid, yMid).toFloat() else 0f val maxLen = if (isStripAndAntialiased) len else BIG_MAX_LEN if (isStrip) { gpuShapeViewCommands.addVertex(xMid.toFloat(), yMid.toFloat(), len = 0f, maxLen = maxLen) diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/view/vector/GpuShapeViewCommands.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/view/vector/GpuShapeViewCommands.kt index b24172e971..89291ff0a2 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/view/vector/GpuShapeViewCommands.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/view/vector/GpuShapeViewCommands.kt @@ -91,12 +91,12 @@ class GpuShapeViewCommands { vertices = AgCachedBuffer(Float32Buffer(bufferVertexData.toFloatArray()).buffer) } - private val decomposed = Matrix.Transform() + private val decomposed = MMatrix.Transform() private val tempColorMul = FloatArray(4) private val texturesToDelete = FastArrayList() private val tempUniforms = AGUniformValues() - private val tempMat = Matrix() - fun render(ctx: RenderContext, globalMatrix: Matrix, localMatrix: Matrix, applyScissor: Boolean, colorMul: RGBA, doRequireTexture: Boolean) { + private val tempMat = MMatrix() + fun render(ctx: RenderContext, globalMatrix: MMatrix, localMatrix: MMatrix, applyScissor: Boolean, colorMul: RGBA, doRequireTexture: Boolean) { val vertices = this.vertices ?: return ctx.agBufferManager.delete(verticesToDelete) verticesToDelete.clear() diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge/view/vector/GpuShapeViewPrograms.kt b/korge/src/commonMain/kotlin/com/soywiz/korge/view/vector/GpuShapeViewPrograms.kt index a5093d8a22..6301c3dbac 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge/view/vector/GpuShapeViewPrograms.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge/view/vector/GpuShapeViewPrograms.kt @@ -149,7 +149,7 @@ object GpuShapeViewPrograms { ) fun paintToShaderInfo( - stateTransform: Matrix, + stateTransform: MMatrix, paint: Paint, globalAlpha: Double, lineWidth: Double, @@ -167,7 +167,7 @@ object GpuShapeViewPrograms { } is BitmapPaint -> { - val mat = Matrix().apply { + val mat = MMatrix().apply { identity() preconcat(paint.transform) preconcat(stateTransform) @@ -196,7 +196,7 @@ object GpuShapeViewPrograms { paint.fillColors(RgbaPremultipliedArray(gradientBitmap.ints)) } - val npaint = paint.copy(transform = Matrix().apply { + val npaint = paint.copy(transform = MMatrix().apply { identity() preconcat(paint.transform) preconcat(stateTransform) @@ -215,8 +215,8 @@ object GpuShapeViewPrograms { else -> PROGRAM_TYPE_GRADIENT_LINEAR } it[u_Transform] = mat.toMatrix3D() - it[u_Gradientp0] = Vector3D(paint.x0.toFloat(), paint.y0.toFloat(), paint.r0.toFloat()) - it[u_Gradientp1] = Vector3D(paint.x1.toFloat(), paint.y1.toFloat(), paint.r1.toFloat()) + it[u_Gradientp0] = MVector4(paint.x0.toFloat(), paint.y0.toFloat(), paint.r0.toFloat()) + it[u_Gradientp1] = MVector4(paint.x1.toFloat(), paint.y1.toFloat(), paint.r1.toFloat()) it[u_GlobalAlpha] = globalAlpha.toFloat() //it[u_LineWidth] = lineWidth.toFloat() }, mapOf( diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge3d/Camera3D.kt b/korge/src/commonMain/kotlin/com/soywiz/korge3d/Camera3D.kt index e56aec5ade..eaf9869afa 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge3d/Camera3D.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge3d/Camera3D.kt @@ -1,8 +1,8 @@ package com.soywiz.korge3d import com.soywiz.korma.geom.Angle -import com.soywiz.korma.geom.Matrix3D -import com.soywiz.korma.geom.Vector3D +import com.soywiz.korma.geom.MMatrix3D +import com.soywiz.korma.geom.MVector4 import com.soywiz.korma.geom.cosine import com.soywiz.korma.geom.degrees import com.soywiz.korma.geom.minus @@ -15,7 +15,7 @@ import com.soywiz.korma.geom.unaryMinus abstract class Camera3D : View3D() { //TODO: I don't think that a Camera should subtype View - private var projMat = Matrix3D() + private var projMat = MMatrix3D() private var width: Double = 0.0 private var height: Double = 0.0 protected var dirty = true @@ -29,7 +29,7 @@ abstract class Camera3D : View3D() { } } - fun getProjMatrix(width: Double, height: Double): Matrix3D { + fun getProjMatrix(width: Double, height: Double): MMatrix3D { if (this.width != width || this.height != height) { this.dirty = true this.width = width @@ -42,7 +42,7 @@ abstract class Camera3D : View3D() { return projMat } - protected abstract fun updateMatrix(mat: Matrix3D, width: Double, height: Double) + protected abstract fun updateMatrix(mat: MMatrix3D, width: Double, height: Double) override fun render(ctx: RenderContext3D) { // Do nothing except when debugging @@ -66,7 +66,7 @@ abstract class Camera3D : View3D() { return this } - override fun updateMatrix(mat: Matrix3D, width: Double, height: Double) { + override fun updateMatrix(mat: MMatrix3D, width: Double, height: Double) { mat.setToPerspective(fov, if (height != 0.0) width / height else 1.0, near, far) } @@ -76,17 +76,17 @@ abstract class Camera3D : View3D() { } //TODO: position, target and up are also stored in transform....do we need repetition here? - val position = Vector3D(0f, 1f, 10f) + val position = MVector4(0f, 1f, 10f) var yaw = -90.degrees var pitch = 0.0.degrees var roll = 0.0.degrees var zoom = 45.degrees - val front = Vector3D(0f, 0f, -1f) - private val worldUp = Vector3D(0f, 1f, 0f) - private val up = Vector3D(0f, 1f, 0f) - private val temp = Vector3D() - private val right = Vector3D().cross(front, up).normalize() + val front = MVector4(0f, 0f, -1f) + private val worldUp = MVector4(0f, 1f, 0f) + private val up = MVector4(0f, 1f, 0f) + private val temp = MVector4() + private val right = MVector4().cross(front, up).normalize() init { diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge3d/Library3D.kt b/korge/src/commonMain/kotlin/com/soywiz/korge3d/Library3D.kt index fce36d2904..110c5b2827 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge3d/Library3D.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge3d/Library3D.kt @@ -8,7 +8,7 @@ import com.soywiz.korim.color.RGBA import com.soywiz.korim.format.readBitmap import com.soywiz.korio.file.std.resourcesVfs import com.soywiz.korma.geom.Angle -import com.soywiz.korma.geom.Matrix3D +import com.soywiz.korma.geom.MMatrix3D @Korge3DExperimental data class Library3D( @@ -47,7 +47,7 @@ data class Library3D( var scenes = FastStringMap() open class Instance3D(val library: Library3D) { - val transform = Matrix3D() + val transform = MMatrix3D() var def: Def? = null val children = arrayListOf() var id: String = "" @@ -110,17 +110,17 @@ data class Library3D( val material: MaterialDef? = null ) : ObjectDef() - data class BoneDef constructor(val index: Int, val name: String, val invBindMatrix: Matrix3D) : Def() { + data class BoneDef constructor(val index: Int, val name: String, val invBindMatrix: MMatrix3D) : Def() { lateinit var skin: SkinDef fun toBone() = Bone3D(index, name, invBindMatrix.clone()) } data class SkinDef( - val controllerId: String, - val controllerName: String, - val bindShapeMatrix: Matrix3D, - val skinSource: String, - val bones: List + val controllerId: String, + val controllerName: String, + val bindShapeMatrix: MMatrix3D, + val skinSource: String, + val bones: List ) : Def() { fun toSkin() = Skin3D(bindShapeMatrix, bones.map { it.toBone() }) } diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge3d/Light3D.kt b/korge/src/commonMain/kotlin/com/soywiz/korge3d/Light3D.kt index eb766b134f..3515912d0f 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge3d/Light3D.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge3d/Light3D.kt @@ -2,7 +2,7 @@ package com.soywiz.korge3d import com.soywiz.korim.color.Colors import com.soywiz.korim.color.RGBA -import com.soywiz.korma.geom.Vector3D +import com.soywiz.korma.geom.MVector4 @Korge3DExperimental fun Container3D.light( @@ -20,8 +20,8 @@ open class Light3D( var linearAttenuation: Double = 0.0, var quadraticAttenuation: Double = 0.00111109 ) : View3D() { - internal val colorVec = Vector3D() - internal val attenuationVec = Vector3D() + internal val colorVec = MVector4() + internal val attenuationVec = MVector4() fun setTo( color: RGBA = Colors.WHITE, diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge3d/Material3D.kt b/korge/src/commonMain/kotlin/com/soywiz/korge3d/Material3D.kt index 8d2e8728eb..ccfe599d1b 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge3d/Material3D.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge3d/Material3D.kt @@ -1,11 +1,10 @@ package com.soywiz.korge3d -import com.soywiz.korag.* import com.soywiz.korim.bitmap.Bitmap import com.soywiz.korim.color.Colors import com.soywiz.korim.color.RGBA import com.soywiz.korim.color.setToColor -import com.soywiz.korma.geom.Vector3D +import com.soywiz.korma.geom.MVector4 @Korge3DExperimental data class Material3D( @@ -22,7 +21,7 @@ data class Material3D( @Korge3DExperimental data class LightColor(val color: RGBA) : Light("color") { - val colorVec = Vector3D().setToColor(color) + val colorVec = MVector4().setToColor(color) } @Korge3DExperimental diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge3d/MeshBuilder3D.kt b/korge/src/commonMain/kotlin/com/soywiz/korge3d/MeshBuilder3D.kt index 1b3f506758..da23dc9f8a 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge3d/MeshBuilder3D.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge3d/MeshBuilder3D.kt @@ -9,7 +9,7 @@ import com.soywiz.korge3d.internal.toNBuffer import com.soywiz.korge3d.internal.vector3DTemps import com.soywiz.korim.color.Colors import com.soywiz.korim.color.RGBA -import com.soywiz.korma.geom.Vector3D +import com.soywiz.korma.geom.MVector4 import kotlin.math.PI import kotlin.math.cos import kotlin.math.sin @@ -55,7 +55,7 @@ class MeshBuilder3D( _material = Material3D(emission, ambient, diffuse, specular, shininess, indexOfRefraction) } - fun addVertex(pos: Vector3D, normal: Vector3D = Vector3D(), texcoords: Vector3D = Vector3D()): Int { + fun addVertex(pos: MVector4, normal: MVector4 = MVector4(), texcoords: MVector4 = MVector4()): Int { return addVertex(pos.x, pos.y, pos.z, normal.x, normal.y, normal.z, texcoords.x, texcoords.y) } @@ -86,7 +86,7 @@ class MeshBuilder3D( fun addIndices(vararg indices: Int) = indices.forEach { addIndex(it) } - fun faceTriangle(v1: Vector3D, v2: Vector3D, v3: Vector3D) { + fun faceTriangle(v1: MVector4, v2: MVector4, v3: MVector4) { vector3DTemps { val u = v2 - v1 val v = v3 - v1 @@ -102,7 +102,7 @@ class MeshBuilder3D( } fun faceTriangle( - v1: Vector3D, v2: Vector3D, v3: Vector3D, + v1: MVector4, v2: MVector4, v3: MVector4, nx: Float, ny: Float, nz: Float ) { val i1 = addVertex(v1.x, v1.y, v1.z, nx, ny, nz) @@ -111,7 +111,7 @@ class MeshBuilder3D( addIndices(i1, i2, i3) } - fun faceRectangle(v1: Vector3D, v2: Vector3D, v3: Vector3D, v4: Vector3D) { + fun faceRectangle(v1: MVector4, v2: MVector4, v3: MVector4, v4: MVector4) { vector3DTemps { val u = v2 - v1 val v = v3 - v1 @@ -129,8 +129,8 @@ class MeshBuilder3D( } fun faceRectangle( - v1: Vector3D, v2: Vector3D, v3: Vector3D, v4: Vector3D, - t1: Vector3D, t2: Vector3D, t3: Vector3D, t4: Vector3D + v1: MVector4, v2: MVector4, v3: MVector4, v4: MVector4, + t1: MVector4, t2: MVector4, t3: MVector4, t4: MVector4 ) { vector3DTemps { val u = v2 - v1 @@ -148,7 +148,7 @@ class MeshBuilder3D( } } - fun pyramidTriangleBase(v1: Vector3D, v2: Vector3D, v3: Vector3D, v4: Vector3D) { + fun pyramidTriangleBase(v1: MVector4, v2: MVector4, v3: MVector4, v4: MVector4) { // cannot reuse vertices because the normals need to be different! faceTriangle(v1, v2, v3) faceTriangle(v1, v2, v4) @@ -170,16 +170,16 @@ class MeshBuilder3D( val hz = depth / 2f // front face, clockwise - val v1 = Vector3D(-hx, +hy, -hz) - val v2 = Vector3D(+hx, +hy, -hz) - val v3 = Vector3D(+hx, -hy, -hz) - val v4 = Vector3D(-hx, -hy, -hz) + val v1 = MVector4(-hx, +hy, -hz) + val v2 = MVector4(+hx, +hy, -hz) + val v3 = MVector4(+hx, -hy, -hz) + val v4 = MVector4(-hx, -hy, -hz) // back face, clockwise - val v5 = Vector3D(-hx, +hy, +hz) - val v6 = Vector3D(+hx, +hy, +hz) - val v7 = Vector3D(+hx, -hy, +hz) - val v8 = Vector3D(-hx, -hy, +hz) + val v5 = MVector4(-hx, +hy, +hz) + val v6 = MVector4(+hx, +hy, +hz) + val v7 = MVector4(+hx, -hy, +hz) + val v8 = MVector4(-hx, -hy, +hz) // cannot reuse vertices because the normals need to be different! faceRectangle(v1, v2, v3, v4) //front @@ -198,10 +198,10 @@ class MeshBuilder3D( val x = cos(u) * sin(v) * rx val y = cos(v) * ry val z = sin(u) * sin(v) * rz - Vector3D(x, y, z) + MVector4(x, y, z) } - fun parametric(longitudeLines: Int = 10, latitudeLines: Int = 10, F: (u: Float, v: Float) -> Vector3D) { + fun parametric(longitudeLines: Int = 10, latitudeLines: Int = 10, F: (u: Float, v: Float) -> MVector4) { // modified from [https://stackoverflow.com/questions/7687148/drawing-sphere-in-opengl-without-using-glusphere] val startU = 0f val startV = 0f diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge3d/RenderContext3D.kt b/korge/src/commonMain/kotlin/com/soywiz/korge3d/RenderContext3D.kt index 4b84d12a91..3249d0be66 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge3d/RenderContext3D.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge3d/RenderContext3D.kt @@ -6,26 +6,26 @@ import com.soywiz.korag.* import com.soywiz.korge.render.AgBitmapTextureManager import com.soywiz.korge.render.AgBufferManager import com.soywiz.korge.render.RenderContext -import com.soywiz.korma.geom.Matrix3D -import com.soywiz.korma.geom.Vector3D +import com.soywiz.korma.geom.MMatrix3D +import com.soywiz.korma.geom.MVector4 @Korge3DExperimental class RenderContext3D() { lateinit var ag: AG lateinit var rctx: RenderContext val shaders = Shaders3D() - val bindMat4 = Matrix3D() - val bones = Array(128) { Matrix3D() } - val tempMat = Matrix3D() - val projMat: Matrix3D = Matrix3D() + val bindMat4 = MMatrix3D() + val bones = Array(128) { MMatrix3D() } + val tempMat = MMatrix3D() + val projMat: MMatrix3D = MMatrix3D() val lights = arrayListOf() - val projCameraMat: Matrix3D = Matrix3D() - val cameraMat: Matrix3D = Matrix3D() - val cameraMatInv: Matrix3D = Matrix3D() + val projCameraMat: MMatrix3D = MMatrix3D() + val cameraMat: MMatrix3D = MMatrix3D() + val cameraMatInv: MMatrix3D = MMatrix3D() val dynamicVertexBufferPool = Pool { AGBuffer() } val dynamicVertexDataPool = Pool { AGVertexData() } val dynamicIndexBufferPool = Pool { AGBuffer() } - val ambientColor: Vector3D = Vector3D() + val ambientColor: MVector4 = MVector4() val textureManager by lazy { AgBitmapTextureManager(ag) } val bufferManager by lazy { AgBufferManager(ag) } diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge3d/Shapes3D.kt b/korge/src/commonMain/kotlin/com/soywiz/korge3d/Shapes3D.kt index e866484bcf..3ed308ae80 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge3d/Shapes3D.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge3d/Shapes3D.kt @@ -1,8 +1,8 @@ package com.soywiz.korge3d import com.soywiz.korge3d.internal.vector3DTemps -import com.soywiz.korma.geom.Matrix3D -import com.soywiz.korma.geom.Vector3D +import com.soywiz.korma.geom.MMatrix3D +import com.soywiz.korma.geom.MVector4 import com.soywiz.korma.geom.scale import kotlin.math.PI import kotlin.math.cos @@ -26,7 +26,7 @@ class Shape3D( var height: Double = initHeight var depth: Double = initDepth - override fun prepareExtraModelMatrix(mat: Matrix3D) { + override fun prepareExtraModelMatrix(mat: MMatrix3D) { mat.identity().scale(width, height, depth) } @@ -67,39 +67,39 @@ fun T.material(material: Material3D?): T { @Korge3DExperimental class Cube3D(var width: Double, var height: Double, var depth: Double) : BaseViewWithMesh3D(mesh) { - override fun prepareExtraModelMatrix(mat: Matrix3D) { + override fun prepareExtraModelMatrix(mat: MMatrix3D) { mat.identity().scale(width, height, depth) } companion object { val mesh = MeshBuilder3D { vector3DTemps { - fun face(pos: Vector3D) { + fun face(pos: MVector4) { val dims = (0 until 3).filter { pos[it] == 0f } - val normal = Vector3D().setToFunc { if (pos[it] != 0f) 1f else 0f } - val dirs = Array(2) { dim -> Vector3D().setToFunc { if (it == dims[dim]) .5f else 0f } } + val normal = MVector4().setToFunc { if (pos[it] != 0f) 1f else 0f } + val dirs = Array(2) { dim -> MVector4().setToFunc { if (it == dims[dim]) .5f else 0f } } val dx = dirs[0] val dy = dirs[1] - val i0 = addVertex(pos - dx - dy, normal, Vector3D(0f, 0f, 0f)) - val i1 = addVertex(pos + dx - dy, normal, Vector3D(1f, 0f, 0f)) - val i2 = addVertex(pos - dx + dy, normal, Vector3D(0f, 1f, 0f)) + val i0 = addVertex(pos - dx - dy, normal, MVector4(0f, 0f, 0f)) + val i1 = addVertex(pos + dx - dy, normal, MVector4(1f, 0f, 0f)) + val i2 = addVertex(pos - dx + dy, normal, MVector4(0f, 1f, 0f)) - val i3 = addVertex(pos - dx + dy, normal, Vector3D(0f, 1f, 0f)) - val i4 = addVertex(pos + dx - dy, normal, Vector3D(1f, 0f, 0f)) - val i5 = addVertex(pos + dx + dy, normal, Vector3D(1f, 1f, 0f)) + val i3 = addVertex(pos - dx + dy, normal, MVector4(0f, 1f, 0f)) + val i4 = addVertex(pos + dx - dy, normal, MVector4(1f, 0f, 0f)) + val i5 = addVertex(pos + dx + dy, normal, MVector4(1f, 1f, 0f)) addIndices(i0, i1, i2, i3, i4, i5) } - face(Vector3D(0f, +.5f, 0f)) - face(Vector3D(0f, -.5f, 0f)) + face(MVector4(0f, +.5f, 0f)) + face(MVector4(0f, -.5f, 0f)) - face(Vector3D(+.5f, 0f, 0f)) - face(Vector3D(-.5f, 0f, 0f)) + face(MVector4(+.5f, 0f, 0f)) + face(MVector4(-.5f, 0f, 0f)) - face(Vector3D(0f, 0f, +.5f)) - face(Vector3D(0f, 0f, -.5f)) + face(MVector4(0f, 0f, +.5f)) + face(MVector4(0f, 0f, -.5f)) } } } @@ -119,7 +119,7 @@ inline fun Container3D.sphere( @Korge3DExperimental class Sphere3D(var radius: Double) : BaseViewWithMesh3D(mesh) { - override fun prepareExtraModelMatrix(mat: Matrix3D) { + override fun prepareExtraModelMatrix(mat: MMatrix3D) { mat.identity().scale(radius, radius, radius) } @@ -130,8 +130,8 @@ class Sphere3D(var radius: Double) : BaseViewWithMesh3D(mesh) { val N = 16 val M = 16 - val p = Vector3D() - val nv = Vector3D() + val p = MVector4() + val nv = MVector4() for (m in 0..M) { for (n in 0..N) { @@ -141,7 +141,7 @@ class Sphere3D(var radius: Double) : BaseViewWithMesh3D(mesh) { nv.copyFrom(p) nv.normalize() - addVertex(p, nv, Vector3D(0f, 0f, 0f)) + addVertex(p, nv, MVector4(0f, 0f, 0f)) } } diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge3d/Skeleton3D.kt b/korge/src/commonMain/kotlin/com/soywiz/korge3d/Skeleton3D.kt index 35ed93ee6e..44dd2def27 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge3d/Skeleton3D.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge3d/Skeleton3D.kt @@ -1,7 +1,7 @@ package com.soywiz.korge3d import com.soywiz.korge3d.internal.toFast -import com.soywiz.korma.geom.Matrix3D +import com.soywiz.korma.geom.MMatrix3D import com.soywiz.korma.geom.invert @Korge3DExperimental @@ -10,7 +10,7 @@ open class Joint3D constructor( val jname: String, val jsid: String, val jointParent: Joint3D? = null, - initialMatrix: Matrix3D + initialMatrix: MMatrix3D ) : Container3D() { init { this.transform.setMatrix(initialMatrix) @@ -41,13 +41,13 @@ open class Joint3D constructor( data class Bone3D constructor( val index: Int, val name: String, - val invBindMatrix: Matrix3D + val invBindMatrix: MMatrix3D ) @Korge3DExperimental -data class Skin3D(val bindShapeMatrix: Matrix3D, val bones: List) { +data class Skin3D(val bindShapeMatrix: MMatrix3D, val bones: List) { val bindShapeMatrixInv = bindShapeMatrix.clone().invert() - val matrices = Array(bones.size) { Matrix3D() } + val matrices = Array(bones.size) { MMatrix3D() } } @Korge3DExperimental diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge3d/SkyBox.kt b/korge/src/commonMain/kotlin/com/soywiz/korge3d/SkyBox.kt index 29e638340b..80bdb8dc80 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge3d/SkyBox.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge3d/SkyBox.kt @@ -15,8 +15,8 @@ import com.soywiz.korim.format.readBitmap import com.soywiz.korio.async.async import com.soywiz.korio.file.VfsFile import com.soywiz.korio.file.std.resourcesVfs -import com.soywiz.korma.geom.Matrix3D -import com.soywiz.korma.geom.Vector3D +import com.soywiz.korma.geom.MMatrix3D +import com.soywiz.korma.geom.MVector4 import com.soywiz.korma.geom.translate import kotlinx.coroutines.coroutineScope @@ -56,13 +56,13 @@ suspend fun VfsFile.readCubeMap(ext: String): CubeMap { @Korge3DExperimental fun Stage3D.skyBox(cubemap: CubeMap, centerX: Float = 0f, centerY: Float = 0f, centerZ: Float = 0f): SkyBox { - return SkyBox(cubemap, Vector3D(centerX, centerY, centerZ)).addTo(this) + return SkyBox(cubemap, MVector4(centerX, centerY, centerZ)).addTo(this) } @Korge3DExperimental class SkyBox( val cubemap: CubeMap, - val center: Vector3D + val center: MVector4 ) : View3D() { /* inner class Texture3DDrawer { @@ -156,7 +156,7 @@ class SkyBox( private val uniformValues = AGUniformValues() private val rs = AGDepthAndFrontFace.DEFAULT.withDepthMask(depthMask = false).withDepthFunc(depthFunc = AGCompareMode.LESS_EQUAL) - private val viewNoTrans = Matrix3D() + private val viewNoTrans = MMatrix3D() override fun render(ctx: RenderContext3D) { //println("----------- SkyBox render ---------------") diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge3d/Terrain3D.kt b/korge/src/commonMain/kotlin/com/soywiz/korge3d/Terrain3D.kt index 9f8b461b3c..61a845b9ba 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge3d/Terrain3D.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge3d/Terrain3D.kt @@ -4,8 +4,8 @@ import com.soywiz.kds.iterators.fastForEachWithIndex import com.soywiz.kmem.clamp import com.soywiz.korag.* import com.soywiz.korim.bitmap.Bitmap -import com.soywiz.korma.geom.Matrix3D -import com.soywiz.korma.geom.Vector3D +import com.soywiz.korma.geom.MMatrix3D +import com.soywiz.korma.geom.MVector4 interface HeightMap { operator fun get(x: Float, z: Float): Float @@ -62,25 +62,25 @@ class Terrain3D( private val uniformValues = AGUniformValues() private val rs = AGDepthAndFrontFace.DEFAULT.withDepthFunc(depthFunc = AGCompareMode.LESS_EQUAL) - private val tempMat1 = Matrix3D() - private val tempMat2 = Matrix3D() - private val tempMat3 = Matrix3D() + private val tempMat1 = MMatrix3D() + private val tempMat2 = MMatrix3D() + private val tempMat3 = MMatrix3D() private fun getHeight(x: Float, z: Float) : Float = heightMap[x,z] * heightScale - fun calcNormal(x: Float, z: Float): Vector3D { + fun calcNormal(x: Float, z: Float): MVector4 { val hl = getHeight(x - 1, z) val hr = getHeight(x + 1, z) val hf = getHeight(x, z + 1) val hb = getHeight(x, z - 1) - val v = Vector3D(hl - hr, 2f, hb - hf).normalize() + val v = MVector4(hl - hr, 2f, hb - hf).normalize() return v } fun createMesh(): Mesh3D { meshBuilder3D.reset() - val vec = Vector3D() - val tex = Vector3D() //TODO: + val vec = MVector4() + val tex = MVector4() //TODO: var z = 0f val adjX = (width / 2) + centerX val adjZ = (depth / 2) + centerZ diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge3d/Text3D.kt b/korge/src/commonMain/kotlin/com/soywiz/korge3d/Text3D.kt index daa3d2e257..a08e3e23bc 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge3d/Text3D.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge3d/Text3D.kt @@ -5,34 +5,33 @@ import com.soywiz.kmem.clamp import com.soywiz.korag.* import com.soywiz.korge.render.Texture import com.soywiz.korge.ui.DefaultUIBitmapFont -import com.soywiz.korim.bitmap.* import com.soywiz.korim.font.BitmapFont -import com.soywiz.korma.geom.Matrix3D -import com.soywiz.korma.geom.Vector3D +import com.soywiz.korma.geom.MMatrix3D +import com.soywiz.korma.geom.MVector4 import com.soywiz.korma.geom.invert @Korge3DExperimental -fun Container3D.text3D(str: String, v1: Vector3D, v2: Vector3D, v3: Vector3D, v4: Vector3D): Text3D = +fun Container3D.text3D(str: String, v1: MVector4, v2: MVector4, v3: MVector4, v4: MVector4): Text3D = Text3D(str, v1, v2, v3, v4).addTo(this) @Korge3DExperimental class Text3D( var text: String, - var v1: Vector3D, var v2: Vector3D, var v3: Vector3D, var v4: Vector3D + var v1: MVector4, var v2: MVector4, var v3: MVector4, var v4: MVector4 ) : View3D() { var font: BitmapFont = DefaultUIBitmapFont - protected open fun prepareExtraModelMatrix(mat: Matrix3D) { + protected open fun prepareExtraModelMatrix(mat: MMatrix3D) { mat.identity() } private val uniformValues = AGUniformValues() private val rs = AGDepthAndFrontFace.DEFAULT.withDepthFunc(depthFunc = AGCompareMode.LESS_EQUAL) - private val tempMat1 = Matrix3D() - private val tempMat2 = Matrix3D() - private val tempMat3 = Matrix3D() - private val identity = Matrix3D() + private val tempMat1 = MMatrix3D() + private val tempMat2 = MMatrix3D() + private val tempMat3 = MMatrix3D() + private val identity = MMatrix3D() fun AGUniformValues.setMaterialLight( @@ -122,14 +121,14 @@ class Text3D( var dx = 0.0 var dy = 0.0 - val dv1 = Vector3D(v1.x, v1.y, v1.z, v1.w) - val dv2 = Vector3D(v2.x, v2.y, v3.z, v2.w) - val dv3 = Vector3D(v3.x, v3.y, v3.z, v3.w) - val dv4 = Vector3D(v4.x, v4.y, v4.z, v4.w) - val t1 = Vector3D() - val t2 = Vector3D() - val t3 = Vector3D() - val t4 = Vector3D() + val dv1 = MVector4(v1.x, v1.y, v1.z, v1.w) + val dv2 = MVector4(v2.x, v2.y, v3.z, v2.w) + val dv3 = MVector4(v3.x, v3.y, v3.z, v3.w) + val dv4 = MVector4(v4.x, v4.y, v4.z, v4.w) + val t1 = MVector4() + val t2 = MVector4() + val t3 = MVector4() + val t4 = MVector4() for (n in str.indices) { val c1 = str[n].toInt() if (c1 == '\n'.toInt()) { diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge3d/Transform3D.kt b/korge/src/commonMain/kotlin/com/soywiz/korge3d/Transform3D.kt index f6edb74483..85996830f6 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge3d/Transform3D.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge3d/Transform3D.kt @@ -1,12 +1,12 @@ package com.soywiz.korge3d import com.soywiz.korma.geom.Angle -import com.soywiz.korma.geom.EulerRotation -import com.soywiz.korma.geom.Matrix3D +import com.soywiz.korma.geom.MEulerRotation +import com.soywiz.korma.geom.MMatrix3D import com.soywiz.korma.geom.Position3D -import com.soywiz.korma.geom.Quaternion +import com.soywiz.korma.geom.MQuaternion import com.soywiz.korma.geom.Scale3D -import com.soywiz.korma.geom.Vector3D +import com.soywiz.korma.geom.MVector4 import com.soywiz.korma.geom.getTRS import com.soywiz.korma.geom.plus import com.soywiz.korma.geom.setTRS @@ -19,20 +19,20 @@ class Transform3D { internal var transformDirty = false companion object { - private val identityMat = Matrix3D() + private val identityMat = MMatrix3D() } - val globalMatrixUncached: Matrix3D = Matrix3D() + val globalMatrixUncached: MMatrix3D = MMatrix3D() get() { val parent = parent?.globalMatrixUncached ?: identityMat field.multiply(parent, matrix) return field } - val globalMatrix: Matrix3D + val globalMatrix: MMatrix3D get() = globalMatrixUncached // @TODO: Cache! - val matrix: Matrix3D = Matrix3D() + val matrix: MMatrix3D = MMatrix3D() get() { if (matrixDirty) { matrixDirty = false @@ -50,9 +50,9 @@ class Transform3D { field?.children?.add(this) } - private val _translation = Vector3D(0, 0, 0) - private val _rotation = Quaternion() - private val _scale = Vector3D(1, 1, 1) + private val _translation = MVector4(0, 0, 0) + private val _rotation = MQuaternion() + private val _scale = MVector4(1, 1, 1) @PublishedApi internal var _eulerRotationDirty: Boolean = true @@ -70,10 +70,10 @@ class Transform3D { } val translation: Position3D get() = updateTRSIfRequired()._translation - val rotation: Quaternion get() = updateTRSIfRequired()._rotation + val rotation: MQuaternion get() = updateTRSIfRequired()._rotation val scale: Scale3D get() = updateTRSIfRequired()._scale - var rotationEuler: EulerRotation = EulerRotation() + var rotationEuler: MEulerRotation = MEulerRotation() private set get() { if (_eulerRotationDirty) { @@ -86,7 +86,7 @@ class Transform3D { ///////////////// ///////////////// - fun setMatrix(mat: Matrix3D): Transform3D { + fun setMatrix(mat: MMatrix3D): Transform3D { transformDirty = true this.matrix.copyFrom(mat) return this @@ -100,7 +100,7 @@ class Transform3D { fun setTranslation(x: Double, y: Double, z: Double, w: Double = 1.0) = setTranslation(x.toFloat(), y.toFloat(), z.toFloat(), w.toFloat()) fun setTranslation(x: Int, y: Int, z: Int, w: Int = 1) = setTranslation(x.toFloat(), y.toFloat(), z.toFloat(), w.toFloat()) - fun setRotation(quat: Quaternion) = updatingTRS { + fun setRotation(quat: MQuaternion) = updatingTRS { updateTRSIfRequired() matrixDirty = true _eulerRotationDirty = true @@ -115,7 +115,7 @@ class Transform3D { fun setRotation(x: Double, y: Double, z: Double, w: Double) = setRotation(x.toFloat(), y.toFloat(), z.toFloat(), w.toFloat()) fun setRotation(x: Int, y: Int, z: Int, w: Int) = setRotation(x.toFloat(), y.toFloat(), z.toFloat(), w.toFloat()) - fun setRotation(euler: EulerRotation) = updatingTRS { + fun setRotation(euler: MEulerRotation) = updatingTRS { _eulerRotationDirty = true rotation.setEuler(euler) } @@ -143,31 +143,31 @@ class Transform3D { ///////////////// @PublishedApi - internal val UP = Vector3D(0f, 1f, 0f) + internal val UP = MVector4(0f, 1f, 0f) @PublishedApi - internal val tempMat1 = Matrix3D() + internal val tempMat1 = MMatrix3D() @PublishedApi - internal val tempMat2 = Matrix3D() + internal val tempMat2 = MMatrix3D() @PublishedApi - internal val tempVec1 = Vector3D() + internal val tempVec1 = MVector4() @PublishedApi - internal val tempVec2 = Vector3D() + internal val tempVec2 = MVector4() - fun lookAt(tx: Float, ty: Float, tz: Float, up: Vector3D = UP): Transform3D { + fun lookAt(tx: Float, ty: Float, tz: Float, up: MVector4 = UP): Transform3D { tempMat1.setToLookAt(translation, tempVec1.setTo(tx, ty, tz, 1f), up) rotation.setFromRotationMatrix(tempMat1) return this } - fun lookAt(tx: Double, ty: Double, tz: Double, up: Vector3D = UP) = lookAt(tx.toFloat(), ty.toFloat(), tz.toFloat(), up) - fun lookAt(tx: Int, ty: Int, tz: Int, up: Vector3D = UP) = lookAt(tx.toFloat(), ty.toFloat(), tz.toFloat(), up) + fun lookAt(tx: Double, ty: Double, tz: Double, up: MVector4 = UP) = lookAt(tx.toFloat(), ty.toFloat(), tz.toFloat(), up) + fun lookAt(tx: Int, ty: Int, tz: Int, up: MVector4 = UP) = lookAt(tx.toFloat(), ty.toFloat(), tz.toFloat(), up) //setTranslation(px, py, pz) //lookUp(tx, ty, tz, up) fun setTranslationAndLookAt( px: Float, py: Float, pz: Float, tx: Float, ty: Float, tz: Float, - up: Vector3D = UP + up: MVector4 = UP ): Transform3D = setMatrix( matrix.multiply( tempMat1.setToTranslation(px, py, pz), @@ -177,10 +177,10 @@ class Transform3D { fun setTranslationAndLookAt( px: Double, py: Double, pz: Double, tx: Double, ty: Double, tz: Double, - up: Vector3D = UP + up: MVector4 = UP ) = setTranslationAndLookAt(px.toFloat(), py.toFloat(), pz.toFloat(), tx.toFloat(), ty.toFloat(), tz.toFloat(), up) - private val tempEuler = EulerRotation() + private val tempEuler = MEulerRotation() fun rotate(x: Angle, y: Angle, z: Angle): Transform3D { val re = this.rotationEuler tempEuler.setTo(re.x+x,re.y+y, re.z+z) @@ -188,7 +188,7 @@ class Transform3D { return this } - fun translate(vec:Vector3D) : Transform3D { + fun translate(vec:MVector4) : Transform3D { this.setTranslation( this.translation.x + vec.x, this.translation.y + vec.y, this.translation.z+vec.z ) return this } diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge3d/View3D.kt b/korge/src/commonMain/kotlin/com/soywiz/korge3d/View3D.kt index 5930fca0b4..572e37e82b 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge3d/View3D.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge3d/View3D.kt @@ -3,7 +3,7 @@ package com.soywiz.korge3d import com.soywiz.kds.iterators.fastForEach import com.soywiz.korge.baseview.BaseView import com.soywiz.korma.geom.Angle -import com.soywiz.korma.geom.Matrix3D +import com.soywiz.korma.geom.MMatrix3D import com.soywiz.korma.geom.degrees @Korge3DExperimental @@ -111,7 +111,7 @@ abstract class View3D : BaseView() { } get() = _parent - val modelMat = Matrix3D() + val modelMat = MMatrix3D() //val position = Vector3D() diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge3d/ViewWithMesh3D.kt b/korge/src/commonMain/kotlin/com/soywiz/korge3d/ViewWithMesh3D.kt index ceaa80d640..9a6a080548 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge3d/ViewWithMesh3D.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge3d/ViewWithMesh3D.kt @@ -5,7 +5,7 @@ import com.soywiz.kds.iterators.fastForEach import com.soywiz.kds.iterators.fastForEachWithIndex import com.soywiz.kmem.clamp import com.soywiz.korag.* -import com.soywiz.korma.geom.Matrix3D +import com.soywiz.korma.geom.MMatrix3D import com.soywiz.korma.geom.invert @Korge3DExperimental @@ -23,11 +23,11 @@ open class ViewWithMesh3D( private val rs = AGDepthAndFrontFace.DEFAULT.withDepthFunc(depthFunc = AGCompareMode.LESS_EQUAL) //private val rs = AGRenderState(depthFunc = AGCompareMode.ALWAYS) - private val tempMat1 = Matrix3D() - private val tempMat2 = Matrix3D() - private val tempMat3 = Matrix3D() + private val tempMat1 = MMatrix3D() + private val tempMat2 = MMatrix3D() + private val tempMat3 = MMatrix3D() - protected open fun prepareExtraModelMatrix(mat: Matrix3D) { + protected open fun prepareExtraModelMatrix(mat: MMatrix3D) { mat.identity() } @@ -46,7 +46,7 @@ open class ViewWithMesh3D( } } - private val identity = Matrix3D() + private val identity = MMatrix3D() private val identityInv = identity.clone().invert() override fun render(ctx: RenderContext3D) { diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge3d/animation/Animator3D.kt b/korge/src/commonMain/kotlin/com/soywiz/korge3d/animation/Animator3D.kt index a0d83bdb31..b2e0795aef 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge3d/animation/Animator3D.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge3d/animation/Animator3D.kt @@ -9,7 +9,7 @@ import com.soywiz.korge3d.Library3D import com.soywiz.korge3d.Transform3D import com.soywiz.korge3d.View3D import com.soywiz.korge3d.get -import com.soywiz.korma.geom.Matrix3D +import com.soywiz.korma.geom.MMatrix3D import com.soywiz.korma.geom.degrees import com.soywiz.korma.interpolation.interpolate @@ -110,7 +110,7 @@ data class Animation3D(val id: String, val target: String, val property: String, var seconds: FloatArray = floatArrayOf(), var interpolations: Array = arrayOf(), var floats: FloatArray? = null, - var matrices: Array? = null + var matrices: Array? = null ) { val transforms = matrices?.map { Transform3D().setMatrix(it) }?.toTypedArray() val totalFrames = seconds.size diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge3d/format/Collada.kt b/korge/src/commonMain/kotlin/com/soywiz/korge3d/format/Collada.kt index 894aa5d98b..2bf8288f31 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge3d/format/Collada.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge3d/format/Collada.kt @@ -24,10 +24,10 @@ import com.soywiz.korio.serialization.xml.text import com.soywiz.korio.util.StrReader import com.soywiz.korio.util.buildList import com.soywiz.korio.util.reader -import com.soywiz.korma.geom.EulerRotation -import com.soywiz.korma.geom.Matrix3D -import com.soywiz.korma.geom.Quaternion -import com.soywiz.korma.geom.Vector3D +import com.soywiz.korma.geom.MEulerRotation +import com.soywiz.korma.geom.MMatrix3D +import com.soywiz.korma.geom.MQuaternion +import com.soywiz.korma.geom.MVector4 import com.soywiz.korma.geom.degrees import com.soywiz.korma.geom.plus import com.soywiz.korma.geom.setTRS @@ -48,7 +48,7 @@ class ColladaParser { val name: String } - data class MatrixSourceParam(override val name: String, val matrices: Array) : SourceParam + data class MatrixSourceParam(override val name: String, val matrices: Array) : SourceParam data class FloatSourceParam(override val name: String, val floats: FloatArrayList) : SourceParam data class NamesSourceParam(override val name: String, val names: ArrayList) : SourceParam data class Source(val id: String, val params: FastStringMap) @@ -65,7 +65,7 @@ class ColladaParser { val controllerName: String, val inputs: FastStringMap, val vcounts: IntArrayList, - val bindShapeMatrix: Matrix3D, + val bindShapeMatrix: MMatrix3D, val jointInputs: FastStringMap, val skinSource: String ) { @@ -339,7 +339,7 @@ class ColladaParser { if (skin != null) { val skinSource = skin.str("source") val bindShapeMatrix = skin["bind_shape_matrix"].firstOrNull()?.text?.reader()?.readMatrix3D() - ?: Matrix3D() + ?: MMatrix3D() for (source in parseSources(skin, this@ColladaParser.sourceArrayParams)) { sources[source.id] = source } @@ -566,7 +566,7 @@ class ColladaParser { } } - fun FastStringMap.getMatrices(a: String, b: String): Array? = + fun FastStringMap.getMatrices(a: String, b: String): Array? = (this[a]?.params?.get(b) as? MatrixSourceParam?)?.matrices fun FastStringMap.getStrings(a: String, b: String): Array? = @@ -585,7 +585,7 @@ class ColladaParser { when (technique.nameLC) { "point" -> { val color = technique["color"].firstOrNull()?.text?.reader()?.readVector3D() - ?: Vector3D(1, 1, 1) + ?: MVector4(1, 1, 1) val constant_attenuation = technique["constant_attenuation"].firstOrNull()?.text?.toDoubleOrNull() ?: 1.0 @@ -603,7 +603,7 @@ class ColladaParser { } "ambient" -> { val color = technique["color"].firstOrNull()?.text?.reader()?.readVector3D() - ?: Vector3D(1, 1, 1) + ?: MVector4(1, 1, 1) lightDef = Library3D.AmbientLightDef(RGBA.float(color.x, color.y, color.z, 1f)) } else -> { @@ -732,11 +732,11 @@ class ColladaParser { instancesById: FastStringMap ): Library3D.Instance3D { val instance = Library3D.Instance3D(this) - var location: Vector3D? = null - var scale: Vector3D? = null - var rotationX: Vector3D? = null - var rotationY: Vector3D? = null - var rotationZ: Vector3D? = null + var location: MVector4? = null + var scale: MVector4? = null + var rotationX: MVector4? = null + var rotationY: MVector4? = null + var rotationZ: MVector4? = null instance.id = node.str("id") instance.sid = node.getString("sid") @@ -812,16 +812,16 @@ class ColladaParser { } } if (location != null || scale != null || rotationX != null || rotationY != null || rotationZ != null) { - val trns = location ?: Vector3D(0, 0, 0, 1) - val scl = scale ?: Vector3D(1, 1, 1) - val rotX = rotationX ?: Vector3D(1, 0, 0, 0) - val rotY = rotationY ?: Vector3D(0, 1, 0, 0) - val rotZ = rotationZ ?: Vector3D(0, 0, 1, 0) + val trns = location ?: MVector4(0, 0, 0, 1) + val scl = scale ?: MVector4(1, 1, 1) + val rotX = rotationX ?: MVector4(1, 0, 0, 0) + val rotY = rotationY ?: MVector4(0, 1, 0, 0) + val rotZ = rotationZ ?: MVector4(0, 0, 1, 0) rotationVectorToEulerRotation(rotX) instance.transform.setTRS( trns, - Quaternion().setTo( + MQuaternion().setTo( combine( rotationVectorToEulerRotation(rotX), rotationVectorToEulerRotation(rotY), @@ -835,15 +835,15 @@ class ColladaParser { } private fun combine( - a: EulerRotation, - b: EulerRotation, - c: EulerRotation, - out: EulerRotation = EulerRotation() - ): EulerRotation { + a: MEulerRotation, + b: MEulerRotation, + c: MEulerRotation, + out: MEulerRotation = MEulerRotation() + ): MEulerRotation { return out.setTo(a.x + b.x + c.x, a.y + b.y + c.y, a.z + b.z + c.z) } - private fun rotationVectorToEulerRotation(vec: Vector3D, out: EulerRotation = EulerRotation()): EulerRotation { + private fun rotationVectorToEulerRotation(vec: MVector4, out: MEulerRotation = MEulerRotation()): MEulerRotation { val degrees = vec.w.degrees return out.setTo(degrees * vec.x, degrees * vec.y, degrees * vec.z) } @@ -896,7 +896,7 @@ class ColladaParser { } "float4x4" -> { val floats = (data as FloatSourceParam).floats.data - val out = Array(count) { Matrix3D() } + val out = Array(count) { MMatrix3D() } for (n in 0 until count) { out[n].setFromColladaData(floats, (n * stride) + totalOffset) //mat.transpose() @@ -936,21 +936,21 @@ class ColladaParser { //fun com.soywiz.korma.geom.Matrix3D.setFromColladaData(f: FloatArray, o: Int) = setColumns( //private fun Matrix3D.setFromColladaData(f: FloatArray, o: Int) = setColumns4x4(f, o) -private fun Matrix3D.setFromColladaData(f: FloatArray, o: Int) = setRows4x4(f, o) +private fun MMatrix3D.setFromColladaData(f: FloatArray, o: Int) = setRows4x4(f, o) -private fun StrReader.readVector3D(): Vector3D { +private fun StrReader.readVector3D(): MVector4 { val f = readFloats(FloatArrayList()) return when { - f.size == 4 -> Vector3D(f[0], f[1], f[2], f[3]) - else -> Vector3D(f[0], f[1], f[2]) + f.size == 4 -> MVector4(f[0], f[1], f[2], f[3]) + else -> MVector4(f[0], f[1], f[2]) } } -private fun StrReader.readMatrix3D(): Matrix3D { +private fun StrReader.readMatrix3D(): MMatrix3D { val f = readFloats(FloatArrayList()) if (f.size == 16) { //return com.soywiz.korma.geom.Matrix3D().setRows( - return Matrix3D().setFromColladaData(f.data, 0) + return MMatrix3D().setFromColladaData(f.data, 0) } else { error("Invalid matrix size ${f.size} : str='$str'") } diff --git a/korge/src/commonMain/kotlin/com/soywiz/korge3d/internal/InternalExt.kt b/korge/src/commonMain/kotlin/com/soywiz/korge3d/internal/InternalExt.kt index 865abd0be5..de50b48aa5 100644 --- a/korge/src/commonMain/kotlin/com/soywiz/korge3d/internal/InternalExt.kt +++ b/korge/src/commonMain/kotlin/com/soywiz/korge3d/internal/InternalExt.kt @@ -2,7 +2,7 @@ package com.soywiz.korge3d.internal import com.soywiz.kds.* import com.soywiz.kmem.* -import com.soywiz.korma.geom.Vector3D +import com.soywiz.korma.geom.MVector4 import kotlin.native.concurrent.ThreadLocal internal fun Map.toFast() = FastStringMap().apply { @@ -12,7 +12,7 @@ internal fun Map.toFast() = FastStringMap().apply { } } -internal operator fun Vector3D.get(char: Char): Float = when (char) { +internal operator fun MVector4.get(char: Char): Float = when (char) { 'x', 'r' -> this[0] 'y', 'g' -> this[1] 'z', 'b' -> this[2] @@ -22,7 +22,7 @@ internal operator fun Vector3D.get(char: Char): Float = when (char) { else -> Float.NaN } -internal fun Vector3D.swizzle(name: String, input: Vector3D = this): Vector3D { +internal fun MVector4.swizzle(name: String, input: MVector4 = this): MVector4 { val x = name.getOrElse(0) { '0' } val y = name.getOrElse(1) { '0' } val z = name.getOrElse(2) { '0' } @@ -30,7 +30,7 @@ internal fun Vector3D.swizzle(name: String, input: Vector3D = this): Vector3D { return this.setTo(input[x], input[y], input[z], input[w]) } -internal operator fun Vector3D.get(name: String): Vector3D = Vector3D().copyFrom(this).swizzle(name) +internal operator fun MVector4.get(name: String): MVector4 = MVector4().copyFrom(this).swizzle(name) @ThreadLocal internal val vector3DTemps = Vector3DTemps() @@ -39,14 +39,14 @@ internal class Vector3DTemps { @PublishedApi internal var pos = 0 @PublishedApi - internal val items = arrayListOf(Vector3D(), Vector3D(), Vector3D()) + internal val items = arrayListOf(MVector4(), MVector4(), MVector4()) - fun alloc(): Vector3D { + fun alloc(): MVector4 { val npos = pos++ return if (npos < items.size) { items[npos] } else { - val item = Vector3D() + val item = MVector4() items.add(item) item } @@ -61,8 +61,8 @@ internal class Vector3DTemps { } } - operator fun Vector3D.plus(that: Vector3D) = alloc().setToFunc { this[it] + that[it] } - operator fun Vector3D.minus(that: Vector3D) = alloc().setToFunc { this[it] - that[it] } + operator fun MVector4.plus(that: MVector4) = alloc().setToFunc { this[it] + that[it] } + operator fun MVector4.minus(that: MVector4) = alloc().setToFunc { this[it] - that[it] } } internal fun FloatArrayList.toNBuffer(): Buffer = toFloatArray().toNBuffer() diff --git a/korge/src/commonTest/kotlin/com/soywiz/korge/animate/AnimStateManagerTest.kt b/korge/src/commonTest/kotlin/com/soywiz/korge/animate/AnimStateManagerTest.kt index 349d0f043e..89f0b7b812 100644 --- a/korge/src/commonTest/kotlin/com/soywiz/korge/animate/AnimStateManagerTest.kt +++ b/korge/src/commonTest/kotlin/com/soywiz/korge/animate/AnimStateManagerTest.kt @@ -4,7 +4,6 @@ import com.soywiz.klock.* import com.soywiz.korge.tween.* import com.soywiz.korge.view.* import com.soywiz.korio.util.* -import com.soywiz.korma.geom.* import kotlin.test.* class AnimStateManagerTest { @@ -14,7 +13,7 @@ class AnimStateManagerTest { val view = DummyView() val state1 = AnimState(view::x[100], time = 0.5.seconds) view.animStateManager.set(state1) - fun log() { log += "${view.pos.niceStr} : ${view.alpha.niceStr(1)}" } + fun log() { log += "${view.ipos.niceStr} : ${view.alpha.niceStr(1)}" } log() view.updateSingleView(0.seconds) diff --git a/korge/src/commonTest/kotlin/com/soywiz/korge/animate/AnimatorTest.kt b/korge/src/commonTest/kotlin/com/soywiz/korge/animate/AnimatorTest.kt index 362f6b97c2..a65fb1a764 100644 --- a/korge/src/commonTest/kotlin/com/soywiz/korge/animate/AnimatorTest.kt +++ b/korge/src/commonTest/kotlin/com/soywiz/korge/animate/AnimatorTest.kt @@ -23,11 +23,11 @@ class AnimatorTest : ViewsForTesting() { animate(completeOnCancel = false) { moveTo(view, 100, 0) moveBy(view, y = +100.0) - block { log += "${view.pos}" } + block { log += "${view.ipos}" } moveBy(view, x = +10.0) moveTo(view, x = { view.x + 10 }) } - assertEquals("(120, 100)", view.pos.toString()) + assertEquals("(120, 100)", view.ipos.toString()) assertEquals("[(100, 100)]", log.toString()) } diff --git a/korge/src/commonTest/kotlin/com/soywiz/korge/animate/NewAnimatorTest.kt b/korge/src/commonTest/kotlin/com/soywiz/korge/animate/NewAnimatorTest.kt index c774e166d4..9ffb8b8119 100644 --- a/korge/src/commonTest/kotlin/com/soywiz/korge/animate/NewAnimatorTest.kt +++ b/korge/src/commonTest/kotlin/com/soywiz/korge/animate/NewAnimatorTest.kt @@ -4,7 +4,6 @@ import com.soywiz.klock.* import com.soywiz.korge.component.* import com.soywiz.korge.view.* import com.soywiz.korio.util.* -import com.soywiz.korma.geom.* import com.soywiz.korma.interpolation.* import kotlin.test.* @@ -18,7 +17,7 @@ class NewAnimatorTest { var _animator: Animator? = null fun logLine() { - lines += "${view.pos.niceStr} : ${_animator?.nodes?.size} : ${view.getComponentsOfType(UpdateComponent)?.size} : ${log.joinToString(",")}" + lines += "${view.ipos.niceStr} : ${_animator?.nodes?.size} : ${view.getComponentsOfType(UpdateComponent)?.size} : ${log.joinToString(",")}" } logLine() @@ -74,7 +73,7 @@ class NewAnimatorTest { var log = "" val lines = arrayListOf() fun logLine() { - lines += "${view.pos.niceStr}, ${view.alpha.niceStr(1)} : $log" + lines += "${view.ipos.niceStr}, ${view.alpha.niceStr(1)} : $log" } logLine() val animator = view.animator(defaultTime = 1.seconds, defaultEasing = Easing.LINEAR) { @@ -148,7 +147,7 @@ class NewAnimatorTest { } val lines = arrayListOf() fun logLine() { - lines += "${view.pos.niceStr}, ${view.alpha.niceStr(1)}" + lines += "${view.ipos.niceStr}, ${view.alpha.niceStr(1)}" } for (n in 0 until 12) { view.updateSingleView(0.1.seconds) @@ -235,7 +234,7 @@ class NewAnimatorTest { animator.onComplete.add { log += "complete" } val lines = arrayListOf() fun logLine() { - lines += "view1[${view1.pos.niceStr}, ${view1.alpha.niceStr(1)}], view2[${view2.pos.niceStr}, ${view2.alpha.niceStr(1)}], log=${log.joinToString("")}" + lines += "view1[${view1.ipos.niceStr}, ${view1.alpha.niceStr(1)}], view2[${view2.ipos.niceStr}, ${view2.alpha.niceStr(1)}], log=${log.joinToString("")}" } for (n in 0 until 24) { executorView.updateSingleView(0.25.seconds) diff --git a/korge/src/commonTest/kotlin/com/soywiz/korge/atlas/AtlasInfoTest.kt b/korge/src/commonTest/kotlin/com/soywiz/korge/atlas/AtlasInfoTest.kt index ed68dfc238..f5fb0279be 100644 --- a/korge/src/commonTest/kotlin/com/soywiz/korge/atlas/AtlasInfoTest.kt +++ b/korge/src/commonTest/kotlin/com/soywiz/korge/atlas/AtlasInfoTest.kt @@ -8,10 +8,8 @@ import com.soywiz.korim.bitmap.* import com.soywiz.korio.async.suspendTest import com.soywiz.korio.file.std.resourcesVfs import com.soywiz.korio.lang.assert -import com.soywiz.korio.lang.substr -import com.soywiz.korma.geom.Rectangle -import com.soywiz.korma.geom.RectangleInt -import com.soywiz.korma.geom.Size +import com.soywiz.korma.geom.MRectangle +import com.soywiz.korma.geom.MSize import kotlin.test.Test import kotlin.test.assertEquals @@ -25,13 +23,13 @@ class AtlasInfoTest { assertEquals("RGBA8888", atlas.format) assertEquals(124, atlas.frames.size) assertEquals(1.0, atlas.scale) - assertEquals(Size(1021, 1003), atlas.size.size) + assertEquals(MSize(1021, 1003), atlas.size.size) val firstFrame = atlas.frames.first() assertEquals("arms/forearm_jump_0.png", atlas.frames.map { it.name }.first()) - assertEquals(Rectangle(993, 319, 28, 41), firstFrame.frame.rect) - assertEquals(Size(55, 47), firstFrame.sourceSize.size) - assertEquals(Rectangle(8, 7, 28, 41), firstFrame.spriteSourceSize.rect) + assertEquals(MRectangle(993, 319, 28, 41), firstFrame.frame.rect) + assertEquals(MSize(55, 47), firstFrame.sourceSize.size) + assertEquals(MRectangle(8, 7, 28, 41), firstFrame.spriteSourceSize.rect) assertEquals(true, firstFrame.rotated) assertEquals(true, firstFrame.trimmed) } diff --git a/korge/src/commonTest/kotlin/com/soywiz/korge/component/list/ViewListTest.kt b/korge/src/commonTest/kotlin/com/soywiz/korge/component/list/ViewListTest.kt index 581bd72af9..6fd2324ce3 100644 --- a/korge/src/commonTest/kotlin/com/soywiz/korge/component/list/ViewListTest.kt +++ b/korge/src/commonTest/kotlin/com/soywiz/korge/component/list/ViewListTest.kt @@ -4,7 +4,7 @@ import com.soywiz.korge.tests.ViewsForTesting import com.soywiz.korge.view.SolidRect import com.soywiz.korge.view.xy import com.soywiz.korim.color.Colors -import com.soywiz.korma.geom.Rectangle +import com.soywiz.korma.geom.MRectangle import kotlin.test.Test import kotlin.test.assertEquals @@ -17,6 +17,6 @@ class ViewListTest : ViewsForTesting() { views.stage.addChild(item1) val itemList = ViewList(item0, item1, 3) assertEquals(3, itemList.length) - assertEquals(Rectangle(40, 0, 10, 10), itemList[2]?.globalBounds) + assertEquals(MRectangle(40, 0, 10, 10), itemList[2]?.globalBounds) } } diff --git a/korge/src/commonTest/kotlin/com/soywiz/korge/html/HtmlTest.kt b/korge/src/commonTest/kotlin/com/soywiz/korge/html/HtmlTest.kt index f2b92486f5..01da737999 100644 --- a/korge/src/commonTest/kotlin/com/soywiz/korge/html/HtmlTest.kt +++ b/korge/src/commonTest/kotlin/com/soywiz/korge/html/HtmlTest.kt @@ -3,7 +3,7 @@ package com.soywiz.korge.html import com.soywiz.korim.color.Colors import com.soywiz.korim.font.SystemFont import com.soywiz.korim.text.TextAlignment -import com.soywiz.korma.geom.Rectangle +import com.soywiz.korma.geom.MRectangle import kotlin.coroutines.EmptyCoroutineContext import kotlin.test.Test import kotlin.test.assertEquals @@ -16,9 +16,9 @@ class HtmlTest { Html.FontsCatalog(null, EmptyCoroutineContext) ) assertEquals("50%", doc.text) - doc.doPositioning(Html.MetricsProvider.Identity, Rectangle(0, 0, 100, 100)) - assertEquals(Rectangle(48.5, 0.0, 3.0, 1.0), doc.bounds) - assertEquals(listOf(Rectangle(48.5, 0.0, 3.0, 1.0)), doc.allSpans.map { it.bounds }) + doc.doPositioning(Html.MetricsProvider.Identity, MRectangle(0, 0, 100, 100)) + assertEquals(MRectangle(48.5, 0.0, 3.0, 1.0), doc.bounds) + assertEquals(listOf(MRectangle(48.5, 0.0, 3.0, 1.0)), doc.allSpans.map { it.bounds }) val format = doc.firstFormat assertEquals(SystemFont("Times New Roman", EmptyCoroutineContext), format.computedFace) assertEquals(33, format.computedSize) diff --git a/korge/src/commonTest/kotlin/com/soywiz/korge/input/MouseDragComponentTest.kt b/korge/src/commonTest/kotlin/com/soywiz/korge/input/MouseDragComponentTest.kt index 60e3ee7ef5..fd662b5ab2 100644 --- a/korge/src/commonTest/kotlin/com/soywiz/korge/input/MouseDragComponentTest.kt +++ b/korge/src/commonTest/kotlin/com/soywiz/korge/input/MouseDragComponentTest.kt @@ -4,8 +4,8 @@ import com.soywiz.korev.MouseButton import com.soywiz.korge.tests.ViewsForTesting import com.soywiz.korge.view.solidRect import com.soywiz.korim.color.Colors -import com.soywiz.korma.geom.Matrix -import com.soywiz.korma.geom.Point +import com.soywiz.korma.geom.MMatrix +import com.soywiz.korma.geom.MPoint import com.soywiz.korma.geom.SizeInt import kotlin.test.Test import kotlin.test.assertEquals @@ -17,7 +17,7 @@ class MouseDragComponentTest : ViewsForTesting( @Test fun testStageScale() = viewsTest { assertEquals(1.0, stage.scale) - assertEquals(Matrix(), stage.localMatrix) + assertEquals(MMatrix(), stage.localMatrix) assertEquals(1.0, views.devicePixelRatio) assertEquals(0.5, views.windowToGlobalScaleX) assertEquals(2.0, views.globalToWindowScaleX) @@ -30,13 +30,13 @@ class MouseDragComponentTest : ViewsForTesting( val deltaX = 20 val deltaY = 10 mouseMoveTo(10, 10) - assertEquals(Point(10, 10), views.globalMouseXY) - assertEquals(Point(20, 20), views.windowMouseXY) + assertEquals(MPoint(10, 10), views.globalMouseXY) + assertEquals(MPoint(20, 20), views.windowMouseXY) mouseDown(MouseButton.LEFT) mouseMoveTo(10 + deltaX, 10 + deltaY) - assertEquals(Point(30, 20), views.globalMouseXY) - assertEquals(Point(60, 40), views.windowMouseXY) + assertEquals(MPoint(30, 20), views.globalMouseXY) + assertEquals(MPoint(60, 40), views.windowMouseXY) mouseUp(MouseButton.LEFT) - assertEquals(Point(deltaX, deltaY), rect.pos) + assertEquals(MPoint(deltaX, deltaY), rect.ipos) } } diff --git a/korge/src/commonTest/kotlin/com/soywiz/korge/tween/TweenInterpolators.kt b/korge/src/commonTest/kotlin/com/soywiz/korge/tween/TweenInterpolators.kt index fb1eefb415..b7def7287c 100644 --- a/korge/src/commonTest/kotlin/com/soywiz/korge/tween/TweenInterpolators.kt +++ b/korge/src/commonTest/kotlin/com/soywiz/korge/tween/TweenInterpolators.kt @@ -2,8 +2,7 @@ package com.soywiz.korge.tween import com.soywiz.korge.view.DummyView import com.soywiz.korge.view.xy -import com.soywiz.korma.geom.Point -import com.soywiz.korma.geom.mutable +import com.soywiz.korma.geom.MPoint import com.soywiz.korma.geom.shape.buildVectorPath import com.soywiz.korma.geom.vector.line import kotlin.test.Test @@ -14,14 +13,14 @@ class TweenInterpolators { fun test() { val path = buildVectorPath { line(0, 0, 100, 100) } val view = DummyView().xy(30, 30) - val v2 = view::pos[path] - assertEquals(Point(30, 30), view.pos) + val v2 = view::ipos[path] + assertEquals(MPoint(30, 30), view.ipos) v2.init() v2.set(0.0) - assertEquals(Point(0, 0), view.pos) + assertEquals(MPoint(0, 0), view.ipos) v2.set(0.5) - assertEquals(Point(50, 50), view.pos.mutable.round()) + assertEquals(MPoint(50, 50), view.ipos.mutable.round()) v2.set(1.0) - assertEquals(Point(100, 100), view.pos.mutable.round()) + assertEquals(MPoint(100, 100), view.ipos.mutable.round()) } } diff --git a/korge/src/commonTest/kotlin/com/soywiz/korge/view/BitmapSliceViewTest.kt b/korge/src/commonTest/kotlin/com/soywiz/korge/view/BitmapSliceViewTest.kt index 4b806745d7..479fcacc14 100644 --- a/korge/src/commonTest/kotlin/com/soywiz/korge/view/BitmapSliceViewTest.kt +++ b/korge/src/commonTest/kotlin/com/soywiz/korge/view/BitmapSliceViewTest.kt @@ -1,11 +1,5 @@ package com.soywiz.korge.view -import com.soywiz.korim.bitmap.Bitmap32 -import com.soywiz.korim.bitmap.slice -import com.soywiz.korma.geom.Size -import kotlin.test.Test -import kotlin.test.assertEquals - class BitmapSliceViewTest { //@Test //fun test() { diff --git a/korge/src/commonTest/kotlin/com/soywiz/korge/view/CachedContainerTest.kt b/korge/src/commonTest/kotlin/com/soywiz/korge/view/CachedContainerTest.kt index 59407a34ff..54b0d6d455 100644 --- a/korge/src/commonTest/kotlin/com/soywiz/korge/view/CachedContainerTest.kt +++ b/korge/src/commonTest/kotlin/com/soywiz/korge/view/CachedContainerTest.kt @@ -37,17 +37,17 @@ class CachedContainerTest { @Test fun testMatrixOrder() { - val globalMatrix = Matrix().scale(2, 2).translate(50, 50) + val globalMatrix = MMatrix().scale(2, 2).translate(50, 50) val globalMatrixInv = globalMatrix.inverted() val renderScale = 2.0 - val lbounds = Point(10, 20) + val lbounds = MPoint(10, 20) - val mat1 = Matrix().also { + val mat1 = MMatrix().also { it.copyFrom(globalMatrixInv) it.translate(-lbounds.x, -lbounds.y) it.scale(renderScale) } - val mat2 = Matrix().also { + val mat2 = MMatrix().also { it.copyFrom(globalMatrix) it.pretranslate(lbounds.x, lbounds.y) it.prescale(1.0 / renderScale) diff --git a/korge/src/commonTest/kotlin/com/soywiz/korge/view/GraphicsTest.kt b/korge/src/commonTest/kotlin/com/soywiz/korge/view/GraphicsTest.kt index c469aa0a98..8ed5ad65e0 100644 --- a/korge/src/commonTest/kotlin/com/soywiz/korge/view/GraphicsTest.kt +++ b/korge/src/commonTest/kotlin/com/soywiz/korge/view/GraphicsTest.kt @@ -2,15 +2,14 @@ package com.soywiz.korge.view import com.soywiz.korag.log.AGLog import com.soywiz.korge.render.RenderContext -import com.soywiz.korim.bitmap.* import com.soywiz.korim.color.Colors import com.soywiz.korio.async.suspendTest import com.soywiz.korio.util.OS import com.soywiz.korio.util.niceStr import com.soywiz.korma.geom.Anchor -import com.soywiz.korma.geom.Point -import com.soywiz.korma.geom.Rectangle -import com.soywiz.korma.geom.Size +import com.soywiz.korma.geom.MPoint +import com.soywiz.korma.geom.MRectangle +import com.soywiz.korma.geom.MSize import com.soywiz.korma.geom.bezier.Bezier import com.soywiz.korma.geom.vector.StrokeInfo import com.soywiz.korma.geom.vector.circle @@ -33,7 +32,7 @@ class GraphicsTest { } } val bmp = g.bitmap.base.toBMP32() - assertEquals(Size(101, 101), bmp.size) + assertEquals(MSize(101, 101), bmp.size) //assertEquals("#ff0000ff", bmp[0, 0].hexString) //assertEquals("#ff0000ff", bmp[99, 99].hexString) assertEquals("#ff0000ff", bmp[1, 1].hexString) @@ -155,12 +154,12 @@ class GraphicsTest { @Test fun testGraphicsBoundsWithOnlyStrokes() { - val p0 = Point(109, 135) - val p1 = Point(25, 190) - val p2 = Point(210, 250) - val p3 = Point(234, 49) + val p0 = MPoint(109, 135) + val p1 = MPoint(25, 190) + val p2 = MPoint(210, 250) + val p3 = MPoint(234, 49) val g = CpuGraphics() - assertEquals(Rectangle(), g.getLocalBounds()) + assertEquals(MRectangle(), g.getLocalBounds()) g.updateShape { clear() stroke(Colors.DIMGREY, info = StrokeInfo(thickness = 1.0)) { @@ -185,7 +184,7 @@ class GraphicsTest { } } // assertEquals(Rectangle(25, 49, 209, 201), g.getLocalBounds()) // strokes = false - assertEquals(Rectangle(24.5, 47.0, 211.5, 203.5), g.getLocalBounds()) + assertEquals(MRectangle(24.5, 47.0, 211.5, 203.5), g.getLocalBounds()) } @Test @@ -234,7 +233,7 @@ class GraphicsTest { val posCircle = container.circle(25.0, fill = Colors.ORANGE) { anchor(Anchor.CENTER) - position(graphics.pos) + position(graphics.ipos) } val posCircle2 = container.circle(5.0, fill = Colors.RED) { diff --git a/korge/src/commonTest/kotlin/com/soywiz/korge/view/ShapeViewTest.kt b/korge/src/commonTest/kotlin/com/soywiz/korge/view/ShapeViewTest.kt index 7686f607ed..40c9f8efab 100644 --- a/korge/src/commonTest/kotlin/com/soywiz/korge/view/ShapeViewTest.kt +++ b/korge/src/commonTest/kotlin/com/soywiz/korge/view/ShapeViewTest.kt @@ -1,6 +1,6 @@ package com.soywiz.korge.view -import com.soywiz.korma.geom.Rectangle +import com.soywiz.korma.geom.MRectangle import com.soywiz.korma.geom.vector.line import kotlin.test.Test import kotlin.test.assertEquals @@ -16,9 +16,9 @@ class ShapeViewTest { line(256.0, 256.0, 400.0, 256.0) } view.boundsIncludeStrokes = false - assertEquals(Rectangle(256, 256, 144, 0), view.getLocalBounds(), message = "bounds without strokes $renderer") + assertEquals(MRectangle(256, 256, 144, 0), view.getLocalBounds(), message = "bounds without strokes $renderer") view.boundsIncludeStrokes = true - assertEquals(Rectangle(255.5, 255.5, 145.0, 1.0), view.getLocalBounds(), message = "bounds with strokes $renderer") + assertEquals(MRectangle(255.5, 255.5, 145.0, 1.0), view.getLocalBounds(), message = "bounds with strokes $renderer") } } } diff --git a/korge/src/commonTest/kotlin/com/soywiz/korge/view/StageTest.kt b/korge/src/commonTest/kotlin/com/soywiz/korge/view/StageTest.kt index e66e1f166f..e0119acceb 100644 --- a/korge/src/commonTest/kotlin/com/soywiz/korge/view/StageTest.kt +++ b/korge/src/commonTest/kotlin/com/soywiz/korge/view/StageTest.kt @@ -2,7 +2,7 @@ package com.soywiz.korge.view import com.soywiz.korge.input.mouse import com.soywiz.korge.tests.ViewsForTesting -import com.soywiz.korma.geom.Point +import com.soywiz.korma.geom.MPoint import kotlin.test.Test import kotlin.test.assertEquals @@ -12,7 +12,7 @@ class StageTest : ViewsForTesting() { views.input.setMouseGlobalXY(10.0, 20.0, down = false) stage.scale(0.5, 0.5) stage.mouse.currentPosGlobal - assertEquals(Point(20, 40), stage.mouseXY) - assertEquals(Point(20, 40), views.globalMouseXY) + assertEquals(MPoint(20, 40), stage.mouseXY) + assertEquals(MPoint(20, 40), views.globalMouseXY) } } diff --git a/korge/src/commonTest/kotlin/com/soywiz/korge/view/TextOldTest.kt b/korge/src/commonTest/kotlin/com/soywiz/korge/view/TextOldTest.kt index 3e16251503..97bf255355 100644 --- a/korge/src/commonTest/kotlin/com/soywiz/korge/view/TextOldTest.kt +++ b/korge/src/commonTest/kotlin/com/soywiz/korge/view/TextOldTest.kt @@ -3,9 +3,9 @@ package com.soywiz.korge.view import com.soywiz.korge.render.VertexInfo import com.soywiz.korge.render.testRenderContext import com.soywiz.korge.scene.debugBmpFontSync -import com.soywiz.korma.geom.Point -import com.soywiz.korma.geom.Rectangle -import com.soywiz.korma.geom.Size +import com.soywiz.korma.geom.MPoint +import com.soywiz.korma.geom.MRectangle +import com.soywiz.korma.geom.MSize import kotlin.test.Test import kotlin.test.assertEquals @@ -26,10 +26,10 @@ class TextOldTest { assertEquals( listOf( listOf( - Point(0, 0), - Point(32, 0), - Point(32, 32), - Point(0, 32) + MPoint(0, 0), + MPoint(32, 0), + MPoint(32, 32), + MPoint(0, 32) ) ), vertices.map { it.map { it.xy } } @@ -40,13 +40,13 @@ class TextOldTest { @Test fun testDebugFontSize() { assertEquals(8.0, debugBmpFontSync.fontSize) - assertEquals(Size(192, 192), debugBmpFontSync.baseBmp.size) + assertEquals(MSize(192, 192), debugBmpFontSync.baseBmp.size) } @Test fun testBounds() { val text = TextOld("1", textSize = 32.0) - assertEquals(Rectangle(0, 0, 28, 32), text.getLocalBoundsOptimizedAnchored()) + assertEquals(MRectangle(0, 0, 28, 32), text.getLocalBoundsOptimizedAnchored()) } @Test @@ -54,7 +54,7 @@ class TextOldTest { val text = TextOld("1", textSize = 32.0) assertEquals(text, text.hitTest(10, 5)) assertEquals(null, text.hitTest(30, 5)) - text.setTextBounds(Rectangle(0, 0, 32, 32)) + text.setTextBounds(MRectangle(0, 0, 32, 32)) assertEquals(text, text.hitTest(10, 5)) assertEquals(text, text.hitTest(30, 5)) assertEquals(null, text.hitTest(33, 5)) diff --git a/korge/src/commonTest/kotlin/com/soywiz/korge/view/ViewFixedSizeContainerTest.kt b/korge/src/commonTest/kotlin/com/soywiz/korge/view/ViewFixedSizeContainerTest.kt index db3db46210..fb7f0b9993 100644 --- a/korge/src/commonTest/kotlin/com/soywiz/korge/view/ViewFixedSizeContainerTest.kt +++ b/korge/src/commonTest/kotlin/com/soywiz/korge/view/ViewFixedSizeContainerTest.kt @@ -4,7 +4,7 @@ import com.soywiz.korag.* import com.soywiz.korag.log.AGBaseLog import com.soywiz.korge.tests.ViewsForTesting import com.soywiz.korim.color.Colors -import com.soywiz.korma.geom.Rectangle +import com.soywiz.korma.geom.MRectangle import com.soywiz.korma.geom.SizeInt import kotlin.test.Test import kotlin.test.assertEquals @@ -35,6 +35,6 @@ class ViewFixedSizeContainerTest : ViewsForTesting( stage.render(it) } - assertEquals(listOf(Rectangle(234, 105, 150, 150)), log) + assertEquals(listOf(MRectangle(234, 105, 150, 150)), log) } } diff --git a/korge/src/commonTest/kotlin/com/soywiz/korge/view/ViewTest.kt b/korge/src/commonTest/kotlin/com/soywiz/korge/view/ViewTest.kt index 759bd49df8..c89aa32a1d 100644 --- a/korge/src/commonTest/kotlin/com/soywiz/korge/view/ViewTest.kt +++ b/korge/src/commonTest/kotlin/com/soywiz/korge/view/ViewTest.kt @@ -2,7 +2,7 @@ package com.soywiz.korge.view import com.soywiz.korge.tests.ViewsForTesting import com.soywiz.korim.bitmap.Bitmap32 -import com.soywiz.korma.geom.Point +import com.soywiz.korma.geom.MPoint import com.soywiz.korma.geom.SizeInt import kotlin.test.Test import kotlin.test.assertEquals @@ -34,9 +34,9 @@ class ViewTest { rect = solidRect(100, 100).position(30, 30) } } - assertEquals("(30, 30), (90, 90)", "${rect.pos}, ${rect.getPositionRelativeTo(container)}") - rect.setPositionRelativeTo(container, Point(240, 240)) - assertEquals("(80, 80), (240, 240)", "${rect.pos}, ${rect.getPositionRelativeTo(container)}") + assertEquals("(30, 30), (90, 90)", "${rect.ipos}, ${rect.getPositionRelativeTo(container)}") + rect.setPositionRelativeTo(container, MPoint(240, 240)) + assertEquals("(80, 80), (240, 240)", "${rect.ipos}, ${rect.getPositionRelativeTo(container)}") } @Test diff --git a/korge/src/commonTest/kotlin/com/soywiz/korge/view/Views2Test.kt b/korge/src/commonTest/kotlin/com/soywiz/korge/view/Views2Test.kt index d1b2b9d01d..8aa8379cf4 100644 --- a/korge/src/commonTest/kotlin/com/soywiz/korge/view/Views2Test.kt +++ b/korge/src/commonTest/kotlin/com/soywiz/korge/view/Views2Test.kt @@ -5,8 +5,8 @@ import com.soywiz.korge.tests.ViewsForTesting import com.soywiz.korim.bitmap.Bitmap32 import com.soywiz.korim.color.Colors import com.soywiz.korma.geom.Anchor -import com.soywiz.korma.geom.Point -import com.soywiz.korma.geom.Rectangle +import com.soywiz.korma.geom.MPoint +import com.soywiz.korma.geom.MRectangle import com.soywiz.korma.geom.ScaleMode import com.soywiz.korma.geom.SizeInt import kotlin.math.absoluteValue @@ -51,7 +51,7 @@ class Views2Test : ViewsForTesting( centerOnStage() } logger.info { str() } - assertEquals(Point((virtualSize.width - RECT_WIDTH) / 2, (virtualSize.height - RECT_HEIGHT) / 2), rect.pos) + assertEquals(MPoint((virtualSize.width - RECT_WIDTH) / 2, (virtualSize.height - RECT_HEIGHT) / 2), rect.ipos) } @Test @@ -68,11 +68,11 @@ class Views2Test : ViewsForTesting( centerOn(rect1) } assertEquals( - Point( + MPoint( CONTAINER_X + (CONTAINER_WIDTH - RECT_WIDTH) / 2, CONTAINER_Y + (CONTAINER_HEIGHT - RECT_HEIGHT) / 2 ), - rect2.pos + rect2.ipos ) } @@ -101,18 +101,18 @@ class Views2Test : ViewsForTesting( assertEquals(6.66666, rect1.scaleY, 0.001) assertEquals( - Point( + MPoint( CONTAINER_X + (CONTAINER_WIDTH - RECT_WIDTH) / 2, CONTAINER_Y + (CONTAINER_HEIGHT - RECT_HEIGHT) / 2 ), - rect2.pos + rect2.ipos ) } @Test fun testImageLocalBounds() = viewsTest { val image = image(Bitmap32(10, 10, Colors.TRANSPARENT_BLACK)).size(100, 100).xy(50, 50) - assertEquals(Rectangle(0, 0, 10, 10).toStringBounds(), image.getLocalBoundsOptimizedAnchored().toStringBounds()) - assertEquals(Rectangle(50, 50, 100, 100).toStringBounds(), image.getBounds(image.parent!!).toStringBounds()) + assertEquals(MRectangle(0, 0, 10, 10).toStringBounds(), image.getLocalBoundsOptimizedAnchored().toStringBounds()) + assertEquals(MRectangle(50, 50, 100, 100).toStringBounds(), image.getBounds(image.parent!!).toStringBounds()) } } diff --git a/korge/src/commonTest/kotlin/com/soywiz/korge/view/ViewsTest.kt b/korge/src/commonTest/kotlin/com/soywiz/korge/view/ViewsTest.kt index 6850231782..3e803ef0e4 100644 --- a/korge/src/commonTest/kotlin/com/soywiz/korge/view/ViewsTest.kt +++ b/korge/src/commonTest/kotlin/com/soywiz/korge/view/ViewsTest.kt @@ -16,7 +16,7 @@ import com.soywiz.korim.bitmap.Bitmap32 import com.soywiz.korim.color.Colors import com.soywiz.korio.lang.portableSimpleName import com.soywiz.korio.util.niceStr -import com.soywiz.korma.geom.Rectangle +import com.soywiz.korma.geom.MRectangle import com.soywiz.korma.geom.vector.circle import com.soywiz.korma.geom.vector.rect import kotlin.test.Test @@ -75,14 +75,14 @@ class ViewsTest : ViewsForTesting() { fun testBounds() = viewsTest { val image = Image(tex).position(100, 100) views.stage += image - assertEquals(Rectangle(100, 100, 10, 10), image.getGlobalBounds()) + assertEquals(MRectangle(100, 100, 10, 10), image.getGlobalBounds()) } @Test fun testBounds2() = viewsTest { val image = Image(tex).position(-100, 100) views.stage += image - assertEquals(Rectangle(-100, 100, 10, 10), image.getGlobalBounds()) + assertEquals(MRectangle(-100, 100, 10, 10), image.getGlobalBounds()) } @Test @@ -220,8 +220,8 @@ class ViewsTest : ViewsForTesting() { fill(Colors.RED) { circle(0.0,0.0,100.0) } } container.addChild(contents) - assertEquals(Rectangle(-100, -100, 200, 200), contents.getBounds(container), "bounds1") // (x=-100, y=-100, w=200, h=200) - assertEquals(Rectangle(0, 0, 200, 200), contents.getBounds(this), "bounds2") // (x=0, y=0, w=200, h=200) + assertEquals(MRectangle(-100, -100, 200, 200), contents.getBounds(container), "bounds1") // (x=-100, y=-100, w=200, h=200) + assertEquals(MRectangle(0, 0, 200, 200), contents.getBounds(this), "bounds2") // (x=0, y=0, w=200, h=200) } @Test @@ -231,43 +231,43 @@ class ViewsTest : ViewsForTesting() { assertEquals(false, image.isVisibleToUser()) } - private fun assertEquals(a: Rectangle, b: Rectangle) = assertEquals(a.toString(), b.toString()) + private fun assertEquals(a: MRectangle, b: MRectangle) = assertEquals(a.toString(), b.toString()) @Test fun testRect() = viewsTest { - assertEquals(Rectangle(0, 0, 1280, 720), this.stage.globalBounds, "rect0") + assertEquals(MRectangle(0, 0, 1280, 720), this.stage.globalBounds, "rect0") RectBase().also { addChild(it) }.also { rect1 -> - assertEquals(Rectangle(0, 0, 0, 0), rect1.globalBounds, "rect1") + assertEquals(MRectangle(0, 0, 0, 0), rect1.globalBounds, "rect1") } Image(Bitmap32(16, 16, Colors.RED)).also { addChild(it) }.also { rect2 -> - assertEquals(Rectangle(0, 0, 16, 16), rect2.globalBounds, "rect2") + assertEquals(MRectangle(0, 0, 16, 16), rect2.globalBounds, "rect2") } SolidRect(32, 32, Colors.RED).also { addChild(it) }.also { rect3 -> - assertEquals(Rectangle(0, 0, 32, 32), rect3.globalBounds, "rect3") + assertEquals(MRectangle(0, 0, 32, 32), rect3.globalBounds, "rect3") } RoundRect(32.0, 24.0, 5.0, 5.0, Colors.RED).also { addChild(it) }.also { rect3 -> - assertEquals(Rectangle(0, 0, 32, 24), rect3.globalBounds, "rect4") + assertEquals(MRectangle(0, 0, 32, 24), rect3.globalBounds, "rect4") } Circle(32.0, Colors.RED).also { addChild(it) }.also { rect3 -> - assertEquals(Rectangle(0, 0, 64, 64).toString(), rect3.globalBounds.toString(), "rect5") + assertEquals(MRectangle(0, 0, 64, 64).toString(), rect3.globalBounds.toString(), "rect5") } CpuGraphics().also { addChild(it) }.updateShape { fill(Colors.RED) { rect(0, 0, 100, 100) } }.also { rect4 -> - assertEquals(Rectangle(0, 0, 100, 100), rect4.globalBounds, "rect6") + assertEquals(MRectangle(0, 0, 100, 100), rect4.globalBounds, "rect6") rect4.render(views.renderContext) - assertEquals(Rectangle(0, 0, 100, 100), rect4.globalBounds, "rect7") + assertEquals(MRectangle(0, 0, 100, 100), rect4.globalBounds, "rect7") } } @Test fun testRoundRect() = viewsTest { RoundRect(32.0, 24.0, 5.0, 5.0, Colors.RED).also { addChild(it) }.also { rect3 -> - assertEquals(Rectangle(0, 0, 32, 24), rect3.getLocalBounds(), message = "local") - assertEquals(Rectangle(0, 0, 32, 24), rect3.globalBounds, message = "global") + assertEquals(MRectangle(0, 0, 32, 24), rect3.getLocalBounds(), message = "local") + assertEquals(MRectangle(0, 0, 32, 24), rect3.globalBounds, message = "global") } } diff --git a/korge/src/commonTest/kotlin/com/soywiz/korge/view/filter/ColorMatrixFilterTest.kt b/korge/src/commonTest/kotlin/com/soywiz/korge/view/filter/ColorMatrixFilterTest.kt index 2a1d56a225..0fea9d8433 100644 --- a/korge/src/commonTest/kotlin/com/soywiz/korge/view/filter/ColorMatrixFilterTest.kt +++ b/korge/src/commonTest/kotlin/com/soywiz/korge/view/filter/ColorMatrixFilterTest.kt @@ -1,6 +1,6 @@ package com.soywiz.korge.view.filter -import com.soywiz.korma.geom.Vector3D +import com.soywiz.korma.geom.MVector4 import kotlin.test.Test import kotlin.test.assertEquals @@ -10,8 +10,8 @@ class ColorMatrixFilterTest { val grayFilter = ColorMatrixFilter(ColorMatrixFilter.GRAYSCALE_MATRIX) assertEquals( - Vector3D(0.57f, 0.57f, 0.57f, 1f), - grayFilter.colorMatrix.transform(Vector3D(.75f, .5f, .25f, 1f)) + MVector4(0.57f, 0.57f, 0.57f, 1f), + grayFilter.colorMatrix.transform(MVector4(.75f, .5f, .25f, 1f)) ) } } diff --git a/korge/src/commonTest/kotlin/com/soywiz/korge/view/filter/ComposedFilterTest.kt b/korge/src/commonTest/kotlin/com/soywiz/korge/view/filter/ComposedFilterTest.kt index 4fc0658f0f..18becfd37f 100644 --- a/korge/src/commonTest/kotlin/com/soywiz/korge/view/filter/ComposedFilterTest.kt +++ b/korge/src/commonTest/kotlin/com/soywiz/korge/view/filter/ComposedFilterTest.kt @@ -4,7 +4,7 @@ import com.soywiz.korag.log.AGLog import com.soywiz.korge.render.RenderContext import com.soywiz.korge.view.View import com.soywiz.korio.async.suspendTest -import com.soywiz.korma.geom.Rectangle +import com.soywiz.korma.geom.MRectangle import kotlin.test.Test import kotlin.test.assertEquals @@ -19,7 +19,7 @@ class ComposedFilterTest { log += "image.frameBuffers=${ctx.frameBuffers.totalItemsInUse}" } - override fun getLocalBoundsInternal(out: Rectangle) { + override fun getLocalBoundsInternal(out: MRectangle) { out.setTo(0, 0, 10, 10) } } diff --git a/korge/src/commonTest/kotlin/com/soywiz/korge/view/tiles/TileMapTest.kt b/korge/src/commonTest/kotlin/com/soywiz/korge/view/tiles/TileMapTest.kt index abce424753..1fdb790a3d 100644 --- a/korge/src/commonTest/kotlin/com/soywiz/korge/view/tiles/TileMapTest.kt +++ b/korge/src/commonTest/kotlin/com/soywiz/korge/view/tiles/TileMapTest.kt @@ -31,10 +31,10 @@ class TileMapTest { 2 to TileSetTileInfo(0, Bitmap32(16, 16, premultiplied = true).slice()), 3 to TileSetTileInfo(0, Bitmap32(16, 16, premultiplied = true).slice()), ), collisionsMap = intMapOf( - 0 to com.soywiz.korim.tiles.TileShapeInfoImpl(HitTestDirectionFlags.NONE, Shape2d.Rectangle(0, 0, 16, 16), Matrix()), - 1 to com.soywiz.korim.tiles.TileShapeInfoImpl(HitTestDirectionFlags.NONE, Shape2d.Empty, Matrix()), - 2 to com.soywiz.korim.tiles.TileShapeInfoImpl(HitTestDirectionFlags.ALL, Shape2d.Empty, Matrix()), - 3 to com.soywiz.korim.tiles.TileShapeInfoImpl(HitTestDirectionFlags.ALL, Shape2d.Rectangle(0, 0, 16, 16), Matrix()), + 0 to com.soywiz.korim.tiles.TileShapeInfoImpl(HitTestDirectionFlags.NONE, Shape2d.Rectangle(0, 0, 16, 16), MMatrix()), + 1 to com.soywiz.korim.tiles.TileShapeInfoImpl(HitTestDirectionFlags.NONE, Shape2d.Empty, MMatrix()), + 2 to com.soywiz.korim.tiles.TileShapeInfoImpl(HitTestDirectionFlags.ALL, Shape2d.Empty, MMatrix()), + 3 to com.soywiz.korim.tiles.TileShapeInfoImpl(HitTestDirectionFlags.ALL, Shape2d.Rectangle(0, 0, 16, 16), MMatrix()), )) val map = TileMap(SparseChunkedStackedIntArray2(StackedIntArray2(IntArray2(2, 2, intArrayOf(0, 1, 2, 3)))), tileSet) assertEquals(false, map.pixelHitTest(5, 5, HitTestDirection.DOWN)) diff --git a/korge/src/commonTest/kotlin/com/soywiz/korge3d/Matrix3DTest.kt b/korge/src/commonTest/kotlin/com/soywiz/korge3d/Matrix3DTest.kt index 33f81515ba..c86d5c9d11 100644 --- a/korge/src/commonTest/kotlin/com/soywiz/korge3d/Matrix3DTest.kt +++ b/korge/src/commonTest/kotlin/com/soywiz/korge3d/Matrix3DTest.kt @@ -1,13 +1,13 @@ package com.soywiz.korge3d -import com.soywiz.korma.geom.EulerRotation -import com.soywiz.korma.geom.Matrix -import com.soywiz.korma.geom.Matrix3D -import com.soywiz.korma.geom.Point +import com.soywiz.korma.geom.MEulerRotation +import com.soywiz.korma.geom.MMatrix +import com.soywiz.korma.geom.MMatrix3D +import com.soywiz.korma.geom.MPoint import com.soywiz.korma.geom.Position3D -import com.soywiz.korma.geom.Quaternion +import com.soywiz.korma.geom.MQuaternion import com.soywiz.korma.geom.Scale3D -import com.soywiz.korma.geom.Vector3D +import com.soywiz.korma.geom.MVector4 import com.soywiz.korma.geom.degrees import com.soywiz.korma.geom.fromRows import com.soywiz.korma.geom.getTRS @@ -24,7 +24,7 @@ import kotlin.test.assertEquals import kotlin.test.assertTrue class Matrix3DTest { - val transMat = Matrix3D.fromRows( + val transMat = MMatrix3D.fromRows( 1f, 0f, 0f, 1f, 0f, 1f, 0f, 2f, 0f, 0f, 1f, 3f, @@ -34,18 +34,18 @@ class Matrix3DTest { @Test fun testSetTRS() { assertEquals( - Matrix3D(), - Matrix3D().setTRS( + MMatrix3D(), + MMatrix3D().setTRS( Position3D(0, 0, 0), - Quaternion(), + MQuaternion(), Scale3D(1, 1, 1) ) ) assertEquals( transMat, - Matrix3D().setTRS( + MMatrix3D().setTRS( Position3D(1, 2, 3), - Quaternion(), + MQuaternion(), Scale3D(1, 1, 1) ) ) @@ -54,7 +54,7 @@ class Matrix3DTest { @Test fun testGetTRS() { val pos = Position3D() - val quat = Quaternion() + val quat = MQuaternion() val scale = Scale3D() transMat.getTRS(pos, quat, scale) @@ -63,13 +63,13 @@ class Matrix3DTest { @Test fun testSetGetTRS() { - val mat = Matrix3D() + val mat = MMatrix3D() val opos = Position3D(1, 2, 3) - val oquat = Quaternion().setEuler(15.degrees, 30.degrees, 60.degrees) + val oquat = MQuaternion().setEuler(15.degrees, 30.degrees, 60.degrees) val oscale = Scale3D(1, 2, 3) val pos = Position3D().copyFrom(opos) - val quat = Quaternion().copyFrom(oquat) + val quat = MQuaternion().copyFrom(oquat) val scale = Scale3D().copyFrom(oscale) mat.setTRS(pos, quat, scale) @@ -82,26 +82,26 @@ class Matrix3DTest { @Test fun testQuat() { - assertEquals(Quaternion(0.7, 0.0, 0.0, 0.7).round(1), Quaternion().setEuler(90.degrees, 0.degrees, 0.degrees).round(1)) - assertEquals(Quaternion(0.0, 0.7, 0.0, 0.7).round(1), Quaternion().setEuler(0.degrees, 90.degrees, 0.degrees).round(1)) - assertEquals(Quaternion(0.0, 0.0, 0.7, 0.7).round(1), Quaternion().setEuler(0.degrees, 0.degrees, 90.degrees).round(1)) + assertEquals(MQuaternion(0.7, 0.0, 0.0, 0.7).round(1), MQuaternion().setEuler(90.degrees, 0.degrees, 0.degrees).round(1)) + assertEquals(MQuaternion(0.0, 0.7, 0.0, 0.7).round(1), MQuaternion().setEuler(0.degrees, 90.degrees, 0.degrees).round(1)) + assertEquals(MQuaternion(0.0, 0.0, 0.7, 0.7).round(1), MQuaternion().setEuler(0.degrees, 0.degrees, 90.degrees).round(1)) - assertEquals(EulerRotation(90.degrees, 0.degrees, 0.degrees), EulerRotation().setQuaternion(Quaternion().setEuler(90.degrees, 0.degrees, 0.degrees)), 0.1) - assertEquals(EulerRotation(0.degrees, 90.degrees, 0.degrees), EulerRotation().setQuaternion(Quaternion().setEuler(0.degrees, 90.degrees, 0.degrees)), 0.1) - assertEquals(EulerRotation(0.degrees, 0.degrees, 90.degrees), EulerRotation().setQuaternion(Quaternion().setEuler(0.degrees, 0.degrees, 90.degrees)), 0.1) + assertEquals(MEulerRotation(90.degrees, 0.degrees, 0.degrees), MEulerRotation().setQuaternion(MQuaternion().setEuler(90.degrees, 0.degrees, 0.degrees)), 0.1) + assertEquals(MEulerRotation(0.degrees, 90.degrees, 0.degrees), MEulerRotation().setQuaternion(MQuaternion().setEuler(0.degrees, 90.degrees, 0.degrees)), 0.1) + assertEquals(MEulerRotation(0.degrees, 0.degrees, 90.degrees), MEulerRotation().setQuaternion(MQuaternion().setEuler(0.degrees, 0.degrees, 90.degrees)), 0.1) } @Test fun testInvert() { - val mat = Matrix3D().setTRS(Position3D(1, 2, 3), Quaternion().setEuler(15.degrees, 30.degrees, 60.degrees), Scale3D(1, 2, 3)) - val inv = Matrix3D().invert(mat) + val mat = MMatrix3D().setTRS(Position3D(1, 2, 3), MQuaternion().setEuler(15.degrees, 30.degrees, 60.degrees), Scale3D(1, 2, 3)) + val inv = MMatrix3D().invert(mat) assertEquals( - Matrix3D().round(2).toString(), + MMatrix3D().round(2).toString(), (mat * inv).round(2).toString() ) } - fun assertEquals(a: EulerRotation, b: EulerRotation, delta: Double = 0.01) { + fun assertEquals(a: MEulerRotation, b: MEulerRotation, delta: Double = 0.01) { assertTrue("$a\n$b\na!=b // delta=$delta") { abs(a.x.degrees - b.x.degrees) <= delta && abs(a.y.degrees - b.y.degrees) <= delta && @@ -109,7 +109,7 @@ class Matrix3DTest { } } - fun assertEquals(a: Quaternion, b: Quaternion, delta: Double = 0.01) { + fun assertEquals(a: MQuaternion, b: MQuaternion, delta: Double = 0.01) { assertTrue("$a\n$b\na!=b // delta=$delta") { abs(a.x - b.x) <= delta && abs(a.y - b.y) <= delta && @@ -126,18 +126,18 @@ class Matrix3DTest { assertTrue("$a != $b // delta=$delta") { abs(a - b) <= delta } } - fun Vector3D.round(digits: Int = 0) = setTo(round(x, digits), round(y, digits), round(z, digits), round(w, digits)) - fun Quaternion.round(digits: Int = 0) = setTo(round(x, digits), round(y, digits), round(z, digits), round(w, digits)) - fun Matrix3D.round(digits: Int = 0) = setToMap { round(it, digits) } + fun MVector4.round(digits: Int = 0) = setTo(round(x, digits), round(y, digits), round(z, digits), round(w, digits)) + fun MQuaternion.round(digits: Int = 0) = setTo(round(x, digits), round(y, digits), round(z, digits), round(w, digits)) + fun MMatrix3D.round(digits: Int = 0) = setToMap { round(it, digits) } fun round(x: Float, digits: Int) = (round(x * 10.0.pow(digits)) / 10.0.pow(digits)).toFloat() fun round(x: Double, digits: Int) = round(x * 10.0.pow(digits)) / 10.0.pow(digits) @Test fun testConvert() { - val mat = Matrix().translate(100, 20).scale(2, 2) - assertEquals(Point(240, 60), mat.transform(Point(20, 10))) + val mat = MMatrix().translate(100, 20).scale(2, 2) + assertEquals(MPoint(240, 60), mat.transform(MPoint(20, 10))) val m3d = mat.toMatrix3D() - assertEquals(Vector3D(240, 60, 0, 1), m3d.transform(Vector3D(20, 10, 0, 1))) + assertEquals(MVector4(240, 60, 0, 1), m3d.transform(MVector4(20, 10, 0, 1))) } } diff --git a/korge/src/commonTest/kotlin/com/soywiz/korge3d/MeshTest.kt b/korge/src/commonTest/kotlin/com/soywiz/korge3d/MeshTest.kt index 4dad4b8a4e..3cc32b844f 100644 --- a/korge/src/commonTest/kotlin/com/soywiz/korge3d/MeshTest.kt +++ b/korge/src/commonTest/kotlin/com/soywiz/korge3d/MeshTest.kt @@ -17,6 +17,6 @@ class MeshTest { @Test fun testEmpty() { - assertEquals(Unit, Mesh().getLocalBoundsInternal(Rectangle()), "Doesn't throw with mutability exception") + assertEquals(Unit, Mesh().getLocalBoundsInternal(MRectangle()), "Doesn't throw with mutability exception") } } diff --git a/korge/src/jvmMain/kotlin/com/soywiz/korge/awt/UiEditProperties.kt b/korge/src/jvmMain/kotlin/com/soywiz/korge/awt/UiEditProperties.kt index 00fd784f98..cddbe713fd 100644 --- a/korge/src/jvmMain/kotlin/com/soywiz/korge/awt/UiEditProperties.kt +++ b/korge/src/jvmMain/kotlin/com/soywiz/korge/awt/UiEditProperties.kt @@ -185,9 +185,9 @@ internal class UiEditProperties(app: UiApplication, view: View?, val views: View UiFourItemEditableValue(app, vv[0], vv[1], vv[2], vv[3]) } - type.isSubtypeOf(Margin::class.starProjectedType) -> { + type.isSubtypeOf(IMargin::class.starProjectedType) -> { @Suppress("UNCHECKED_CAST") - prop as KMutableProperty1 + prop as KMutableProperty1 val vv = listOf( ObservableProperty("a", { prop.set(instance, prop.get(instance).duplicate(top = it)) }, { prop.get(instance).top }), ObservableProperty("b", { prop.set(instance, prop.get(instance).duplicate(right = it)) }, { prop.get(instance).right }), diff --git a/korge/src/jvmTest/kotlin/com/soywiz/korge/view/ReferenceGraphicsTest.kt b/korge/src/jvmTest/kotlin/com/soywiz/korge/view/ReferenceGraphicsTest.kt index 47f477e20f..b66115ac33 100644 --- a/korge/src/jvmTest/kotlin/com/soywiz/korge/view/ReferenceGraphicsTest.kt +++ b/korge/src/jvmTest/kotlin/com/soywiz/korge/view/ReferenceGraphicsTest.kt @@ -104,7 +104,7 @@ class ReferenceGraphicsTest { globalAlpha = 0.75 fillStyle = BitmapPaint( korgeBitmap, - Matrix().translate(50, 50).scale(0.125), + MMatrix().translate(50, 50).scale(0.125), cycleX = CycleMethod.REPEAT, cycleY = CycleMethod.REPEAT ) @@ -115,7 +115,7 @@ class ReferenceGraphicsTest { globalAlpha = 0.9 fillStyle = //createLinearGradient(150.0, 0.0, 200.0, 50.0) - createLinearGradient(0.0, 0.0, 100.0, 100.0, transform = Matrix().scale(0.5).pretranslate(300, 0)) + createLinearGradient(0.0, 0.0, 100.0, 100.0, transform = MMatrix().scale(0.5).pretranslate(300, 0)) //.addColorStop(0.0, Colors.BLACK).addColorStop(1.0, Colors.WHITE) .addColorStop(0.0, Colors.RED).addColorStop(0.5, Colors.GREEN).addColorStop(1.0, Colors.BLUE) clip({ diff --git a/korge/src/jvmTest/kotlin/com/soywiz/korge/view/SDFViewTest.kt b/korge/src/jvmTest/kotlin/com/soywiz/korge/view/SDFViewTest.kt index f984e66541..5e657076e6 100644 --- a/korge/src/jvmTest/kotlin/com/soywiz/korge/view/SDFViewTest.kt +++ b/korge/src/jvmTest/kotlin/com/soywiz/korge/view/SDFViewTest.kt @@ -2,7 +2,6 @@ package com.soywiz.korge.view import com.soywiz.korag.shader.* import com.soywiz.korge.render.* -import com.soywiz.korge.scene.* import com.soywiz.korge.testing.* import com.soywiz.korim.color.* import com.soywiz.korma.geom.* @@ -27,7 +26,7 @@ class SDFViewTest { open class CircleSDFView(width: Double = 100.0, height: Double = 100.0, var time: Double = 0.0) : ShadedView(PROGRAM, width, height) { var radius = 0.49 var feather = 0.005 - var center = Point(0.5, 0.5) + var center = MPoint(0.5, 0.5) override fun renderInternal(ctx: RenderContext) { this.programUniforms[u_Center] = center diff --git a/korge/src/jvmTest/kotlin/com/soywiz/korge/view/ViewsJvmTest.kt b/korge/src/jvmTest/kotlin/com/soywiz/korge/view/ViewsJvmTest.kt index 2aaaeffff8..3c9634d455 100644 --- a/korge/src/jvmTest/kotlin/com/soywiz/korge/view/ViewsJvmTest.kt +++ b/korge/src/jvmTest/kotlin/com/soywiz/korge/view/ViewsJvmTest.kt @@ -34,13 +34,13 @@ class ViewsJvmTest : ViewsForTesting(log = true) { @Test fun textGetBounds1() = viewsTest { val font = views.debugBmpFont - assertEquals(Rectangle(0, 0, 77, 8), TextOld("Hello World", font = font, textSize = 8.0).globalBounds) + assertEquals(MRectangle(0, 0, 77, 8), TextOld("Hello World", font = font, textSize = 8.0).globalBounds) } @Test fun textGetBounds2() = viewsTest { val font = views.debugBmpFont - assertEquals(Rectangle(0, 0, 154, 16), TextOld("Hello World", font = font, textSize = 16.0).globalBounds) + assertEquals(MRectangle(0, 0, 154, 16), TextOld("Hello World", font = font, textSize = 16.0).globalBounds) } @Test @@ -86,7 +86,7 @@ class ViewsJvmTest : ViewsForTesting(log = true) { drawBorder = true ) //textResult.bmp.showImageAndWait() - assertEquals(Size(453, 121), textResult.bmp.size) + assertEquals(MSize(453, 121), textResult.bmp.size) //assertEquals(Size(450, 240), textResult.bmp.size) } } @@ -96,6 +96,6 @@ class ViewsJvmTest : ViewsForTesting(log = true) { val bitmap = runBlockingNoJs { resourcesVfs["texture.png"].readBitmap() } - assertEquals(Size(64, 64), bitmap.size) + assertEquals(MSize(64, 64), bitmap.size) } } diff --git a/korge/src/nativeTest/kotlin/com/soywiz/korge/KorgeMultithreadedTest.kt b/korge/src/nativeTest/kotlin/com/soywiz/korge/KorgeMultithreadedTest.kt index 1fabf09197..8bc67f4c0e 100644 --- a/korge/src/nativeTest/kotlin/com/soywiz/korge/KorgeMultithreadedTest.kt +++ b/korge/src/nativeTest/kotlin/com/soywiz/korge/KorgeMultithreadedTest.kt @@ -85,7 +85,7 @@ class KorgeMultithreadedTest { path.getCurvesList() val curves = path.getCurves() - assertEquals(Unit, Mesh().getLocalBoundsInternal(Rectangle()), "Doesn't throw with mutability exception") + assertEquals(Unit, Mesh().getLocalBoundsInternal(MRectangle()), "Doesn't throw with mutability exception") log += "rect.filterScale=${rect.filterScale}" log += "rect.mask=${rect.mask != null}" diff --git a/korgw/src/androidMain/kotlin/com/soywiz/korgw/KorgwSurfaceView.kt b/korgw/src/androidMain/kotlin/com/soywiz/korgw/KorgwSurfaceView.kt index a596219599..2a2d6205fc 100644 --- a/korgw/src/androidMain/kotlin/com/soywiz/korgw/KorgwSurfaceView.kt +++ b/korgw/src/androidMain/kotlin/com/soywiz/korgw/KorgwSurfaceView.kt @@ -16,7 +16,6 @@ import android.view.WindowManager import com.soywiz.kds.IntMap import com.soywiz.kds.buildIntArray import com.soywiz.kds.lock.NonRecursiveLock -import com.soywiz.kds.toIntArrayList import com.soywiz.kds.toMap import com.soywiz.klock.PerformanceCounter import com.soywiz.klock.TimeSpan @@ -30,8 +29,7 @@ import com.soywiz.korev.StandardGamepadMapping import com.soywiz.korev.Touch import com.soywiz.korev.TouchEvent import com.soywiz.korio.async.Signal -import com.soywiz.korma.geom.Point -import java.util.* +import com.soywiz.korma.geom.MPoint import javax.microedition.khronos.egl.EGL10 import javax.microedition.khronos.egl.EGLConfig import javax.microedition.khronos.egl.EGLDisplay @@ -157,8 +155,8 @@ open class KorgwSurfaceView constructor( } } gameWindow.dispatchGamepadUpdateStart() - val l = Point() - val r = Point() + val l = MPoint() + val r = MPoint() for ((index, gamepad) in gamepads.withIndex()) { val info = getGamepadInfo(gamepad.id) if (!info.connected) { diff --git a/korgw/src/commonMain/kotlin/com/soywiz/kgl/KmlGlExt.kt b/korgw/src/commonMain/kotlin/com/soywiz/kgl/KmlGlExt.kt index 0ac7c74a02..cffbf9d7df 100644 --- a/korgw/src/commonMain/kotlin/com/soywiz/kgl/KmlGlExt.kt +++ b/korgw/src/commonMain/kotlin/com/soywiz/kgl/KmlGlExt.kt @@ -2,7 +2,7 @@ package com.soywiz.kgl import com.soywiz.klogger.Console import com.soywiz.kmem.* -import com.soywiz.korma.geom.Rectangle +import com.soywiz.korma.geom.MRectangle import com.soywiz.krypto.encoding.hex import kotlin.native.concurrent.ThreadLocal @@ -38,7 +38,7 @@ fun KmlGl.getBooleanv(pname: Int): Boolean = tempByte1Buffer { getBooleanv(pname fun KmlGl.getFloatv(pname: Int): Float = tempFloat1Buffer { getFloatv(pname, it) } fun KmlGl.getIntegerv(pname: Int): Int = tempInt1Buffer { getIntegerv(pname, it) } fun KmlGl.getVertexAttribiv(index: Int, pname: Int): Int = tempInt1Buffer { getVertexAttribiv(index, pname, it) } -fun KmlGl.getRectanglev(pname: Int, out: Rectangle = Rectangle()): Rectangle = tempNBuffer4.let { +fun KmlGl.getRectanglev(pname: Int, out: MRectangle = MRectangle()): MRectangle = tempNBuffer4.let { it.setFloat32(0, 0f) it.setFloat32(1, 0f) it.setFloat32(2, 0f) diff --git a/korgw/src/commonMain/kotlin/com/soywiz/korag/AGState.kt b/korgw/src/commonMain/kotlin/com/soywiz/korag/AGState.kt index 22313b5cdf..45308da658 100644 --- a/korgw/src/commonMain/kotlin/com/soywiz/korag/AGState.kt +++ b/korgw/src/commonMain/kotlin/com/soywiz/korag/AGState.kt @@ -2,19 +2,11 @@ package com.soywiz.korag import com.soywiz.kds.* import com.soywiz.kds.iterators.* -import com.soywiz.klock.* -import com.soywiz.klogger.* import com.soywiz.kmem.* -import com.soywiz.kmem.unit.* -import com.soywiz.korag.annotation.* -import com.soywiz.korag.gl.* import com.soywiz.korag.shader.* -import com.soywiz.korag.shader.gl.* -import com.soywiz.korim.bitmap.* import com.soywiz.korim.color.* import com.soywiz.korio.lang.* import com.soywiz.korma.geom.* -import kotlin.coroutines.* import kotlin.jvm.* inline class AGReadKind(val ordinal: Int) { @@ -580,7 +572,7 @@ inline class AGFullState(val data: Int32Buffer = Int32Buffer(8)) { var scissor: AGScissor ; get() = AGScissor(data[5], data[6]) ; set(value) { data[5] = value.xy; data[6] = value.wh } } -fun Rectangle?.toAGScissor(): AGScissor { +fun MRectangle?.toAGScissor(): AGScissor { if (this == null) return AGScissor.NIL return AGScissor(x.toInt(), y.toInt(), width.toInt(), height.toInt()) } @@ -651,8 +643,8 @@ inline class AGScissor(val data: Long) { return "Scissor(x=${x}, y=${y}, width=${width}, height=${height})" } - fun toRect(out: Rectangle = Rectangle()): Rectangle = out.setTo(x, y, width, height) - fun toRectOrNull(out: Rectangle = Rectangle()): Rectangle? { + fun toRect(out: MRectangle = MRectangle()): MRectangle = out.setTo(x, y, width, height) + fun toRectOrNull(out: MRectangle = MRectangle()): MRectangle? { if (this == NIL) return null return out.setTo(x, y, width, height) } @@ -689,7 +681,7 @@ inline class AGScissor(val data: Long) { } } -fun AGScissor.applyMatrixBounds(m: Matrix): AGScissor { +fun AGScissor.applyMatrixBounds(m: MMatrix): AGScissor { val x0 = m.transformX(left, top) val x1 = m.transformX(right, top) val x2 = m.transformX(left, bottom) diff --git a/korgw/src/commonMain/kotlin/com/soywiz/korag/AGValue.kt b/korgw/src/commonMain/kotlin/com/soywiz/korag/AGValue.kt index df3ebdfb0d..d6f581d641 100644 --- a/korgw/src/commonMain/kotlin/com/soywiz/korag/AGValue.kt +++ b/korgw/src/commonMain/kotlin/com/soywiz/korag/AGValue.kt @@ -86,14 +86,14 @@ class AGUniformValues(val capacity: Int = 8 * 1024) { operator fun set(uniform: Uniform, value: Float) { this[uniform].set(value) } operator fun set(uniform: Uniform, value: FloatArray) { this[uniform].set(value) } operator fun set(uniform: Uniform, value: Double) { this[uniform].set(value) } - operator fun set(uniform: Uniform, value: Matrix3D) { this[uniform].set(value) } + operator fun set(uniform: Uniform, value: MMatrix3D) { this[uniform].set(value) } operator fun set(uniform: Uniform, value: IPoint) { this[uniform].set(value) } - operator fun set(uniform: Uniform, value: Vector3D) { this[uniform].set(value) } + operator fun set(uniform: Uniform, value: MVector4) { this[uniform].set(value) } operator fun set(uniform: Uniform, value: RGBAf) { this[uniform].set(value) } operator fun set(uniform: Uniform, value: RGBA) { this[uniform].set(value) } operator fun set(uniform: Uniform, value: RGBAPremultiplied) { this[uniform].set(value) } - operator fun set(uniform: Uniform, value: Array) { this[uniform].set(value) } - operator fun set(uniform: Uniform, value: Array) { this[uniform].set(value) } + operator fun set(uniform: Uniform, value: Array) { this[uniform].set(value) } + operator fun set(uniform: Uniform, value: Array) { this[uniform].set(value) } operator fun set(uniform: Uniform, value: Array) { this[uniform].set(value) } companion object { @@ -194,14 +194,14 @@ open class AGValue( } } - fun set(value: Vector3D) = set(value.data) + fun set(value: MVector4) = set(value.data) fun set(value: RGBAf) = set(value.data, 0, 4) fun set(value: IPoint) = set(value.x.toFloat(), value.y.toFloat()) - fun set(value: Margin) = set(value.top.toFloat(), value.right.toFloat(), value.bottom.toFloat(), value.left.toFloat()) + fun set(value: IMargin) = set(value.top.toFloat(), value.right.toFloat(), value.bottom.toFloat(), value.left.toFloat()) fun set(value: RectCorners) = set(value.topLeft.toFloat(), value.topRight.toFloat(), value.bottomRight.toFloat(), value.bottomLeft.toFloat()) fun set(value: RGBA) = set(value.rf, value.gf, value.bf, value.af) fun set(value: RGBAPremultiplied) = set(value.rf, value.gf, value.bf, value.af) - fun set(mat: Matrix3D) = tempMatrixLock { set(tempMatrix.also { it[0] = mat }) } + fun set(mat: MMatrix3D) = tempMatrixLock { set(tempMatrix.also { it[0] = mat }) } fun set(value: BooleanArray, offset: Int = 0, size: Int = value.size - offset) { _setIntArray(size) { value[offset + it].toInt() } @@ -238,14 +238,14 @@ open class AGValue( } } - fun set(vectors: Array) { + fun set(vectors: Array) { for (n in 0 until min(vectors.size, arrayCount)) { val data = vectors[n].data f32.setArray(n * stride, data, 0, min(data.size, stride)) } } - fun set(matArray: Array) { + fun set(matArray: Array) { val arrayCount = min(arrayCount, matArray.size) val matSize = when (type) { VarType.Mat2 -> 2; VarType.Mat3 -> 3; VarType.Mat4 -> 4; else -> -1 @@ -265,7 +265,7 @@ open class AGValue( private val tempFloatsLock = NonRecursiveLock() private val tempFloats = FloatArray(64 * (4 * 4)) private val tempMatrixLock = NonRecursiveLock() - private val tempMatrix = Array(1) { Matrix3D() } + private val tempMatrix = Array(1) { MMatrix3D() } } override fun toString(): String { diff --git a/korgw/src/commonMain/kotlin/com/soywiz/korag/shader/delegated.kt b/korgw/src/commonMain/kotlin/com/soywiz/korag/shader/delegated.kt index 420747858c..0e76404fc9 100644 --- a/korgw/src/commonMain/kotlin/com/soywiz/korag/shader/delegated.kt +++ b/korgw/src/commonMain/kotlin/com/soywiz/korag/shader/delegated.kt @@ -2,8 +2,8 @@ package com.soywiz.korag.shader import com.soywiz.kmem.toInt import com.soywiz.korag.* -import com.soywiz.korma.geom.Matrix3D -import com.soywiz.korma.geom.Vector3D +import com.soywiz.korma.geom.MMatrix3D +import com.soywiz.korma.geom.MVector4 import kotlin.reflect.KProperty class DoubleDelegatedUniform(val uniform: Uniform, val values: FloatArray, val index: Int, val onSet: (Double) -> Unit, default: Double, val storage: UniformFloatStorage) { @@ -55,9 +55,9 @@ class Vector4DelegatedUniform(val uniform: Uniform, val values: FloatArray, val storage.update() } - operator fun getValue(obj: Any, prop: KProperty<*>): Vector3D = Vector3D(values[0], values[1], values[2], values[3]) + operator fun getValue(obj: Any, prop: KProperty<*>): MVector4 = MVector4(values[0], values[1], values[2], values[3]) - operator fun setValue(obj: Any, prop: KProperty<*>, value: Vector3D) { + operator fun setValue(obj: Any, prop: KProperty<*>, value: MVector4) { values[0] = value.x values[1] = value.y values[2] = value.z @@ -127,20 +127,20 @@ class UniformFloatStorage(val uniforms: AGUniformValues, val uniform: Uniform, v fun vector4Delegate(index: Int = 0) = Vector4DelegatedUniform(uniform, array, index, this) } -class UniformValueStorageMatrix3D(val uniforms: AGUniformValues, val uniform: Uniform, val value: Matrix3D) { +class UniformValueStorageMatrix3D(val uniforms: AGUniformValues, val uniform: Uniform, val value: MMatrix3D) { init { uniforms[uniform] = value } fun delegate() = this - fun setMatrix(value: Matrix3D) { + fun setMatrix(value: MMatrix3D) { this.value.copyFrom(value) uniforms[uniform] = this.value } - operator fun getValue(obj: Any, prop: KProperty<*>): Matrix3D = value - operator fun setValue(obj: Any, prop: KProperty<*>, value: Matrix3D) = setMatrix(value) + operator fun getValue(obj: Any, prop: KProperty<*>): MMatrix3D = value + operator fun setValue(obj: Any, prop: KProperty<*>, value: MMatrix3D) = setMatrix(value) } fun AGUniformValues.storageFor(uniform: Uniform, array: FloatArray = FloatArray(4)) = @@ -148,8 +148,8 @@ fun AGUniformValues.storageFor(uniform: Uniform, array: FloatArray = FloatArray( //fun AGUniformValues.storageForMatrix2(uniform: Uniform, matrix: Matrix3D = Matrix3D()) = UniformValueStorage(this, uniform, matrix) //fun AGUniformValues.storageForMatrix3(uniform: Uniform, matrix: Matrix3D = Matrix3D()) = UniformValueStorage(this, uniform, matrix) //fun AGUniformValues.storageForMatrix4(uniform: Uniform, matrix: Matrix3D = Matrix3D()) = UniformValueStorage(this, uniform, matrix) -fun AGUniformValues.storageForMatrix3D(uniform: Uniform, matrix: Matrix3D = Matrix3D()): UniformValueStorageMatrix3D { - return UniformValueStorageMatrix3D(this, uniform, Matrix3D()).also { +fun AGUniformValues.storageForMatrix3D(uniform: Uniform, matrix: MMatrix3D = MMatrix3D()): UniformValueStorageMatrix3D { + return UniformValueStorageMatrix3D(this, uniform, MMatrix3D()).also { it.setMatrix(matrix) } } diff --git a/korgw/src/commonMain/kotlin/com/soywiz/korev/Input.kt b/korgw/src/commonMain/kotlin/com/soywiz/korev/Input.kt index 1a7c1ba86c..3b538d44a7 100644 --- a/korgw/src/commonMain/kotlin/com/soywiz/korev/Input.kt +++ b/korgw/src/commonMain/kotlin/com/soywiz/korev/Input.kt @@ -250,7 +250,7 @@ class GamepadInfo constructor( companion object { val DEFAULT_NAME2 = "Wireless Controller" } - private val axesData: Array = Array(2) { Point() } + private val axesData: Array = Array(2) { MPoint() } val fullName: String get() = "$name - $name2" @@ -284,7 +284,7 @@ class GamepadInfo constructor( val ry: Double get() = this[GameButton.RY] operator fun get(button: GameButton): Double = mapping.get(button, this) - operator fun get(stick: GameStick): Point = axesData[stick.id].apply { + operator fun get(stick: GameStick): MPoint = axesData[stick.id].apply { this.x = getX(stick) this.y = getY(stick) } diff --git a/korgw/src/commonMain/kotlin/com/soywiz/korgw/GameWindow.kt b/korgw/src/commonMain/kotlin/com/soywiz/korgw/GameWindow.kt index b007a42f68..b3ceb1f036 100644 --- a/korgw/src/commonMain/kotlin/com/soywiz/korgw/GameWindow.kt +++ b/korgw/src/commonMain/kotlin/com/soywiz/korgw/GameWindow.kt @@ -60,8 +60,8 @@ import com.soywiz.korma.geom.Anchor import com.soywiz.korma.geom.Angle import com.soywiz.korma.geom.IRectangle import com.soywiz.korma.geom.ISize -import com.soywiz.korma.geom.Point -import com.soywiz.korma.geom.Rectangle +import com.soywiz.korma.geom.MPoint +import com.soywiz.korma.geom.MRectangle import com.soywiz.korma.geom.absoluteValue import com.soywiz.korma.geom.degrees import com.soywiz.korma.geom.minus @@ -377,7 +377,7 @@ open class GameWindow : open val isSoftKeyboardVisible: Boolean get() = false - open fun setInputRectangle(windowRect: Rectangle) { + open fun setInputRectangle(windowRect: MRectangle) { } open fun showSoftKeyboard(force: Boolean = true, config: ISoftKeyboardConfig? = null) { @@ -764,8 +764,8 @@ open class GameWindow : } fun dispatchGamepadUpdateAdd( - leftStick: Point, - rightStick: Point, + leftStick: MPoint, + rightStick: MPoint, rawButtonsPressed: Int, mapping: GamepadMapping, name: String?, diff --git a/korgw/src/commonTest/kotlin/com/soywiz/korgw/AGUniformsTest.kt b/korgw/src/commonTest/kotlin/com/soywiz/korgw/AGUniformsTest.kt index 0baaf903b8..607684a6da 100644 --- a/korgw/src/commonTest/kotlin/com/soywiz/korgw/AGUniformsTest.kt +++ b/korgw/src/commonTest/kotlin/com/soywiz/korgw/AGUniformsTest.kt @@ -14,19 +14,19 @@ class AGUniformsTest { val block = UniformBlock(projMatrix, viewMatrix, color1, layoutSize = null) val data = UniformBlockData(block) val buffer = UniformBlockBuffer(block, 2) - data[projMatrix].set(Matrix3D().multiply(2f)) + data[projMatrix].set(MMatrix3D().multiply(2f)) val index1 = buffer.put(data) - data[projMatrix].set(Matrix3D().multiply(3f)) + data[projMatrix].set(MMatrix3D().multiply(3f)) val index2 = buffer.put(data) //println(buffer.buffer.f32.toFloatArray().toList()) assertEquals(listOf(0, 1), listOf(index1, index2)) buffer.copyIndexTo(index1, data) - assertEquals(Matrix3D().multiply(2f), Matrix3D().setColumns4x4(data[projMatrix].data.f32.toFloatArray(), 0)) + assertEquals(MMatrix3D().multiply(2f), MMatrix3D().setColumns4x4(data[projMatrix].data.f32.toFloatArray(), 0)) buffer.copyIndexTo(index2, data) - assertEquals(Matrix3D().multiply(3f), Matrix3D().setColumns4x4(data[projMatrix].data.f32.toFloatArray(), 0)) + assertEquals(MMatrix3D().multiply(3f), MMatrix3D().setColumns4x4(data[projMatrix].data.f32.toFloatArray(), 0)) //block.attributePositions //println(block.totalSize) diff --git a/korgw/src/commonTest/kotlin/com/soywiz/korgw/GameWindowTest.kt b/korgw/src/commonTest/kotlin/com/soywiz/korgw/GameWindowTest.kt index 791b56c7d7..75dfea9efb 100644 --- a/korgw/src/commonTest/kotlin/com/soywiz/korgw/GameWindowTest.kt +++ b/korgw/src/commonTest/kotlin/com/soywiz/korgw/GameWindowTest.kt @@ -3,8 +3,8 @@ package com.soywiz.korgw import com.soywiz.korim.color.Colors import com.soywiz.korim.vector.buildShape import com.soywiz.korio.async.suspendTest -import com.soywiz.korma.geom.PointInt -import com.soywiz.korma.geom.Size +import com.soywiz.korma.geom.MPointInt +import com.soywiz.korma.geom.MSize import com.soywiz.korma.geom.vector.lineTo import com.soywiz.korma.geom.vector.moveTo import kotlin.test.Test @@ -22,8 +22,8 @@ class GameWindowTest { } }) val bitmap = cursor.createBitmap() - assertEquals(Size(64, 32), bitmap.bitmap.size) - assertEquals(PointInt(32, 31), bitmap.hotspot) + assertEquals(MSize(64, 32), bitmap.bitmap.size) + assertEquals(MPointInt(32, 31), bitmap.hotspot) //bitmap.bitmap.showImageAndWait() } } diff --git a/korgw/src/iosMacosMain/kotlin/com/soywiz/korgw/DarwinGamePad.kt b/korgw/src/iosMacosMain/kotlin/com/soywiz/korgw/DarwinGamePad.kt index 8bb716651d..fb0a761431 100644 --- a/korgw/src/iosMacosMain/kotlin/com/soywiz/korgw/DarwinGamePad.kt +++ b/korgw/src/iosMacosMain/kotlin/com/soywiz/korgw/DarwinGamePad.kt @@ -2,9 +2,7 @@ package com.soywiz.korgw import com.soywiz.korev.* import com.soywiz.korma.geom.* -import platform.CoreHaptics.* import platform.GameController.* -import kotlin.native.internal.* class DarwinGamePad { val knownControllers = mutableSetOf() @@ -37,8 +35,8 @@ class DarwinGamePad { val mapping = StandardGamepadMapping for ((index, controller) in controllers.withIndex()) { var buttonMask = 0 - val leftStick = Point() - val rightStick = Point() + val leftStick = MPoint() + val rightStick = MPoint() fun button(button: GameButton, pressed: Boolean) { if (pressed) buttonMask = buttonMask or (1 shl button.ordinal) } @@ -48,7 +46,7 @@ class DarwinGamePad { button(button, gcbutton.pressed) } } - fun stick(stick: Point, pad: GCControllerDirectionPad) { + fun stick(stick: MPoint, pad: GCControllerDirectionPad) { stick.setTo(pad.xAxis.value, pad.yAxis.value) } diff --git a/korgw/src/iosMain/kotlin/com/soywiz/korgw/DefaultGameWindowIos.kt b/korgw/src/iosMain/kotlin/com/soywiz/korgw/DefaultGameWindowIos.kt index 20cd21dab0..670417c5a3 100644 --- a/korgw/src/iosMain/kotlin/com/soywiz/korgw/DefaultGameWindowIos.kt +++ b/korgw/src/iosMain/kotlin/com/soywiz/korgw/DefaultGameWindowIos.kt @@ -9,18 +9,14 @@ import com.soywiz.klogger.Console import com.soywiz.kmem.KmemGC import com.soywiz.kmem.hasFlags import com.soywiz.korag.gl.* -import com.soywiz.korev.GameButton -import com.soywiz.korev.GamePadConnectionEvent import com.soywiz.korev.ISoftKeyboardConfig import com.soywiz.korev.Key import com.soywiz.korev.KeyEvent import com.soywiz.korev.SoftKeyboardConfig import com.soywiz.korev.SoftKeyboardReturnKeyType import com.soywiz.korev.SoftKeyboardType -import com.soywiz.korev.StandardGamepadMapping import com.soywiz.korim.format.cg.* -import com.soywiz.korma.geom.Point -import com.soywiz.korma.geom.Rectangle +import com.soywiz.korma.geom.MRectangle import kotlinx.cinterop.CValue import kotlinx.cinterop.ExportObjCClass import kotlinx.cinterop.ObjCAction @@ -29,7 +25,6 @@ import kotlinx.cinterop.memScoped import kotlinx.cinterop.useContents import platform.CoreGraphics.CGPoint import platform.CoreGraphics.CGRect -import platform.CoreGraphics.CGRectMake import platform.EAGL.EAGLContext import platform.EAGL.kEAGLRenderingAPIOpenGLES2 import platform.Foundation.NSBundle @@ -41,9 +36,6 @@ import platform.GLKit.GLKView import platform.GLKit.GLKViewController import platform.GLKit.GLKViewDrawableDepthFormat24 import platform.GLKit.GLKViewDrawableStencilFormat8 -import platform.GameController.GCController -import platform.GameController.GCControllerButtonInput -import platform.GameController.GCControllerDirectionPad import platform.GameController.GCEventViewController import platform.UIKit.* import platform.darwin.NSInteger @@ -542,7 +534,7 @@ open class IosGameWindow( ?: UIApplication.sharedApplication.keyWindow ?: (UIApplication.sharedApplication.windows.first() as UIWindow) - override fun setInputRectangle(windowRect: Rectangle) { + override fun setInputRectangle(windowRect: MRectangle) { println("IosGameWindow.setInputRectangle: windowRect=$windowRect") prepareSoftKeyboardOnce() textField.setBounds(windowRect.toCG()) diff --git a/korgw/src/jsMain/kotlin/com/soywiz/korgw/DefaultGameWindowJs.kt b/korgw/src/jsMain/kotlin/com/soywiz/korgw/DefaultGameWindowJs.kt index 8c95da19bf..f65d9f7849 100644 --- a/korgw/src/jsMain/kotlin/com/soywiz/korgw/DefaultGameWindowJs.kt +++ b/korgw/src/jsMain/kotlin/com/soywiz/korgw/DefaultGameWindowJs.kt @@ -9,7 +9,7 @@ import com.soywiz.korim.format.* import com.soywiz.korio.async.* import com.soywiz.korio.file.* import com.soywiz.korio.util.* -import com.soywiz.korma.geom.Rectangle +import com.soywiz.korma.geom.MRectangle import kotlinx.coroutines.* import org.w3c.dom.events.* import org.w3c.dom.events.MouseEvent @@ -487,7 +487,7 @@ open class BrowserCanvasJsGameWindow( } } - override fun setInputRectangle(windowRect: Rectangle) { + override fun setInputRectangle(windowRect: MRectangle) { ensureSoftKeyboardInput() softKeyboardInput?.style?.let { style -> style.left = "${(windowRect.left / canvasRatio)}px" diff --git a/korgw/src/jvmMain/kotlin/com/soywiz/korgw/awt/BaseAwtGameWindow.kt b/korgw/src/jvmMain/kotlin/com/soywiz/korgw/awt/BaseAwtGameWindow.kt index 48c228b959..8f7b3fadb8 100644 --- a/korgw/src/jvmMain/kotlin/com/soywiz/korgw/awt/BaseAwtGameWindow.kt +++ b/korgw/src/jvmMain/kotlin/com/soywiz/korgw/awt/BaseAwtGameWindow.kt @@ -103,7 +103,7 @@ abstract class BaseAwtGameWindow( val CustomCursor.jvmCursor: java.awt.Cursor by extraPropertyThis { val toolkit = Toolkit.getDefaultToolkit() val size = toolkit.getBestCursorSize(bounds.width.toIntCeil(), bounds.height.toIntCeil()) - val result = this.createBitmap(Size(size.width, size.height)) + val result = this.createBitmap(MSize(size.width, size.height)) //println("BITMAP SIZE=${result.bitmap.size}, hotspot=${result.hotspot}") val hotspotX = result.hotspot.x.toInt().coerceIn(0, result.bitmap.width - 1) val hotspotY = result.hotspot.y.toInt().coerceIn(0, result.bitmap.height - 1) diff --git a/korgw/src/jvmMain/kotlin/com/soywiz/korgw/osx/MacosGameController.kt b/korgw/src/jvmMain/kotlin/com/soywiz/korgw/osx/MacosGameController.kt index 23d38fd658..1f7601ab09 100644 --- a/korgw/src/jvmMain/kotlin/com/soywiz/korgw/osx/MacosGameController.kt +++ b/korgw/src/jvmMain/kotlin/com/soywiz/korgw/osx/MacosGameController.kt @@ -68,7 +68,7 @@ class GCControllerDirectionPad(id: Long) : ObjcRef(id) { val x: Double get() = xAxis.value val y: Double get() = yAxis.value - private val _point: Point = Point() + private val _point: MPoint = MPoint() val point: IPoint get() = _point.setTo(x, y) companion object { diff --git a/korgw/src/macosMain/kotlin/com/soywiz/korgw/DefaultGameWindowMacos.kt b/korgw/src/macosMain/kotlin/com/soywiz/korgw/DefaultGameWindowMacos.kt index bb88bda361..85c4585130 100644 --- a/korgw/src/macosMain/kotlin/com/soywiz/korgw/DefaultGameWindowMacos.kt +++ b/korgw/src/macosMain/kotlin/com/soywiz/korgw/DefaultGameWindowMacos.kt @@ -11,7 +11,7 @@ import com.soywiz.korim.format.* import com.soywiz.korim.format.ns.* import com.soywiz.korio.lang.* import com.soywiz.korma.geom.* -import com.soywiz.korma.geom.Size +import com.soywiz.korma.geom.MSize import kotlinx.cinterop.* import kotlinx.coroutines.* import platform.AppKit.* @@ -270,9 +270,9 @@ class MyNSOpenGLView( } } - var inputRect: Rectangle = Rectangle(0.0, 0.0, 0.0, 0.0) + var inputRect: MRectangle = MRectangle(0.0, 0.0, 0.0, 0.0) - fun setInputRectangle(windowRect: Rectangle) { + fun setInputRectangle(windowRect: MRectangle) { this.inputRect = windowRect } @@ -354,7 +354,7 @@ class MyDefaultGameWindow : GameWindow() { private val openglView: MyNSOpenGLView = MyNSOpenGLView(this@MyDefaultGameWindow, NSMakeRect(0.0, 0.0, 16.0, 16.0), pixelFormat) var timer: NSTimer? = null - override fun setInputRectangle(windowRect: Rectangle) { + override fun setInputRectangle(windowRect: MRectangle) { openglView.setInputRectangle(windowRect) } @@ -491,8 +491,8 @@ class MyDefaultGameWindow : GameWindow() { override val pixelsPerInch: Double get() { val screen = window.screen ?: return 96.0 - val screenSizeInPixels = screen.visibleFrame.useContents { Size(size.width, size.height) } - val screenSizeInMillimeters = CGDisplayScreenSize(((screen.deviceDescription["NSScreenNumber"]) as NSNumber).unsignedIntValue).useContents { Size(width, height) } + val screenSizeInPixels = screen.visibleFrame.useContents { MSize(size.width, size.height) } + val screenSizeInMillimeters = CGDisplayScreenSize(((screen.deviceDescription["NSScreenNumber"]) as NSNumber).unsignedIntValue).useContents { MSize(width, height) } val dpmm = screenSizeInPixels.width / screenSizeInMillimeters.width val dpi = dpmm / 0.0393701 diff --git a/korim/src/androidMain/kotlin/com/soywiz/korim/format/NativeImageFormatProviderAndroid.kt b/korim/src/androidMain/kotlin/com/soywiz/korim/format/NativeImageFormatProviderAndroid.kt index bdcec49cf5..d8be83148f 100644 --- a/korim/src/androidMain/kotlin/com/soywiz/korim/format/NativeImageFormatProviderAndroid.kt +++ b/korim/src/androidMain/kotlin/com/soywiz/korim/format/NativeImageFormatProviderAndroid.kt @@ -265,7 +265,7 @@ class AndroidContext2dRenderer(val bmp: android.graphics.Bitmap, val antialiasin } @Suppress("RemoveRedundantQualifierName") - fun convertPaint(c: com.soywiz.korim.paint.Paint, m: com.soywiz.korma.geom.Matrix, out: Paint, alpha: Double) { + fun convertPaint(c: com.soywiz.korim.paint.Paint, m: com.soywiz.korma.geom.MMatrix, out: Paint, alpha: Double) { when (c) { is com.soywiz.korim.paint.NonePaint -> { out.shader = null @@ -323,9 +323,9 @@ class AndroidContext2dRenderer(val bmp: android.graphics.Bitmap, val antialiasin } } - fun com.soywiz.korma.geom.Matrix.toAndroid() = android.graphics.Matrix().setTo(this) + fun com.soywiz.korma.geom.MMatrix.toAndroid() = android.graphics.Matrix().setTo(this) - fun android.graphics.Matrix.setTo(m: com.soywiz.korma.geom.Matrix) = this.apply { + fun android.graphics.Matrix.setTo(m: com.soywiz.korma.geom.MMatrix) = this.apply { matrixValues[Matrix.MSCALE_X] = m.a.toFloat() matrixValues[Matrix.MSKEW_X] = m.b.toFloat() matrixValues[Matrix.MSKEW_Y] = m.c.toFloat() diff --git a/korim/src/commonMain/kotlin/com/soywiz/korim/atlas/AtlasInfo.kt b/korim/src/commonMain/kotlin/com/soywiz/korim/atlas/AtlasInfo.kt index 3f85882fb1..05ac05115c 100644 --- a/korim/src/commonMain/kotlin/com/soywiz/korim/atlas/AtlasInfo.kt +++ b/korim/src/commonMain/kotlin/com/soywiz/korim/atlas/AtlasInfo.kt @@ -32,14 +32,14 @@ data class AtlasInfo( ) data class Rect(val x: Int, val y: Int, val w: Int, val h: Int) { - val rect get() = Rectangle(x, y, w, h) + val rect get() = MRectangle(x, y, w, h) fun toRectangleInt() : RectangleInt = RectangleInt(x, y, w, h) fun toMap() = mapOf("x" to x, "y" to y, "w" to w, "h" to h) } data class Size(val width: Int, val height: Int) { - val size get() = com.soywiz.korma.geom.Size(width, height) + val size get() = com.soywiz.korma.geom.MSize(width, height) fun toMap() = mapOf("w" to width, "h" to height) } @@ -110,7 +110,7 @@ data class AtlasInfo( spriteSourceSize: Rect, trimmed: Boolean, orig: Size = Size(0, 0), - offset: Point = Point(), + offset: MPoint = MPoint(), ) : this( name = name, frame = frame, @@ -141,7 +141,7 @@ data class AtlasInfo( val orig: Size get() = sourceSize @Deprecated("Use virtFrame", ReplaceWith("Point(virtFrame?.x ?: 0, virtFrame?.y ?: 0)")) - val offset: Point get() = Point(virtFrame?.x ?: 0, virtFrame?.y ?: 0) + val offset: MPoint get() = MPoint(virtFrame?.x ?: 0, virtFrame?.y ?: 0) // @TODO: Rename to path or name //@IgnoreSerialization @@ -319,9 +319,9 @@ data class AtlasInfo( val r = ListReader(content.lines()) var pageImage: Any? = null - fun String.point(): Point { + fun String.point(): MPoint { val list = this.split(',', limit = 2) - return Point(list.first().trim().toInt(), list.last().trim().toInt()) + return MPoint(list.first().trim().toInt(), list.last().trim().toInt()) } fun String.size(): Size = point().let { Size(it.x.toInt(), it.y.toInt()) } @@ -380,10 +380,10 @@ data class AtlasInfo( } else { val name = line var rotate = false - var xy = Point() + var xy = MPoint() var size = Size(0, 0) var orig = Size(0, 0) - var offset = Point() + var offset = MPoint() while (r.hasMore && r.peek().contains(':')) { val (key, value) = r.read().trim().keyValue() when (key) { diff --git a/korim/src/commonMain/kotlin/com/soywiz/korim/atlas/AtlasPacker.kt b/korim/src/commonMain/kotlin/com/soywiz/korim/atlas/AtlasPacker.kt index f2a0ceb629..4044f9a7c7 100644 --- a/korim/src/commonMain/kotlin/com/soywiz/korim/atlas/AtlasPacker.kt +++ b/korim/src/commonMain/kotlin/com/soywiz/korim/atlas/AtlasPacker.kt @@ -3,13 +3,13 @@ package com.soywiz.korim.atlas import com.soywiz.kds.iterators.fastForEach import com.soywiz.kmem.nextPowerOfTwo import com.soywiz.korim.bitmap.* -import com.soywiz.korma.geom.Rectangle -import com.soywiz.korma.geom.Size +import com.soywiz.korma.geom.MRectangle +import com.soywiz.korma.geom.MSize import com.soywiz.korma.geom.binpack.BinPacker import kotlin.jvm.JvmName object AtlasPacker { - data class Entry(val item: T, val originalSlice: BmpSlice, val slice: BmpSlice32, val rectWithBorder: Rectangle, val rect: Rectangle) + data class Entry(val item: T, val originalSlice: BmpSlice, val slice: BmpSlice32, val rectWithBorder: MRectangle, val rect: MRectangle) data class AtlasResult(val tex: Bitmap32, val atlas: Atlas, val packedItems: List>) : AtlasLookup { val packedItemsByItem = packedItems.associateBy { it.item } @@ -45,19 +45,19 @@ object AtlasPacker { fun pack(items: List>, maxSide: Int = 2048, maxTextures: Int = 16, borderSize: Int = 2, fileName: String = "atlas.png"): Result { val borderSize2 = borderSize * 2 val packs = BinPacker.packSeveral(maxSide.toDouble(), maxSide.toDouble(), items) { - Size(it.second.width + borderSize2, it.second.height + borderSize2) + MSize(it.second.width + borderSize2, it.second.height + borderSize2) } if (packs.size > maxTextures) error("textures:${packs.size} > maxTextures:${maxTextures}") return Result(packs.map { pack -> val out = Bitmap32(pack.width.toInt().nextPowerOfTwo, pack.height.toInt().nextPowerOfTwo, premultiplied = true) val packedItems = arrayListOf>() for ((item, rectOrNull) in pack.items) { - val rectWithBorder = rectOrNull ?: Rectangle(0, 0, 1, 1) + val rectWithBorder = rectOrNull ?: MRectangle(0, 0, 1, 1) val width = item.second.width val height = item.second.height val x0 = rectWithBorder.x.toInt() + borderSize val y0 = rectWithBorder.y.toInt() + borderSize - val rect = Rectangle(x0, y0, width, height) + val rect = MRectangle(x0, y0, width, height) val x1 = x0 + width - 1 val y1 = y0 + height - 1 val bmp = item.second.extract().toBMP32IfRequired().premultipliedIfRequired() @@ -76,7 +76,7 @@ object AtlasPacker { frames = packedItems.map { val bmp = it.slice val r = it.rectWithBorder - val rect = Rectangle(r.x.toInt() + 2, r.y.toInt() + 2, bmp.width, bmp.height).toInt() + val rect = MRectangle(r.x.toInt() + 2, r.y.toInt() + 2, bmp.width, bmp.height).toInt() val filename = it.originalSlice.name AtlasInfo.Region( name = filename ?: "unknown", diff --git a/korim/src/commonMain/kotlin/com/soywiz/korim/atlas/MutableAtlas.kt b/korim/src/commonMain/kotlin/com/soywiz/korim/atlas/MutableAtlas.kt index 043fd206ab..da0d6b2f3e 100644 --- a/korim/src/commonMain/kotlin/com/soywiz/korim/atlas/MutableAtlas.kt +++ b/korim/src/commonMain/kotlin/com/soywiz/korim/atlas/MutableAtlas.kt @@ -3,7 +3,6 @@ package com.soywiz.korim.atlas import com.soywiz.korim.bitmap.* import com.soywiz.korma.geom.* import com.soywiz.korma.geom.binpack.BinPacker -import com.soywiz.korma.geom.slice.* import kotlin.collections.LinkedHashMap import kotlin.collections.arrayListOf import kotlin.collections.map diff --git a/korim/src/commonMain/kotlin/com/soywiz/korim/bitmap/Bitmap.kt b/korim/src/commonMain/kotlin/com/soywiz/korim/bitmap/Bitmap.kt index 4ee1e593f3..fd99733bec 100644 --- a/korim/src/commonMain/kotlin/com/soywiz/korim/bitmap/Bitmap.kt +++ b/korim/src/commonMain/kotlin/com/soywiz/korim/bitmap/Bitmap.kt @@ -60,7 +60,7 @@ abstract class Bitmap( val area: Int get() = width * height fun index(x: Int, y: Int) = y * width + x fun inside(x: Int, y: Int) = x in 0 until width && y in 0 until height - override val size: Size get() = Size(width, height) + override val size: MSize get() = MSize(width, height) fun clearDirtyRegion() { if (dirtyRegion != null) { diff --git a/korim/src/commonMain/kotlin/com/soywiz/korim/bitmap/Bitmap32.kt b/korim/src/commonMain/kotlin/com/soywiz/korim/bitmap/Bitmap32.kt index 170b29aaef..3afa56aee4 100644 --- a/korim/src/commonMain/kotlin/com/soywiz/korim/bitmap/Bitmap32.kt +++ b/korim/src/commonMain/kotlin/com/soywiz/korim/bitmap/Bitmap32.kt @@ -8,9 +8,9 @@ import com.soywiz.korim.color.* import com.soywiz.korim.vector.Bitmap32Context2d import com.soywiz.korim.vector.Context2d import com.soywiz.korma.geom.IRectangleInt -import com.soywiz.korma.geom.Matrix3D +import com.soywiz.korma.geom.MMatrix3D import com.soywiz.korma.geom.RectangleInt -import com.soywiz.korma.geom.Vector3D +import com.soywiz.korma.geom.MVector4 import com.soywiz.korma.geom.bottom import com.soywiz.korma.geom.left import com.soywiz.korma.geom.right @@ -298,7 +298,7 @@ class Bitmap32( updateColors(x, y, width, height) { RGBA(R[it.r], G[it.g], B[it.b], A[it.a]) } } - fun applyColorMatrix(matrix: Matrix3D, x: Int = 0, y: Int = 0, width: Int = this.width - x, height: Int = this.height - y, temp: Vector3D = Vector3D()) { + fun applyColorMatrix(matrix: MMatrix3D, x: Int = 0, y: Int = 0, width: Int = this.width - x, height: Int = this.height - y, temp: MVector4 = MVector4()) { val v = temp updateColors(x, y, width, height) { v.setTo(it.rf, it.gf, it.bf, it.af) diff --git a/korim/src/commonMain/kotlin/com/soywiz/korim/bitmap/BitmapExt.kt b/korim/src/commonMain/kotlin/com/soywiz/korim/bitmap/BitmapExt.kt index 4e72167699..507842740e 100644 --- a/korim/src/commonMain/kotlin/com/soywiz/korim/bitmap/BitmapExt.kt +++ b/korim/src/commonMain/kotlin/com/soywiz/korim/bitmap/BitmapExt.kt @@ -2,7 +2,7 @@ package com.soywiz.korim.bitmap import com.soywiz.korim.color.RGBA import com.soywiz.korma.geom.Anchor -import com.soywiz.korma.geom.Rectangle +import com.soywiz.korma.geom.MRectangle import com.soywiz.korma.geom.ScaleMode import kotlin.math.absoluteValue @@ -65,7 +65,7 @@ fun Bitmap.resized(out: Bitmap, scale: ScaleMode, anchor: Anchor): Bitmap { val width = out.width val height = out.height out.context2d(antialiased = true) { - val rect = Rectangle(0, 0, width, height).place(bmp.width.toDouble(), bmp.height.toDouble(), anchor, scale) + val rect = MRectangle(0, 0, width, height).place(bmp.width.toDouble(), bmp.height.toDouble(), anchor, scale) drawImage(bmp, rect.x, rect.y, rect.width, rect.height) } return out @@ -76,7 +76,7 @@ fun Bitmap.resized(width: Int, height: Int, scale: ScaleMode, anchor: Anchor, na resized(if (native) NativeImage(width, height) else createWithThisFormat(width, height), scale, anchor) fun Bitmap.resizedUpTo(width: Int, height: Int, native: Boolean = true): Bitmap { - val rect = Rectangle(0, 0, width, height) + val rect = MRectangle(0, 0, width, height) .place(this.width.toDouble(), this.height.toDouble(), Anchor.TOP_LEFT, ScaleMode.FIT) return resized(rect.width.toInt(), rect.height.toInt(), ScaleMode.FILL, Anchor.TOP_LEFT, native) } diff --git a/korim/src/commonMain/kotlin/com/soywiz/korim/bitmap/BitmapSlice.kt b/korim/src/commonMain/kotlin/com/soywiz/korim/bitmap/BitmapSlice.kt index 3d8f5552e2..6cb6f1730d 100644 --- a/korim/src/commonMain/kotlin/com/soywiz/korim/bitmap/BitmapSlice.kt +++ b/korim/src/commonMain/kotlin/com/soywiz/korim/bitmap/BitmapSlice.kt @@ -91,7 +91,7 @@ fun RectSlice.extract(): T { return out } -fun SliceCoordsWithBase.slice(bounds: IRectangleInt = IRectangleInt(0, 0, width, height), name: String? = null, orientation: ImageOrientation = ImageOrientation.ROTATE_0, padding: IMarginInt = IMarginInt.ZERO): RectSlice = +fun SliceCoordsWithBase.slice(bounds: IRectangleInt = IRectangleInt(0, 0, width, height), name: String? = null, orientation: ImageOrientation = ImageOrientation.ROTATE_0, padding: com.soywiz.korma.geom.IMarginInt = IMarginInt.ZERO): RectSlice = RectSlice( this.base, // @TODO: This shouldn't be necessary. But ASE test fails without this @@ -110,7 +110,7 @@ fun SliceCoordsWithBase.slice(bounds: IRectangleInt = IRectang //fun CoordsWithContainer.sliceWithSize(x: Int, y: Int, width: Int, height: Int, name: String? = null, orientation: ImageOrientation = ImageOrientation.ORIGINAL, padding: IMarginInt = MARGIN_INT_0): RectSlice = // slice(RectangleInt(x, y, width, height), name, orientation, padding) -fun T.slice(bounds: IRectangleInt = IRectangleInt(0, 0, width, height), name: String? = null, orientation: ImageOrientation = ImageOrientation.ROTATE_0, padding: IMarginInt = IMarginInt.ZERO): RectSlice { +fun T.slice(bounds: IRectangleInt = IRectangleInt(0, 0, width, height), name: String? = null, orientation: ImageOrientation = ImageOrientation.ROTATE_0, padding: com.soywiz.korma.geom.IMarginInt = IMarginInt.ZERO): RectSlice { val left = bounds.left.clamp(0, width) val top = bounds.top.clamp(0, height) @@ -123,9 +123,9 @@ fun T.slice(bounds: IRectangleInt = IRectangleInt(0, 0, width, heig ), orientation, padding, name ) } -fun T.sliceWithBounds(left: Int, top: Int, right: Int, bottom: Int, name: String? = null, orientation: ImageOrientation = ImageOrientation.ROTATE_0, padding: IMarginInt = IMarginInt.ZERO): RectSlice = +fun T.sliceWithBounds(left: Int, top: Int, right: Int, bottom: Int, name: String? = null, orientation: ImageOrientation = ImageOrientation.ROTATE_0, padding: com.soywiz.korma.geom.IMarginInt = IMarginInt.ZERO): RectSlice = slice(RectangleInt(left, top, right - left, bottom - top), name, orientation, padding) -fun T.sliceWithSize(x: Int, y: Int, width: Int, height: Int, name: String? = null, orientation: ImageOrientation = ImageOrientation.ROTATE_0, padding: IMarginInt = IMarginInt.ZERO): RectSlice = +fun T.sliceWithSize(x: Int, y: Int, width: Int, height: Int, name: String? = null, orientation: ImageOrientation = ImageOrientation.ROTATE_0, padding: com.soywiz.korma.geom.IMarginInt = IMarginInt.ZERO): RectSlice = slice(RectangleInt(x, y, width, height), name, orientation, padding) val RectSlice.bmpWidth: Int get() = this.baseWidth @@ -135,9 +135,9 @@ val RectSlice.bmpHeight: Int get() = this.baseHeight // http://pixijs.download/dev/docs/PIXI.Texture.html#Texture fun BitmapSliceCompat( bmp: Bitmap, - frame: Rectangle, - orig: Rectangle, - trim: Rectangle, + frame: MRectangle, + orig: MRectangle, + trim: MRectangle, rotated: Boolean, name: String = "unknown" ) = bmp.slice(frame.toInt(), name, if (rotated) ImageOrientation.ROTATE_90 else ImageOrientation.ROTATE_0) diff --git a/korim/src/commonMain/kotlin/com/soywiz/korim/color/Vector3DExt.kt b/korim/src/commonMain/kotlin/com/soywiz/korim/color/Vector3DExt.kt index ac68b21339..bfc5c60359 100644 --- a/korim/src/commonMain/kotlin/com/soywiz/korim/color/Vector3DExt.kt +++ b/korim/src/commonMain/kotlin/com/soywiz/korim/color/Vector3DExt.kt @@ -1,8 +1,8 @@ package com.soywiz.korim.color -import com.soywiz.korma.geom.Vector3D +import com.soywiz.korma.geom.MVector4 -fun Vector3D.setToColorPremultiplied(col: RGBA): Vector3D = this.apply { col.toPremultipliedVector3D(this) } -fun Vector3D.setToColor(col: RGBA): Vector3D = this.apply { col.toPremultipliedVector3D(this) } -fun RGBA.toPremultipliedVector3D(out: Vector3D = Vector3D()): Vector3D = out.setTo(rf * af, gf * af, bf * af, 1f) -fun RGBA.toVector3D(out: Vector3D = Vector3D()): Vector3D = out.setTo(rf, gf, bf, af) +fun MVector4.setToColorPremultiplied(col: RGBA): MVector4 = this.apply { col.toPremultipliedVector3D(this) } +fun MVector4.setToColor(col: RGBA): MVector4 = this.apply { col.toPremultipliedVector3D(this) } +fun RGBA.toPremultipliedVector3D(out: MVector4 = MVector4()): MVector4 = out.setTo(rf * af, gf * af, bf * af, 1f) +fun RGBA.toVector3D(out: MVector4 = MVector4()): MVector4 = out.setTo(rf, gf, bf, af) diff --git a/korim/src/commonMain/kotlin/com/soywiz/korim/font/BitmapFont.kt b/korim/src/commonMain/kotlin/com/soywiz/korim/font/BitmapFont.kt index 560b14723f..23eb27fd20 100644 --- a/korim/src/commonMain/kotlin/com/soywiz/korim/font/BitmapFont.kt +++ b/korim/src/commonMain/kotlin/com/soywiz/korim/font/BitmapFont.kt @@ -33,7 +33,7 @@ import com.soywiz.korio.serialization.json.* import com.soywiz.korio.serialization.xml.Xml import com.soywiz.korio.serialization.xml.get import com.soywiz.korio.util.unquote -import com.soywiz.korma.geom.Rectangle +import com.soywiz.korma.geom.MRectangle import kotlin.collections.component1 import kotlin.collections.component2 import kotlin.collections.set @@ -213,7 +213,7 @@ interface BitmapFont : Font { internal val naturalMetrics = GlyphMetrics( fontSize, true, -1, - Rectangle(xoffset, yoffset, texture.width, texture.height), + MRectangle(xoffset, yoffset, texture.width, texture.height), xadvance.toDouble() ) } @@ -245,7 +245,7 @@ private class BitmapFontImpl constructor( } ) } - override val naturalNonExistantGlyphMetrics: GlyphMetrics = GlyphMetrics(fontSize, false, 0, Rectangle(), 0.0) + override val naturalNonExistantGlyphMetrics: GlyphMetrics = GlyphMetrics(fontSize, false, 0, MRectangle(), 0.0) override fun getKerning(first: Int, second: Int): BitmapFont.Kerning? = kernings[BitmapFont.Kerning.buildKey(first, second)] override fun getOrNull(codePoint: Int): BitmapFont.Glyph? = glyphs[codePoint] diff --git a/korim/src/commonMain/kotlin/com/soywiz/korim/font/Font.kt b/korim/src/commonMain/kotlin/com/soywiz/korim/font/Font.kt index 3d1c47b5a3..b50b85244e 100644 --- a/korim/src/commonMain/kotlin/com/soywiz/korim/font/Font.kt +++ b/korim/src/commonMain/kotlin/com/soywiz/korim/font/Font.kt @@ -76,7 +76,7 @@ data class PlacedGlyphMetrics constructor( val y: Double, val metrics: GlyphMetrics, val fontMetrics: FontMetrics, - val transform: Matrix, + val transform: MMatrix, val index: Int, val nline: Int, ) { @@ -89,7 +89,7 @@ data class PlacedGlyphMetrics constructor( metrics.xadvance, fontMetrics.lineHeight ) - }.applyTransform(Matrix().translate(x, y).premultiply(transform)) + }.applyTransform(MMatrix().translate(x, y).premultiply(transform)) } val boundsPathCurves: Curves by lazy { val curves = boundsPath.getCurves() @@ -107,9 +107,9 @@ data class PlacedGlyphMetrics constructor( val middle = when (startEnd) { true -> caretStart.get(0.5) false -> caretEnd.get(0.5) - null -> Point.middle(caretStart.get(0.5), caretEnd.get(0.5)) + null -> MPoint.middle(caretStart.get(0.5), caretEnd.get(0.5)) } - return Point.distance(middle.x, middle.y, x, y) + return MPoint.distance(middle.x, middle.y, x, y) } fun distToPath(p: IPoint, startEnd: Boolean? = null): Double = distToPath(p.x, p.y, startEnd) @@ -149,7 +149,7 @@ fun Font.renderGlyphToBitmap( renderGlyph() } val imageOut = image.toBMP32IfRequired().applyEffect(effect) - val glyph = PlacedGlyphMetrics(codePoint, gx + border, gy + border, gmetrics, fmetrics, Matrix(), 0, 0) + val glyph = PlacedGlyphMetrics(codePoint, gx + border, gy + border, gmetrics, fmetrics, MMatrix(), 0, 0) return TextToBitmapResult(imageOut, fmetrics, TextMetrics(), listOf(glyph), listOf(listOf(glyph)), buildShape(iwidth, iheight) { renderGlyph() }) @@ -220,7 +220,7 @@ fun Font.drawText( textRangeStart: Int = 0, textRangeEnd: Int = Int.MAX_VALUE, - placed: (TextRendererActions.(codePoint: Int, x: Double, y: Double, size: Double, metrics: GlyphMetrics, fmetrics: FontMetrics, transform: Matrix) -> Unit)? = null + placed: (TextRendererActions.(codePoint: Int, x: Double, y: Double, size: Double, metrics: GlyphMetrics, fmetrics: FontMetrics, transform: MMatrix) -> Unit)? = null ): TextMetricsResult? { //println("drawText!!: text=$text, align=$align") val glyphs = if (outMetrics != null) MultiplePlacedGlyphMetrics() else null @@ -333,14 +333,14 @@ fun Font.getTextBounds( // Compute val bb = BoundsBuilder() var dy = 0.0 - val lineBounds = FastArrayList() + val lineBounds = FastArrayList() val offsetY = actions.getAlignY(align.vertical, out.fontMetrics) //println("--") //println("offsetY=$offsetY, totalMaxLineHeight=${actions.totalMaxLineHeight}, align=$align") //printStackTrace() for (line in actions.lines) { val offsetX = line.getAlignX(align.horizontal) - val rect = Rectangle( + val rect = MRectangle( -offsetX, +offsetY + dy - out.ascent, line.maxX, diff --git a/korim/src/commonMain/kotlin/com/soywiz/korim/font/GlyphPath.kt b/korim/src/commonMain/kotlin/com/soywiz/korim/font/GlyphPath.kt index 22588df4e1..22340b9119 100644 --- a/korim/src/commonMain/kotlin/com/soywiz/korim/font/GlyphPath.kt +++ b/korim/src/commonMain/kotlin/com/soywiz/korim/font/GlyphPath.kt @@ -5,17 +5,17 @@ import com.soywiz.korim.vector.Context2d import com.soywiz.korim.vector.Drawable import com.soywiz.korim.vector.Shape import com.soywiz.korim.vector.draw -import com.soywiz.korma.geom.Matrix -import com.soywiz.korma.geom.Point +import com.soywiz.korma.geom.MMatrix +import com.soywiz.korma.geom.MPoint import com.soywiz.korma.geom.vector.VectorPath data class GlyphPath( var path: VectorPath = VectorPath(), var colorShape: Shape? = null, var bitmap: Bitmap? = null, - val bitmapOffset: Point = Point(0, 0), - val bitmapScale: Point = Point(1, 1), - val transform: Matrix = Matrix(), + val bitmapOffset: MPoint = MPoint(0, 0), + val bitmapScale: MPoint = MPoint(1, 1), + val transform: MMatrix = MMatrix(), var scale: Double = 1.0 ) : Drawable { val isOnlyPath get() = bitmap == null && colorShape == null diff --git a/korim/src/commonMain/kotlin/com/soywiz/korim/font/LazyBitmapFont.kt b/korim/src/commonMain/kotlin/com/soywiz/korim/font/LazyBitmapFont.kt index 7df6eb2caa..cdc9995951 100644 --- a/korim/src/commonMain/kotlin/com/soywiz/korim/font/LazyBitmapFont.kt +++ b/korim/src/commonMain/kotlin/com/soywiz/korim/font/LazyBitmapFont.kt @@ -45,7 +45,7 @@ class LazyBitmapFont( maxWidth = vfontMetrics.maxWidth, ) } - override val naturalNonExistantGlyphMetrics: GlyphMetrics = GlyphMetrics(fontSize, false, 0, Rectangle(), 0.0) + override val naturalNonExistantGlyphMetrics: GlyphMetrics = GlyphMetrics(fontSize, false, 0, MRectangle(), 0.0) override fun getKerning(first: Int, second: Int): BitmapFont.Kerning? { val kerning = font.getKerning(fontSize, first, second) diff --git a/korim/src/commonMain/kotlin/com/soywiz/korim/font/Metrics.kt b/korim/src/commonMain/kotlin/com/soywiz/korim/font/Metrics.kt index f03f64970d..1089c4808f 100644 --- a/korim/src/commonMain/kotlin/com/soywiz/korim/font/Metrics.kt +++ b/korim/src/commonMain/kotlin/com/soywiz/korim/font/Metrics.kt @@ -94,7 +94,7 @@ data class GlyphMetrics( var size: Double = 0.0, var existing: Boolean = false, var codePoint: Int = 0, - val bounds: Rectangle = Rectangle(), + val bounds: MRectangle = MRectangle(), var xadvance: Double = 0.0, ) { val right: Double get() = bounds.right @@ -129,12 +129,12 @@ data class GlyphMetrics( } data class TextMetrics constructor( - val bounds: Rectangle = Rectangle(), - var lineBounds: List = emptyList(), + val bounds: MRectangle = MRectangle(), + var lineBounds: List = emptyList(), val fontMetrics: FontMetrics = FontMetrics(), var nlines: Int = 0, ) { - val firstLineBounds: Rectangle get() = lineBounds.firstOrNull() ?: Rectangle() + val firstLineBounds: MRectangle get() = lineBounds.firstOrNull() ?: MRectangle() val left: Double get() = bounds.left val top: Double get() = bounds.top diff --git a/korim/src/commonMain/kotlin/com/soywiz/korim/font/TtfFont.kt b/korim/src/commonMain/kotlin/com/soywiz/korim/font/TtfFont.kt index f5f8c01f08..7ce3500c3e 100644 --- a/korim/src/commonMain/kotlin/com/soywiz/korim/font/TtfFont.kt +++ b/korim/src/commonMain/kotlin/com/soywiz/korim/font/TtfFont.kt @@ -47,8 +47,8 @@ import com.soywiz.korio.stream.openFastStream import com.soywiz.korio.stream.openUse import com.soywiz.korio.stream.readBytesUpTo import com.soywiz.korio.stream.toSyncStream -import com.soywiz.korma.geom.Matrix -import com.soywiz.korma.geom.Rectangle +import com.soywiz.korma.geom.MMatrix +import com.soywiz.korma.geom.MRectangle import com.soywiz.korma.geom.vector.IVectorPath import com.soywiz.korma.geom.vector.VectorPath import com.soywiz.korma.geom.vector.lineTo @@ -299,7 +299,7 @@ abstract class BaseTtfFont( val substitutionsCodePoints = IntMap() lateinit var fontMetrics1px: FontMetrics; private set - protected val nonExistantGlyphMetrics1px = GlyphMetrics(1.0, false, 0, Rectangle(), 0.0) + protected val nonExistantGlyphMetrics1px = GlyphMetrics(1.0, false, 0, MRectangle(), 0.0) var isOpenType = false val ttfName: String get() = namesi.ttfName @@ -919,7 +919,7 @@ abstract class BaseTtfFont( fun FastByteArrayInputStream.readOffset16(): Int = readU16BE() fun FastByteArrayInputStream.readOffset24(): Int = readU24BE() fun FastByteArrayInputStream.readOffset32(): Int = readS32BE() - fun FastByteArrayInputStream.readAffine2x3(isVar: Boolean, out: Matrix = Matrix()): Matrix { + fun FastByteArrayInputStream.readAffine2x3(isVar: Boolean, out: MMatrix = MMatrix()): MMatrix { val xx = readFIXED3() val yx = readFIXED3() val xy = readFIXED3() @@ -944,7 +944,7 @@ abstract class BaseTtfFont( out.alpha = readF2DOT14().toDouble() return out } - fun FastByteArrayInputStream.readClipBox(doVar: Boolean = false): Rectangle { + fun FastByteArrayInputStream.readClipBox(doVar: Boolean = false): MRectangle { val format = readU8() val xMin: Int = readFWORD() val yMin: Int = readFWORD() @@ -953,7 +953,7 @@ abstract class BaseTtfFont( if (format == 2) { val varIndexBase = readVarIdxBase() } - return Rectangle.fromBounds(xMin, yMin, xMax, yMax) + return MRectangle.fromBounds(xMin, yMin, xMax, yMax) } fun FastByteArrayInputStream.readBaseGlyphPaintRecord() { val glyphID = s.readU16BE() @@ -1936,7 +1936,7 @@ abstract class BaseTtfFont( val size = unitsPerEm.toDouble() val scale = getTextScale(size) - GlyphMetrics(size, true, -1, Rectangle.fromBounds( + GlyphMetrics(size, true, -1, MRectangle.fromBounds( xMin * scale, yMin * scale, xMax * scale, yMax * scale ), advanceWidth * scale) @@ -1955,7 +1955,7 @@ abstract class BaseTtfFont( override val paths = refs.map { ref -> val gpath = ref.glyph.path.path GlyphGraphicsPath(ref.glyph.index, VectorPath(IntArrayList(gpath.commands.size), DoubleArrayList(gpath.data.size))).also { out -> - val m = Matrix() + val m = MMatrix() m.scale(ref.scaleX, ref.scaleY) m.translate(ref.x, -ref.y) out.path.write(ref.glyph.path.path, m) diff --git a/korim/src/commonMain/kotlin/com/soywiz/korim/format/ImageInfo.kt b/korim/src/commonMain/kotlin/com/soywiz/korim/format/ImageInfo.kt index e9efb25ff5..5cb82017a6 100644 --- a/korim/src/commonMain/kotlin/com/soywiz/korim/format/ImageInfo.kt +++ b/korim/src/commonMain/kotlin/com/soywiz/korim/format/ImageInfo.kt @@ -2,14 +2,14 @@ package com.soywiz.korim.format import com.soywiz.kds.Extra import com.soywiz.kds.toMap -import com.soywiz.korma.geom.Size +import com.soywiz.korma.geom.MSize open class ImageInfo : Extra by Extra.Mixin() { var width: Int = 0 var height: Int = 0 var bitsPerPixel: Int = 8 - val size: Size get() = Size(width, height) + val size: MSize get() = MSize(width, height) override fun toString(): String = "ImageInfo(width=$width, height=$height, bpp=$bitsPerPixel, extra=${extra?.toMap()})" } diff --git a/korim/src/commonMain/kotlin/com/soywiz/korim/paint/Filler.kt b/korim/src/commonMain/kotlin/com/soywiz/korim/paint/Filler.kt index a6378c11fa..e381b37336 100644 --- a/korim/src/commonMain/kotlin/com/soywiz/korim/paint/Filler.kt +++ b/korim/src/commonMain/kotlin/com/soywiz/korim/paint/Filler.kt @@ -8,7 +8,7 @@ import com.soywiz.korim.color.RGBAPremultiplied import com.soywiz.korim.color.RgbaPremultipliedArray import com.soywiz.korim.vector.Context2d import com.soywiz.korim.vector.CycleMethod -import com.soywiz.korma.geom.Matrix +import com.soywiz.korma.geom.MMatrix abstract class BaseFiller { abstract fun fill(data: RgbaPremultipliedArray, offset: Int, x0: Int, x1: Int, y: Int) @@ -35,9 +35,9 @@ class BitmapFiller : BaseFiller() { private var cycleX: CycleMethod = CycleMethod.NO_CYCLE private var cycleY: CycleMethod = CycleMethod.NO_CYCLE private var texture: Bitmap32 = Bitmaps.transparent.bmp - private var transform: Matrix = Matrix() + private var transform: MMatrix = MMatrix() private var linear: Boolean = true - private val compTrans = Matrix() + private val compTrans = MMatrix() fun set(fill: BitmapPaint, state: Context2d.State) = this.apply { this.cycleX = fill.cycleX @@ -101,7 +101,7 @@ class GradientFiller : BaseFiller() { fun set(fill: GradientPaint, state: Context2d.State): GradientFiller { fill.fillColors(colors) - this.fill = fill.copy(transform = Matrix().apply { + this.fill = fill.copy(transform = MMatrix().apply { identity() preconcat(fill.transform) preconcat(state.transform) diff --git a/korim/src/commonMain/kotlin/com/soywiz/korim/paint/Paint.kt b/korim/src/commonMain/kotlin/com/soywiz/korim/paint/Paint.kt index 582a88acc7..4ed5ca76c7 100644 --- a/korim/src/commonMain/kotlin/com/soywiz/korim/paint/Paint.kt +++ b/korim/src/commonMain/kotlin/com/soywiz/korim/paint/Paint.kt @@ -8,8 +8,8 @@ import com.soywiz.korim.bitmap.Bitmap import com.soywiz.korim.color.* import com.soywiz.korim.vector.CycleMethod import com.soywiz.korma.geom.Angle -import com.soywiz.korma.geom.Matrix -import com.soywiz.korma.geom.Point +import com.soywiz.korma.geom.MMatrix +import com.soywiz.korma.geom.MPoint import com.soywiz.korma.geom.degrees import com.soywiz.korma.geom.div import com.soywiz.korma.geom.unaryMinus @@ -62,10 +62,10 @@ typealias ColorPaint = RGBA val DefaultPaint: RGBA get() = Colors.BLACK interface TransformedPaint : Paint { - val transform: Matrix + val transform: MMatrix val units: GradientUnits - fun applyMatrix(m: Matrix): TransformedPaint = replaceMatrix(this.transform * m) - fun replaceMatrix(m: Matrix): TransformedPaint + fun applyMatrix(m: MMatrix): TransformedPaint = replaceMatrix(this.transform * m) + fun replaceMatrix(m: MMatrix): TransformedPaint } enum class GradientKind { @@ -97,7 +97,7 @@ data class GradientPaint( val stops: DoubleArrayList = DoubleArrayList(), val colors: IntArrayList = IntArrayList(), val cycle: CycleMethod = CycleMethod.NO_CYCLE, - override val transform: Matrix = Matrix(), + override val transform: MMatrix = MMatrix(), val interpolationMethod: GradientInterpolationMethod = GradientInterpolationMethod.NORMAL, override val units: GradientUnits = GradientUnits.OBJECT_BOUNDING_BOX, val startAngle: Angle = Angle.ZERO, @@ -107,25 +107,25 @@ data class GradientPaint( val isSweep: Boolean get() = kind == GradientKind.SWEEP @Deprecated("") - fun x0(m: Matrix) = m.transformX(x0, y0) + fun x0(m: MMatrix) = m.transformX(x0, y0) @Deprecated("") - fun y0(m: Matrix) = m.transformY(x0, y0) + fun y0(m: MMatrix) = m.transformY(x0, y0) @Deprecated("") - fun r0(m: Matrix) = m.transformX(r0, r0) + fun r0(m: MMatrix) = m.transformX(r0, r0) @Deprecated("") - fun x1(m: Matrix) = m.transformX(x1, y1) + fun x1(m: MMatrix) = m.transformX(x1, y1) @Deprecated("") - fun y1(m: Matrix) = m.transformY(x1, y1) + fun y1(m: MMatrix) = m.transformY(x1, y1) @Deprecated("") - fun r1(m: Matrix) = m.transformX(r1, r1) + fun r1(m: MMatrix) = m.transformX(r1, r1) val numberOfStops get() = stops.size companion object { - fun identity(kind: GradientKind) = GradientPaint(kind, 0.0, 0.0, 0.0, if (kind == GradientKind.RADIAL) 0.0 else 1.0, 0.0, 1.0, transform = Matrix()) + fun identity(kind: GradientKind) = GradientPaint(kind, 0.0, 0.0, 0.0, if (kind == GradientKind.RADIAL) 0.0 else 1.0, 0.0, 1.0, transform = MMatrix()) - fun gradientBoxMatrix(width: Double, height: Double, rotation: Angle, tx: Double, ty: Double, out: Matrix = Matrix()): Matrix { + fun gradientBoxMatrix(width: Double, height: Double, rotation: Angle, tx: Double, ty: Double, out: MMatrix = MMatrix()): MMatrix { out.identity() out.pretranslate(tx + width / 2, ty + height / 2) out.prescale(width / 2, height / 2) @@ -187,9 +187,9 @@ data class GradientPaint( return add(stop, color.depremultipliedAccurate) } - val untransformedGradientMatrix = Matrix().apply { + val untransformedGradientMatrix = MMatrix().apply { translate(-x0, -y0) - val scale = 1.0 / Point.distance(x0, y0, x1, y1).clamp(1.0, 16000.0) + val scale = 1.0 / MPoint.distance(x0, y0, x1, y1).clamp(1.0, 16000.0) scale(scale, scale) rotate(-Angle.between(x0, y0, x1, y1)) } @@ -197,7 +197,7 @@ data class GradientPaint( //val gradientMatrixInv = gradientMatrix.inverted() val transformInv = transform.inverted() - val gradientMatrix = Matrix().apply { + val gradientMatrix = MMatrix().apply { identity() premultiply(untransformedGradientMatrix) premultiply(transformInv) @@ -218,7 +218,7 @@ data class GradientPaint( GradientKind.SWEEP -> { val x = transformInv.transformX(px, py) val y = transformInv.transformY(px, py) - Point.angle(x0, y0, x, y) / 360.degrees + MPoint.angle(x0, y0, x, y) / 360.degrees } GradientKind.RADIAL -> { val x = transformInv.transformX(px, py) @@ -235,7 +235,7 @@ data class GradientPaint( val Float.pow2: Float get() = this * this val Double.pow2: Double get() = this * this - fun getRatioAt(x: Double, y: Double, m: Matrix): Double { + fun getRatioAt(x: Double, y: Double, m: MMatrix): Double { //val tx = gradientMatrix.transformX(x, y) //val ty = gradientMatrix.transformY(x, y) //return m.transformX(tx, ty) @@ -244,7 +244,7 @@ data class GradientPaint( } //override fun applyMatrix(m: Matrix): GradientPaint = copy(transform = transform * m) - override fun replaceMatrix(m: Matrix): GradientPaint = copy(transform = m) + override fun replaceMatrix(m: MMatrix): GradientPaint = copy(transform = m) override fun clone(): Paint = copy(transform = transform.clone()) @@ -263,11 +263,11 @@ data class GradientPaint( } } -inline fun LinearGradientPaint(x0: Number, y0: Number, x1: Number, y1: Number, cycle: CycleMethod = CycleMethod.NO_CYCLE, transform: Matrix = Matrix(), block: GradientPaint.() -> Unit = {}) = GradientPaint(GradientKind.LINEAR, x0.toDouble(), y0.toDouble(), 0.0, x1.toDouble(), y1.toDouble(), 0.0, cycle = cycle, transform = transform).also(block) -inline fun RadialGradientPaint(x0: Number, y0: Number, r0: Number, x1: Number, y1: Number, r1: Number, cycle: CycleMethod = CycleMethod.NO_CYCLE, transform: Matrix = Matrix(), block: GradientPaint.() -> Unit = {}) = GradientPaint(GradientKind.RADIAL, x0.toDouble(), y0.toDouble(), r0.toDouble(), x1.toDouble(), y1.toDouble(), r1.toDouble(), cycle = cycle, transform = transform).also(block) +inline fun LinearGradientPaint(x0: Number, y0: Number, x1: Number, y1: Number, cycle: CycleMethod = CycleMethod.NO_CYCLE, transform: MMatrix = MMatrix(), block: GradientPaint.() -> Unit = {}) = GradientPaint(GradientKind.LINEAR, x0.toDouble(), y0.toDouble(), 0.0, x1.toDouble(), y1.toDouble(), 0.0, cycle = cycle, transform = transform).also(block) +inline fun RadialGradientPaint(x0: Number, y0: Number, r0: Number, x1: Number, y1: Number, r1: Number, cycle: CycleMethod = CycleMethod.NO_CYCLE, transform: MMatrix = MMatrix(), block: GradientPaint.() -> Unit = {}) = GradientPaint(GradientKind.RADIAL, x0.toDouble(), y0.toDouble(), r0.toDouble(), x1.toDouble(), y1.toDouble(), r1.toDouble(), cycle = cycle, transform = transform).also(block) @Deprecated("Only available on Android or Bitmap32") -inline fun SweepGradientPaint(x0: Number, y0: Number, transform: Matrix = Matrix(), block: GradientPaint.() -> Unit = {}) = GradientPaint(GradientKind.SWEEP, x0.toDouble(), y0.toDouble(), 0.0, 0.0, 0.0, 0.0, transform = transform).also(block) -inline fun ConicGradientPaint(startAngle: Angle, x0: Number, y0: Number, transform: Matrix = Matrix(), block: GradientPaint.() -> Unit = {}) = GradientPaint(GradientKind.CONIC, x0.toDouble(), y0.toDouble(), 0.0, 0.0, 0.0, 0.0, startAngle = startAngle, transform = transform).also(block) +inline fun SweepGradientPaint(x0: Number, y0: Number, transform: MMatrix = MMatrix(), block: GradientPaint.() -> Unit = {}) = GradientPaint(GradientKind.SWEEP, x0.toDouble(), y0.toDouble(), 0.0, 0.0, 0.0, 0.0, transform = transform).also(block) +inline fun ConicGradientPaint(startAngle: Angle, x0: Number, y0: Number, transform: MMatrix = MMatrix(), block: GradientPaint.() -> Unit = {}) = GradientPaint(GradientKind.CONIC, x0.toDouble(), y0.toDouble(), 0.0, 0.0, 0.0, 0.0, startAngle = startAngle, transform = transform).also(block) /** Adds color stops to the gradient in the [pairs] list being the left of the pair the ratio between 0.0 and 1.0, and the right of the pair the [Color] */ fun GradientPaint.add(vararg pairs: Pair): GradientPaint { @@ -294,7 +294,7 @@ fun GradientPaint.add(colors: RgbaArray): GradientPaint { } fun Bitmap.toPaint( - transform: Matrix = Matrix(), + transform: MMatrix = MMatrix(), cycleX: CycleMethod = CycleMethod.NO_CYCLE, cycleY: CycleMethod = CycleMethod.NO_CYCLE, smooth: Boolean = true, @@ -303,7 +303,7 @@ fun Bitmap.toPaint( data class BitmapPaint( val bitmap: Bitmap, - override val transform: Matrix = Matrix(), + override val transform: MMatrix = MMatrix(), val cycleX: CycleMethod = CycleMethod.NO_CYCLE, val cycleY: CycleMethod = CycleMethod.NO_CYCLE, val smooth: Boolean = true, @@ -317,7 +317,7 @@ data class BitmapPaint( override fun clone(): Paint = copy(transform = transform.clone()) //override fun applyMatrix(m: Matrix): BitmapPaint = copy(transform = transform * m) - override fun replaceMatrix(m: Matrix): BitmapPaint = copy(transform = m) + override fun replaceMatrix(m: MMatrix): BitmapPaint = copy(transform = m) //override fun transformed(m: Matrix) = BitmapPaint(bitmap, Matrix().multiply(this.transform, m)) override fun toString(): String = "BitmapPaint($bitmap, cycle=($cycleX, $cycleY), smooth=$smooth, transform=$transform)" @@ -336,7 +336,7 @@ ctx.scale(2, 2) ctx.fillRect(100, 100, 100, 100); */ -fun Paint.getPaintWithUnits(transform: Matrix, path: VectorPath): Paint { +fun Paint.getPaintWithUnits(transform: MMatrix, path: VectorPath): Paint { val paint = this if (paint !is TransformedPaint) return this if (paint.units == GradientUnits.USER_SPACE_ON_USE) return this @@ -344,7 +344,7 @@ fun Paint.getPaintWithUnits(transform: Matrix, path: VectorPath): Paint { //val points = path.getPoints2() //val bounds = BoundsBuilder().add(path.getPoints2()).getBounds() val bounds = path.getBounds() - val m = Matrix() + val m = MMatrix() m.pretranslate(bounds.x, bounds.y) m.prescale(bounds.width, bounds.height) return paint.replaceMatrix(paint.transform * m * transform.inverted()) diff --git a/korim/src/commonMain/kotlin/com/soywiz/korim/style/CSS.kt b/korim/src/commonMain/kotlin/com/soywiz/korim/style/CSS.kt index c1434f5d9a..9674ee687d 100644 --- a/korim/src/commonMain/kotlin/com/soywiz/korim/style/CSS.kt +++ b/korim/src/commonMain/kotlin/com/soywiz/korim/style/CSS.kt @@ -20,7 +20,7 @@ import com.soywiz.korio.lang.substr import com.soywiz.korio.util.StrReader import com.soywiz.korio.util.reader import com.soywiz.korma.geom.Angle -import com.soywiz.korma.geom.Matrix +import com.soywiz.korma.geom.MMatrix import com.soywiz.korma.geom.degrees import com.soywiz.korma.geom.radians import com.soywiz.korma.interpolation.Easing @@ -236,10 +236,10 @@ class CSS(val allRules: List, unit: Unit = Unit) { return args } - fun parseTransform(str: String): Matrix { + fun parseTransform(str: String): MMatrix { val tokens = tokenize(str).map { it.str.lowercase() } val tr = ListReader(tokens) - val out = Matrix() + val out = MMatrix() //println("Not implemented: parseTransform: $str: $tokens") while (tr.hasMore) { val id = tr.read().lowercase() @@ -433,9 +433,9 @@ fun CSS.InterpolationResult.getColor(key: String, default: RGBA = Colors.TRANSPA this.ratio.interpolate(k0[key]?.color ?: default, k1[key]?.color ?: default) fun CSS.InterpolationResult.getRatio(key: String, default: Double = 0.0): Double = this.ratio.interpolate(k0[key]?.ratio ?: default, k1[key]?.ratio ?: default) -fun CSS.InterpolationResult.getMatrix(key: String, default: Matrix = Matrix()): Matrix = +fun CSS.InterpolationResult.getMatrix(key: String, default: MMatrix = MMatrix()): MMatrix = this.ratio.interpolate(k0[key]?.matrix ?: default, k1[key]?.matrix ?: default) -fun CSS.InterpolationResult.getTransform(key: String, default: Matrix.Transform = Matrix.Transform()): Matrix.Transform = +fun CSS.InterpolationResult.getTransform(key: String, default: MMatrix.Transform = MMatrix.Transform()): MMatrix.Transform = this.ratio.interpolate(k0[key]?.transform ?: default, k1[key]?.transform ?: default) fun CSS.InterpolationResult.getEasing(key: String, default: Easing = Easing.LINEAR): Easing = k0[key]?.easing ?: default diff --git a/korim/src/commonMain/kotlin/com/soywiz/korim/style/DOM.kt b/korim/src/commonMain/kotlin/com/soywiz/korim/style/DOM.kt index 6f38929b69..695382f69c 100644 --- a/korim/src/commonMain/kotlin/com/soywiz/korim/style/DOM.kt +++ b/korim/src/commonMain/kotlin/com/soywiz/korim/style/DOM.kt @@ -2,13 +2,10 @@ package com.soywiz.korim.style import com.soywiz.kds.iterators.fastForEach import com.soywiz.kds.iterators.fastForEachReverse -import com.soywiz.kds.linkedHashMapOf import com.soywiz.korim.annotation.KorimExperimental -import com.soywiz.korma.geom.Matrix +import com.soywiz.korma.geom.MMatrix import kotlin.jvm.JvmName -import kotlin.reflect.KClass import kotlin.reflect.KMutableProperty1 -import kotlin.reflect.KProperty1 @KorimExperimental open class DOM(val css: CSS) { @@ -53,8 +50,8 @@ open class DOM(val css: CSS) { } class MatrixMapping( override val name: String, - override val property: KMutableProperty1 - ) : Mapping { + override val property: KMutableProperty1 + ) : Mapping { override fun set(element: DomElement, prop: String, value: Any?) { property.set(element, getMatrix(prop, value)) } @@ -66,8 +63,8 @@ open class DOM(val css: CSS) { property as KMutableProperty1 ) } @JvmName("addMatrix") - fun add(name: String, property: KMutableProperty1): DomPropertyMapping = this.apply { mappings[name] = MatrixMapping(name, - property as KMutableProperty1 + fun add(name: String, property: KMutableProperty1): DomPropertyMapping = this.apply { mappings[name] = MatrixMapping(name, + property as KMutableProperty1 ) } } @@ -130,17 +127,17 @@ open class DOM(val css: CSS) { } companion object { - fun getTransform(prop: String, value: Any?): Matrix.Transform = when (value) { - is Matrix.Transform -> value + fun getTransform(prop: String, value: Any?): MMatrix.Transform = when (value) { + is MMatrix.Transform -> value is CSS.InterpolationResult -> value.getTransform(prop) is CSS.Expression -> value.transform - else -> Matrix.Transform() + else -> MMatrix.Transform() } - fun getMatrix(prop: String, value: Any?): Matrix = when (value) { - is Matrix -> value + fun getMatrix(prop: String, value: Any?): MMatrix = when (value) { + is MMatrix -> value is CSS.InterpolationResult -> value.getMatrix(prop) is CSS.Expression -> value.matrix - else -> Matrix() + else -> MMatrix() } fun getRatio(prop: String, value: Any?): Double = when (value) { is Double -> value diff --git a/korim/src/commonMain/kotlin/com/soywiz/korim/text/RichTextDataRenderer.kt b/korim/src/commonMain/kotlin/com/soywiz/korim/text/RichTextDataRenderer.kt index 3dbc0c2308..74c4fc0b26 100644 --- a/korim/src/commonMain/kotlin/com/soywiz/korim/text/RichTextDataRenderer.kt +++ b/korim/src/commonMain/kotlin/com/soywiz/korim/text/RichTextDataRenderer.kt @@ -82,7 +82,7 @@ fun RichTextData.place( fun Context2d.drawRichText( text: RichTextData, - bounds: IRectangle = Rectangle(0, 0, width, height), + bounds: IRectangle = MRectangle(0, 0, width, height), wordWrap: Boolean = true, includePartialLines: Boolean = false, ellipsis: String? = null, diff --git a/korim/src/commonMain/kotlin/com/soywiz/korim/text/TextRenderer.kt b/korim/src/commonMain/kotlin/com/soywiz/korim/text/TextRenderer.kt index 482456a554..06046c7238 100644 --- a/korim/src/commonMain/kotlin/com/soywiz/korim/text/TextRenderer.kt +++ b/korim/src/commonMain/kotlin/com/soywiz/korim/text/TextRenderer.kt @@ -18,7 +18,7 @@ interface ITextRendererActions { var y: Double val lineHeight: Double var currentLineNum: Int - val transform: Matrix + val transform: MMatrix fun getKerning(leftCodePoint: Int, rightCodePoint: Int): Double fun getGlyphMetrics(reader: WStringReader?, codePoint: Int): GlyphMetrics @@ -60,7 +60,7 @@ abstract class TextRendererActions : ITextRendererActions { font.getGlyphMetrics(fontSize, codePoint, glyphMetrics, reader) //var transformAnchor: Anchor = Anchor.BOTTOM_CENTER - override val transform: Matrix = Matrix() + override val transform: MMatrix = MMatrix() var paint: Paint? = null var tint: RGBA = Colors.WHITE // Ignored for now @@ -132,7 +132,7 @@ class BoundBuilderTextRendererActions : TextRendererActions() { current.bounds.add(rx, ry) } - private fun add(rect: Rectangle) { + private fun add(rect: MRectangle) { val fx = rect.left val fy = rect.top val w = rect.width @@ -189,7 +189,7 @@ class Text2TextRendererActions : TextRendererActions() { private val arraySY = doubleArrayListOf() private val arrayRot = doubleArrayListOf() val arrayMetrics = VectorArrayList(dimensions = 4) - private val tr = Matrix.Transform() + private val tr = MMatrix.Transform() val size get() = arrayX.size data class LineInfo(var maxTop: Double = 0.0, var minBottom: Double = 0.0, var maxLineHeight: Double = 0.0) @@ -210,7 +210,7 @@ class Text2TextRendererActions : TextRendererActions() { return out } - fun getGlyphBounds(n: Int, out: Rectangle = Rectangle()): IRectangle { + fun getGlyphBounds(n: Int, out: MRectangle = MRectangle()): IRectangle { if (n >= size) { out.setTo(0, 0, 0, 0) } else { @@ -224,7 +224,7 @@ class Text2TextRendererActions : TextRendererActions() { return out } - fun getBounds(out: Rectangle = Rectangle()): IRectangle { + fun getBounds(out: MRectangle = MRectangle()): IRectangle { if (size == 0) { out.setTo(0, 0, 0, 0) return out @@ -454,7 +454,7 @@ fun VectorBuilder.text( renderer: TextRenderer = DefaultStringTextRenderer as TextRenderer, ) { val vectorBuilder = this - val transform = Matrix() + val transform = MMatrix() val actions = object : TextRendererActions() { val metrics = renderer.measure(text, textSize, font) diff --git a/korim/src/commonMain/kotlin/com/soywiz/korim/tiles/TileShapeInfo.kt b/korim/src/commonMain/kotlin/com/soywiz/korim/tiles/TileShapeInfo.kt index 95319f67e6..da582fff0c 100644 --- a/korim/src/commonMain/kotlin/com/soywiz/korim/tiles/TileShapeInfo.kt +++ b/korim/src/commonMain/kotlin/com/soywiz/korim/tiles/TileShapeInfo.kt @@ -1,22 +1,22 @@ package com.soywiz.korim.tiles -import com.soywiz.korma.geom.Matrix +import com.soywiz.korma.geom.MMatrix import com.soywiz.korma.geom.collider.HitTestDirection import com.soywiz.korma.geom.collider.HitTestDirectionFlags import com.soywiz.korma.geom.collider.HitTestable import com.soywiz.korma.geom.shape.Shape2d interface TileShapeInfo : HitTestable { - fun hitTestAny(shape2d: Shape2d, matrix: Matrix, direction: HitTestDirection): Boolean + fun hitTestAny(shape2d: Shape2d, matrix: MMatrix, direction: HitTestDirection): Boolean } data class TileShapeInfoImpl( val type: HitTestDirectionFlags, val shape: Shape2d, - val transform: Matrix, + val transform: MMatrix, //val path: VectorPath ) : TileShapeInfo { - val transformInv: Matrix = transform.inverted() + val transformInv: MMatrix = transform.inverted() override fun hitTestAny(x: Double, y: Double, direction: HitTestDirection): Boolean { //return path.containsPoint(x, y) && type.matches(direction) @@ -24,6 +24,6 @@ data class TileShapeInfoImpl( return shape.containsPoint(x, y, transformInv) && type.matches(direction) } - override fun hitTestAny(shape2d: Shape2d, matrix: Matrix, direction: HitTestDirection): Boolean = + override fun hitTestAny(shape2d: Shape2d, matrix: MMatrix, direction: HitTestDirection): Boolean = Shape2d.intersects(shape, transform, shape2d, matrix) && type.matches(direction) } diff --git a/korim/src/commonMain/kotlin/com/soywiz/korim/util/NinePatchSlices2D.kt b/korim/src/commonMain/kotlin/com/soywiz/korim/util/NinePatchSlices2D.kt index eba454a18b..2e8985f911 100644 --- a/korim/src/commonMain/kotlin/com/soywiz/korim/util/NinePatchSlices2D.kt +++ b/korim/src/commonMain/kotlin/com/soywiz/korim/util/NinePatchSlices2D.kt @@ -2,7 +2,7 @@ package com.soywiz.korim.util import com.soywiz.korma.geom.IPoint import com.soywiz.korma.geom.ISize -import com.soywiz.korma.geom.Point +import com.soywiz.korma.geom.MPoint import com.soywiz.korma.geom.PointArrayList import com.soywiz.korma.geom.firstX import com.soywiz.korma.geom.firstY @@ -38,7 +38,7 @@ data class NinePatchSlices2D(val x: NinePatchSlices, val y: NinePatchSlices) { positions: List, oldSize: ISize, newSize: ISize ): List = positions.map { transform2D(it, oldSize, newSize) } - fun getScaledPointAt(point: IPoint, oldSize: ISize, newSize: ISize, out: Point = Point()): IPoint { + fun getScaledPointAt(point: IPoint, oldSize: ISize, newSize: ISize, out: MPoint = MPoint()): IPoint { val p = pointArrayListOf(point) transform2DInplace(p, oldSize, newSize) out.setTo(p.firstX, p.firstY) diff --git a/korim/src/commonMain/kotlin/com/soywiz/korim/vector/BitmapVector.kt b/korim/src/commonMain/kotlin/com/soywiz/korim/vector/BitmapVector.kt index b0d09aa369..ce186a3071 100644 --- a/korim/src/commonMain/kotlin/com/soywiz/korim/vector/BitmapVector.kt +++ b/korim/src/commonMain/kotlin/com/soywiz/korim/vector/BitmapVector.kt @@ -5,12 +5,11 @@ import com.soywiz.korim.bitmap.Bitmap32 import com.soywiz.korim.bitmap.NativeImageOrBitmap32 import com.soywiz.korim.bitmap.context2d import com.soywiz.korim.color.RGBA -import com.soywiz.korim.color.RgbaArray import com.soywiz.korma.geom.* class BitmapVector( val shape: BoundsDrawable, - val bounds: Rectangle = shape.bounds, + val bounds: MRectangle = shape.bounds, val scale: Double = 1.0, val rasterizerMethod: ShapeRasterizerMethod = ShapeRasterizerMethod.X4, val antialiasing: Boolean = true, diff --git a/korim/src/commonMain/kotlin/com/soywiz/korim/vector/Context2d.kt b/korim/src/commonMain/kotlin/com/soywiz/korim/vector/Context2d.kt index 83f548a6eb..d74b2812ff 100644 --- a/korim/src/commonMain/kotlin/com/soywiz/korim/vector/Context2d.kt +++ b/korim/src/commonMain/kotlin/com/soywiz/korim/vector/Context2d.kt @@ -25,7 +25,7 @@ open class Context2d constructor( protected open val rendererWidth get() = renderer.width protected open val rendererHeight get() = renderer.height protected open fun rendererRender(state: State, fill: Boolean, winding: Winding? = null) = renderer.render(state, fill, winding) - protected open fun rendererDrawImage(image: Bitmap, x: Double, y: Double, width: Double = image.width.toDouble(), height: Double = image.height.toDouble(), transform: Matrix = Matrix()) = renderer.drawImage(image, x, y, width, height, transform) + protected open fun rendererDrawImage(image: Bitmap, x: Double, y: Double, width: Double = image.width.toDouble(), height: Double = image.height.toDouble(), transform: MMatrix = MMatrix()) = renderer.drawImage(image, x, y, width, height, transform) protected open fun rendererDispose() = renderer.dispose() protected open fun rendererBufferingStart() = renderer.bufferingStart() protected open fun rendererBufferingEnd() = renderer.bufferingEnd() @@ -49,7 +49,7 @@ open class Context2d constructor( override val width: Int get() = (parent.width / scaleX).toInt() override val height: Int get() = (parent.height / scaleY).toInt() - private inline fun adjustMatrix(transform: Matrix, callback: () -> T): T = transform.keepMatrix { + private inline fun adjustMatrix(transform: MMatrix, callback: () -> T): T = transform.keepMatrix { transform.scale(scaleX, scaleY) callback() } @@ -61,7 +61,7 @@ open class Context2d constructor( //override fun renderText(state: State, font: Font, fontSize: Double, text: String, x: Double, y: Double, fill: Boolean): Unit = // adjustState(state) { parent.renderText(state, font, fontSize, text, x, y, fill) } - override fun drawImage(image: Bitmap, x: Double, y: Double, width: Double, height: Double, transform: Matrix) { + override fun drawImage(image: Bitmap, x: Double, y: Double, width: Double, height: Double, transform: MMatrix) { adjustMatrix(transform) { parent.drawImage(image, x, y, width, height, transform) } } } @@ -81,7 +81,7 @@ open class Context2d constructor( } data class State constructor( - var transform: Matrix = Matrix(), + var transform: MMatrix = MMatrix(), var clip: VectorPath? = null, var path: VectorPath = VectorPath(), var lineScaleMode: LineScaleMode = LineScaleMode.NORMAL, @@ -271,10 +271,10 @@ open class Context2d constructor( fun rotateDeg(degs: Double) { state.transform.prerotate(degs.degrees) } fun translate(tx: Double, ty: Double) { state.transform.pretranslate(tx, ty) } - fun transform(m: Matrix) { state.transform.premultiply(m) } + fun transform(m: MMatrix) { state.transform.premultiply(m) } fun transform(a: Double, b: Double, c: Double, d: Double, tx: Double, ty: Double) { state.transform.premultiply(a, b, c, d, tx, ty) } - fun setTransform(m: Matrix) { state.transform.copyFrom(m) } + fun setTransform(m: MMatrix) { state.transform.copyFrom(m) } fun setTransform(a: Double, b: Double, c: Double, d: Double, tx: Double, ty: Double) { state.transform.setTo(a, b, c, d, tx, ty) } fun shear(sx: Double, sy: Double) = transform(1.0, sy, sx, 1.0, 0.0, 0.0) @@ -354,7 +354,7 @@ open class Context2d constructor( fun beginPath() { state.path = VectorPath() } - fun getBounds(out: Rectangle = Rectangle()) = state.path.getBounds(out) + fun getBounds(out: MRectangle = MRectangle()) = state.path.getBounds(out) fun stroke() { if (state.strokeStyle != NonePaint) rendererRender(state, fill = false) } fun fill(winding: Winding? = null) { if (state.fillStyle != NonePaint) rendererRender(state, fill = true, winding = winding) } @@ -501,7 +501,7 @@ open class Context2d constructor( else -> newBi } keepTransform { - setTransform(Matrix()) + setTransform(MMatrix()) this.rendererDrawImage(renderBi, 0.0, 0.0) } //} finally { @@ -511,18 +511,18 @@ open class Context2d constructor( } } - inline fun createLinearGradient(x0: Number, y0: Number, x1: Number, y1: Number, cycle: CycleMethod = CycleMethod.NO_CYCLE, transform: Matrix = Matrix(), block: GradientPaint.() -> Unit = {}) = LinearGradientPaint(x0, y0, x1, y1, cycle, transform, block) - inline fun createRadialGradient(x0: Number, y0: Number, r0: Number, x1: Number, y1: Number, r1: Number, cycle: CycleMethod = CycleMethod.NO_CYCLE, transform: Matrix = Matrix(), block: GradientPaint.() -> Unit = {}) = RadialGradientPaint(x0, y0, r0, x1, y1, r1, cycle, transform, block) + inline fun createLinearGradient(x0: Number, y0: Number, x1: Number, y1: Number, cycle: CycleMethod = CycleMethod.NO_CYCLE, transform: MMatrix = MMatrix(), block: GradientPaint.() -> Unit = {}) = LinearGradientPaint(x0, y0, x1, y1, cycle, transform, block) + inline fun createRadialGradient(x0: Number, y0: Number, r0: Number, x1: Number, y1: Number, r1: Number, cycle: CycleMethod = CycleMethod.NO_CYCLE, transform: MMatrix = MMatrix(), block: GradientPaint.() -> Unit = {}) = RadialGradientPaint(x0, y0, r0, x1, y1, r1, cycle, transform, block) @Deprecated("Only available on Android or Bitmap32") - inline fun createSweepGradient(x0: Number, y0: Number, transform: Matrix = Matrix(), block: GradientPaint.() -> Unit = {}) = SweepGradientPaint(x0, y0, transform, block) - inline fun createConicGradient(startAngle: Angle, x0: Number, y0: Number, transform: Matrix = Matrix(), block: GradientPaint.() -> Unit = {}) = ConicGradientPaint(startAngle, x0, y0, transform, block) + inline fun createSweepGradient(x0: Number, y0: Number, transform: MMatrix = MMatrix(), block: GradientPaint.() -> Unit = {}) = SweepGradientPaint(x0, y0, transform, block) + inline fun createConicGradient(startAngle: Angle, x0: Number, y0: Number, transform: MMatrix = MMatrix(), block: GradientPaint.() -> Unit = {}) = ConicGradientPaint(startAngle, x0, y0, transform, block) fun createColor(color: RGBA): RGBA = color fun createPattern( bitmap: Bitmap, repeat: Boolean = false, smooth: Boolean = true, - transform: Matrix = Matrix() + transform: MMatrix = MMatrix() ) = createPattern( bitmap, CycleMethod.fromRepeat(repeat), CycleMethod.fromRepeat(repeat), smooth, transform ) @@ -532,7 +532,7 @@ open class Context2d constructor( cycleX: CycleMethod = CycleMethod.NO_CYCLE, cycleY: CycleMethod = cycleX, smooth: Boolean = true, - transform: Matrix = Matrix() + transform: MMatrix = MMatrix() ) = BitmapPaint(bitmap, transform, cycleX, cycleY, smooth) fun getTextBounds( @@ -681,7 +681,7 @@ private fun VectorBuilder.write(path: VectorPath) { ) } -private fun VectorBuilder.write(path: VectorPath, m: Matrix) { +private fun VectorBuilder.write(path: VectorPath, m: MMatrix) { path.visitCmds( moveTo = { x, y -> moveTo(m.transformX(x, y), m.transformY(x, y)) }, lineTo = { x, y -> lineTo(m.transformX(x, y), m.transformY(x, y)) }, diff --git a/korim/src/commonMain/kotlin/com/soywiz/korim/vector/Drawable.kt b/korim/src/commonMain/kotlin/com/soywiz/korim/vector/Drawable.kt index e2076a6727..090d27056c 100644 --- a/korim/src/commonMain/kotlin/com/soywiz/korim/vector/Drawable.kt +++ b/korim/src/commonMain/kotlin/com/soywiz/korim/vector/Drawable.kt @@ -4,15 +4,12 @@ import com.soywiz.kmem.clamp import com.soywiz.kmem.toIntCeil import com.soywiz.korim.bitmap.Bitmap import com.soywiz.korim.bitmap.BitmapWithHotspot -import com.soywiz.korim.bitmap.NativeImage import com.soywiz.korim.bitmap.NativeImageOrBitmap32 import com.soywiz.korim.bitmap.context2d import com.soywiz.korma.geom.ISize -import com.soywiz.korma.geom.Point -import com.soywiz.korma.geom.PointInt -import com.soywiz.korma.geom.Rectangle +import com.soywiz.korma.geom.MPointInt +import com.soywiz.korma.geom.MRectangle import com.soywiz.korma.geom.ScaleMode -import com.soywiz.korma.geom.topLeft interface Drawable { fun draw(c: Context2d) @@ -31,7 +28,7 @@ interface SizedDrawable : Drawable { } interface BoundsDrawable : SizedDrawable { - val bounds: Rectangle + val bounds: MRectangle val left: Int get() = bounds.left.toInt() val top: Int get() = bounds.top.toInt() override val width: Int get() = bounds.width.toInt() @@ -53,7 +50,7 @@ fun BoundsDrawable.renderWithHotspot(scale: Double? = null, fit: ISize? = null, translate(-bounds.x, -bounds.y) draw(this@renderWithHotspot) } - return BitmapWithHotspot(image, PointInt( + return BitmapWithHotspot(image, MPointInt( (-bounds.left * rscale).toInt().clamp(0, image.width - 1), (-bounds.top * rscale).toInt().clamp(0, image.height - 1), )) diff --git a/korim/src/commonMain/kotlin/com/soywiz/korim/vector/NinePatchShape.kt b/korim/src/commonMain/kotlin/com/soywiz/korim/vector/NinePatchShape.kt index c14e46c98b..8790a144de 100644 --- a/korim/src/commonMain/kotlin/com/soywiz/korim/vector/NinePatchShape.kt +++ b/korim/src/commonMain/kotlin/com/soywiz/korim/vector/NinePatchShape.kt @@ -7,7 +7,7 @@ import com.soywiz.korim.util.NinePatchSlices import com.soywiz.korim.util.NinePatchSlices2D import com.soywiz.korma.geom.IPoint import com.soywiz.korma.geom.ISize -import com.soywiz.korma.geom.Point +import com.soywiz.korma.geom.MPoint import com.soywiz.korma.geom.asSize import com.soywiz.korma.geom.bottomRight import com.soywiz.korma.geom.vector.VectorPath @@ -15,7 +15,7 @@ import com.soywiz.korma.geom.vector.VectorPath class NinePatchShape(val shape: Shape, val slices: NinePatchSlices2D) { val size: ISize = shape.bounds.bottomRight.asSize() - fun getScaledPointAt(point: IPoint, newSize: ISize, out: Point = Point()): IPoint = + fun getScaledPointAt(point: IPoint, newSize: ISize, out: MPoint = MPoint()): IPoint = slices.getScaledPointAt(point, size, newSize, out) fun transform(newSize: ISize): Shape { diff --git a/korim/src/commonMain/kotlin/com/soywiz/korim/vector/NinePatchVector.kt b/korim/src/commonMain/kotlin/com/soywiz/korim/vector/NinePatchVector.kt index 4f10eea26d..57d43eb665 100644 --- a/korim/src/commonMain/kotlin/com/soywiz/korim/vector/NinePatchVector.kt +++ b/korim/src/commonMain/kotlin/com/soywiz/korim/vector/NinePatchVector.kt @@ -3,9 +3,9 @@ package com.soywiz.korim.vector import com.soywiz.korim.util.NinePatchSlices2D import com.soywiz.korma.geom.IPoint import com.soywiz.korma.geom.ISize -import com.soywiz.korma.geom.Point +import com.soywiz.korma.geom.MPoint import com.soywiz.korma.geom.PointArrayList -import com.soywiz.korma.geom.Size +import com.soywiz.korma.geom.MSize import com.soywiz.korma.geom.vector.VectorPath class NinePatchVector( @@ -13,10 +13,10 @@ class NinePatchVector( val slices: NinePatchSlices2D, oldSize: ISize? = null ) { - val size = oldSize ?: path.getBounds().let { Size(it.right, it.bottom) } + val size = oldSize ?: path.getBounds().let { MSize(it.right, it.bottom) } private val tempPoints = PointArrayList() - fun getScaledPointAt(point: IPoint, newSize: ISize, out: Point = Point()): IPoint = + fun getScaledPointAt(point: IPoint, newSize: ISize, out: MPoint = MPoint()): IPoint = slices.getScaledPointAt(point, size, newSize, out) private inline fun transformPoints(newSize: ISize, gen: PointArrayList.() -> Unit): PointArrayList { diff --git a/korim/src/commonMain/kotlin/com/soywiz/korim/vector/SDF.kt b/korim/src/commonMain/kotlin/com/soywiz/korim/vector/SDF.kt index c97ce91407..9168ea684a 100644 --- a/korim/src/commonMain/kotlin/com/soywiz/korim/vector/SDF.kt +++ b/korim/src/commonMain/kotlin/com/soywiz/korim/vector/SDF.kt @@ -15,7 +15,7 @@ fun VectorPath.sdf(width: Int, height: Int): FloatArray2 = sdf(FloatArray2(width fun VectorPath.sdf(data: FloatArray2): FloatArray2 { val path = this val curvesList = path.toCurvesList() - val p = Point() + val p = MPoint() val pp = Bezier.ProjectedPoint() for (y in 0 until data.height) { for (x in 0 until data.width) { @@ -61,7 +61,7 @@ fun VectorPath.msdfBmp(width: Int, height: Int): Bitmap32 { fun VectorPath.msdf(data: FloatBitmap32): FloatBitmap32 { val path = this val curvesList = path.toCurvesList() - val p = Point() + val p = MPoint() val colorizedCurves = curvesList.map { it.beziers.colorize(it.closed) } val allColorizedCurves = ColorizedBeziers(colorizedCurves.flatMap { it.beziers }) @@ -114,14 +114,14 @@ class ColorizedBeziers(val beziers: List) { class ProjectCurvesLookup(val beziers: List) { private val tempProjected = Bezier.ProjectedPoint() - private val tempPoint = Point() + private val tempPoint = MPoint() fun closestDistance(point: IPoint): Double { closest(point, tempPoint) - return Point.distance(point, tempPoint) + return MPoint.distance(point, tempPoint) } - fun closest(point: IPoint, out: Point = Point()): IPoint { + fun closest(point: IPoint, out: MPoint = MPoint()): IPoint { if (beziers.isEmpty()) return out.setTo(0, 0) var minDistSq: Double = Double.POSITIVE_INFINITY diff --git a/korim/src/commonMain/kotlin/com/soywiz/korim/vector/Shape.kt b/korim/src/commonMain/kotlin/com/soywiz/korim/vector/Shape.kt index 610d6adea0..1060ad6e94 100644 --- a/korim/src/commonMain/kotlin/com/soywiz/korim/vector/Shape.kt +++ b/korim/src/commonMain/kotlin/com/soywiz/korim/vector/Shape.kt @@ -17,18 +17,10 @@ import com.soywiz.korim.vector.format.SVG import com.soywiz.korim.vector.format.SvgPath import com.soywiz.korio.serialization.xml.Xml import com.soywiz.korio.util.niceStr -import com.soywiz.korma.geom.BoundsBuilder -import com.soywiz.korma.geom.Matrix -import com.soywiz.korma.geom.Rectangle +import com.soywiz.korma.geom.* import com.soywiz.korma.geom.bezier.Curves import com.soywiz.korma.geom.bezier.isConvex -import com.soywiz.korma.geom.contains -import com.soywiz.korma.geom.vector.StrokeInfo -import com.soywiz.korma.geom.vector.VectorPath -import com.soywiz.korma.geom.vector.add -import com.soywiz.korma.geom.vector.applyTransform -import com.soywiz.korma.geom.vector.strokeToFill -import com.soywiz.korma.geom.vector.toCurvesList +import com.soywiz.korma.geom.vector.* import kotlin.math.max import kotlin.math.round @@ -49,7 +41,7 @@ import kotlin.math.round */ class SvgBuilder( - val bounds: Rectangle, + val bounds: MRectangle, val scale: Double, val roundDecimalPlaces: Int = -1 ) { @@ -75,7 +67,7 @@ class SvgBuilder( Xml.Tag("defs", mapOf(), defs), Xml.Tag( "g", - mapOf("transform" to Matrix().translate(-bounds.x, -bounds.y).scale(scale, scale).toSvg(roundDecimalPlaces)), + mapOf("transform" to MMatrix().translate(-bounds.x, -bounds.y).scale(scale, scale).toSvg(roundDecimalPlaces)), nodes ) ) //+ nodes @@ -85,13 +77,13 @@ class SvgBuilder( fun buildSvgXml(width: Int? = null, height: Int? = null, block: ShapeBuilder.() -> Unit): Xml = buildShape(width, height) { block() }.toSvg() -private fun Matrix.toSvg(roundDecimalPlaces: Int = -1): String { +private fun MMatrix.toSvg(roundDecimalPlaces: Int = -1): String { val places = roundDecimalPlaces return when (getType()) { - Matrix.Type.IDENTITY -> "translate()" - Matrix.Type.TRANSLATE -> "translate(${tx.niceStr(places)}, ${ty.niceStr(places)})" - Matrix.Type.SCALE -> "scale(${a.niceStr(places)}, ${d.niceStr(places)})" - Matrix.Type.SCALE_TRANSLATE -> "translate(${tx.niceStr(places)}, ${ty.niceStr(places)}) scale(${a.niceStr(places)}, ${d.niceStr(places)})" + MMatrix.Type.IDENTITY -> "translate()" + MMatrix.Type.TRANSLATE -> "translate(${tx.niceStr(places)}, ${ty.niceStr(places)})" + MMatrix.Type.SCALE -> "scale(${a.niceStr(places)}, ${d.niceStr(places)})" + MMatrix.Type.SCALE_TRANSLATE -> "translate(${tx.niceStr(places)}, ${ty.niceStr(places)}) scale(${a.niceStr(places)}, ${d.niceStr(places)})" else -> "matrix(${a.niceStr(places)}, ${b.niceStr(places)}, ${c.niceStr(places)}, ${d.niceStr(places)}, ${tx.niceStr(places)}, ${ty.niceStr(places)})" } } @@ -133,8 +125,8 @@ sealed interface Shape : BoundsDrawable { fun getPath(path: VectorPath = VectorPath()): VectorPath = path // Unoptimized version - fun getBounds(includeStrokes: Boolean): Rectangle = BoundsBuilder().also { addBounds(it, includeStrokes = includeStrokes) }.getBounds() - override val bounds: Rectangle get() = getBounds(includeStrokes = true) + fun getBounds(includeStrokes: Boolean): MRectangle = BoundsBuilder().also { addBounds(it, includeStrokes = includeStrokes) }.getBounds() + override val bounds: MRectangle get() = getBounds(includeStrokes = true) fun containsPoint(x: Double, y: Double): Boolean = bounds.contains(x, y) } @@ -148,7 +140,7 @@ fun Shape.optimize(): Shape { } } -fun Shape.getBounds(out: Rectangle = Rectangle(), bb: BoundsBuilder = BoundsBuilder(), includeStrokes: Boolean = false): Rectangle { +fun Shape.getBounds(out: MRectangle = MRectangle(), bb: BoundsBuilder = BoundsBuilder(), includeStrokes: Boolean = false): MRectangle { bb.reset() addBounds(bb, includeStrokes) bb.getBounds(out) @@ -172,7 +164,7 @@ interface StyledShape : Shape { val path: VectorPath? get() = null val clip: VectorPath? val paint: Paint - val transform: Matrix + val transform: MMatrix val globalAlpha: Double fun getUntransformedPath(): VectorPath? { @@ -321,7 +313,7 @@ data class FillShape( override val path: VectorPath, override val clip: VectorPath?, override val paint: Paint, - override val transform: Matrix = Matrix(), + override val transform: MMatrix = MMatrix(), override val globalAlpha: Double = 1.0, ) : StyledShape { val pathCurvesList: List by lazy { @@ -351,12 +343,12 @@ data class PolylineShape constructor( override val path: VectorPath, override val clip: VectorPath?, override val paint: Paint, - override val transform: Matrix, + override val transform: MMatrix, val strokeInfo: StrokeInfo, override val globalAlpha: Double = 1.0, ) : StyledShape { private val tempBB = BoundsBuilder() - private val tempRect = Rectangle() + private val tempRect = MRectangle() val thickness by strokeInfo::thickness val scaleMode by strokeInfo::scaleMode @@ -440,7 +432,7 @@ class TextShape( val stroke: Paint?, val halign: HorizontalAlign = HorizontalAlign.LEFT, val valign: VerticalAlign = VerticalAlign.TOP, - override val transform: Matrix = Matrix(), + override val transform: MMatrix = MMatrix(), override val globalAlpha: Double = 1.0, ) : StyledShape { override val paint: Paint get() = fill ?: stroke ?: NonePaint @@ -496,17 +488,17 @@ class TextShape( } } -fun Shape.transformedShape(m: Matrix): Shape = when (this) { +fun Shape.transformedShape(m: MMatrix): Shape = when (this) { is EmptyShape -> EmptyShape is CompoundShape -> CompoundShape(components.map { it.transformedShape(m) }) - is FillShape -> FillShape(path.applyTransform(m), clip?.applyTransform(m), paint, Matrix().multiply(transform, m), globalAlpha) - is PolylineShape -> PolylineShape(path.applyTransform(m), clip?.applyTransform(m), paint, Matrix().multiply(transform, m), strokeInfo, globalAlpha) - is TextShape -> TextShape(text, x, y, font, fontSize, clip?.applyTransform(m), fill, stroke, halign, valign, Matrix().multiply(transform, m), globalAlpha) + is FillShape -> FillShape(path.applyTransform(m), clip?.applyTransform(m), paint, MMatrix().multiply(transform, m), globalAlpha) + is PolylineShape -> PolylineShape(path.applyTransform(m), clip?.applyTransform(m), paint, MMatrix().multiply(transform, m), strokeInfo, globalAlpha) + is TextShape -> TextShape(text, x, y, font, fontSize, clip?.applyTransform(m), fill, stroke, halign, valign, MMatrix().multiply(transform, m), globalAlpha) else -> TODO() } -fun Shape.scaledShape(sx: Double, sy: Double = sx): Shape = transformedShape(Matrix().scale(sx, sy)) -fun Shape.translatedShape(x: Double = 0.0, y: Double = 0.0): Shape = transformedShape(Matrix().translate(x, y)) +fun Shape.scaledShape(sx: Double, sy: Double = sx): Shape = transformedShape(MMatrix().scale(sx, sy)) +fun Shape.translatedShape(x: Double = 0.0, y: Double = 0.0): Shape = transformedShape(MMatrix().translate(x, y)) fun Shape.mapShape(map: (Shape) -> Shape): Shape { val result = map(this) diff --git a/korim/src/commonMain/kotlin/com/soywiz/korim/vector/ShapeBuilder.kt b/korim/src/commonMain/kotlin/com/soywiz/korim/vector/ShapeBuilder.kt index 67e497164c..e93a65c60f 100644 --- a/korim/src/commonMain/kotlin/com/soywiz/korim/vector/ShapeBuilder.kt +++ b/korim/src/commonMain/kotlin/com/soywiz/korim/vector/ShapeBuilder.kt @@ -5,11 +5,7 @@ import com.soywiz.korim.font.Font import com.soywiz.korim.paint.BitmapPaint import com.soywiz.korim.paint.Paint import com.soywiz.korim.vector.renderer.DummyRenderer -import com.soywiz.korma.annotations.KorDslMarker -import com.soywiz.korma.annotations.RootViewDslMarker -import com.soywiz.korma.annotations.VectorDslMarker -import com.soywiz.korma.annotations.ViewDslMarker -import com.soywiz.korma.geom.Matrix +import com.soywiz.korma.geom.MMatrix import com.soywiz.korma.geom.vector.LineCap import com.soywiz.korma.geom.vector.LineJoin import com.soywiz.korma.geom.vector.LineScaleMode @@ -99,12 +95,12 @@ open class ShapeBuilder(width: Int?, height: Int?) : Context2d(DummyRenderer), D ) } - override fun rendererDrawImage(image: Bitmap, x: Double, y: Double, width: Double, height: Double, transform: Matrix) { + override fun rendererDrawImage(image: Bitmap, x: Double, y: Double, width: Double, height: Double, transform: MMatrix) { rendererRender(State( transform = transform, path = VectorPath().apply { rect(x, y, width, height) }, fillStyle = BitmapPaint(image, - transform = Matrix() + transform = MMatrix() .scale(width / image.width.toDouble(), height / image.height.toDouble()) .translate(x, y) ) diff --git a/korim/src/commonMain/kotlin/com/soywiz/korim/vector/chart/ChartBars.kt b/korim/src/commonMain/kotlin/com/soywiz/korim/vector/chart/ChartBars.kt index a452ccd21d..14eaa2eab1 100644 --- a/korim/src/commonMain/kotlin/com/soywiz/korim/vector/chart/ChartBars.kt +++ b/korim/src/commonMain/kotlin/com/soywiz/korim/vector/chart/ChartBars.kt @@ -5,7 +5,7 @@ import com.soywiz.korim.color.RGBA import com.soywiz.korim.text.HorizontalAlign import com.soywiz.korim.text.VerticalAlign import com.soywiz.korim.vector.Context2d -import com.soywiz.korma.geom.Rectangle +import com.soywiz.korma.geom.MRectangle import kotlin.math.ceil import kotlin.math.floor import kotlin.math.log10 @@ -48,7 +48,7 @@ open class ChartBars(val list: List) : Chart() { stroke(createColor(color)) } - private fun Context2d.renderRefLine(rect: Rectangle, y: Double, value: String, important: Boolean) { + private fun Context2d.renderRefLine(rect: MRectangle, y: Double, value: String, important: Boolean) { val x = rect.left renderLine(x, y, rect.right, y, if (important) Colors.BLACK else Colors.DARKGREY) fillText( @@ -64,7 +64,7 @@ open class ChartBars(val list: List) : Chart() { val DataPoint.ratio get() = values.first() / maxValue val DataPoint.rRatio get() = values.first() / rMaxValue - private fun Context2d.renderReferenceLines(rect: Rectangle) { + private fun Context2d.renderReferenceLines(rect: MRectangle) { for (n in 0 until 5) { val ratio = n.toDouble() / 4 renderRefLine( @@ -78,7 +78,7 @@ open class ChartBars(val list: List) : Chart() { enum class Fit(val angle: Double) { FULL(0.0), DEG45(-45.0), DEG90(-90.0) } - fun Context2d.renderBars(rect: Rectangle) { + fun Context2d.renderBars(rect: MRectangle) { val barWidth = rect.width / (list.size * 1.5 + 0.5) val barLeft = barWidth * 0.5 val barSpace = barWidth * 1.5 @@ -121,6 +121,6 @@ open class ChartBars(val list: List) : Chart() { //println("Context2d.renderChart:$width,$height") val hpadding = min(64.0, width * 0.1) val vpadding = min(64.0, height * 0.1) - renderBars(Rectangle.fromBounds(hpadding, vpadding, width - hpadding, height - vpadding)) + renderBars(MRectangle.fromBounds(hpadding, vpadding, width - hpadding, height - vpadding)) } } diff --git a/korim/src/commonMain/kotlin/com/soywiz/korim/vector/format/SVG.kt b/korim/src/commonMain/kotlin/com/soywiz/korim/vector/format/SVG.kt index 435be5f7aa..3c97383370 100644 --- a/korim/src/commonMain/kotlin/com/soywiz/korim/vector/format/SVG.kt +++ b/korim/src/commonMain/kotlin/com/soywiz/korim/vector/format/SVG.kt @@ -22,8 +22,8 @@ import com.soywiz.korio.util.StrReader import com.soywiz.korio.util.isLetterOrDigit import com.soywiz.korio.util.isNumeric import com.soywiz.korio.util.reader -import com.soywiz.korma.geom.Matrix -import com.soywiz.korma.geom.Rectangle +import com.soywiz.korma.geom.MMatrix +import com.soywiz.korma.geom.MRectangle import com.soywiz.korma.geom.shape.getPoints2 import com.soywiz.korma.geom.vector.LineCap import com.soywiz.korma.geom.vector.LineJoin @@ -34,7 +34,6 @@ import com.soywiz.korma.geom.vector.isNotEmpty import com.soywiz.korma.geom.vector.roundRect import com.soywiz.korma.geom.vector.write import kotlin.collections.set -import kotlin.reflect.KMutableProperty1 class SVG(val root: Xml, val warningProcessor: ((message: String) -> Unit)? = null) : SizedDrawable { //constructor(@Language("xml") str: String) : this(Xml(str)) @@ -49,7 +48,7 @@ class SVG(val root: Xml, val warningProcessor: ((message: String) -> Unit)? = nu val dheight = root.double("height", 128.0) val viewBox = root.getString("viewBox") ?: "0 0 $dwidth $dheight" val viewBoxNumbers = viewBox.split(' ').map { it.trim().toDoubleOrNull() ?: 0.0 } - val viewBoxRectangle = Rectangle( + val viewBoxRectangle = MRectangle( viewBoxNumbers.getOrElse(0) { 0.0 }, viewBoxNumbers.getOrElse(1) { 0.0 }, viewBoxNumbers.getOrElse(2) { dwidth }, @@ -111,7 +110,7 @@ class SVG(val root: Xml, val warningProcessor: ((message: String) -> Unit)? = nu "userSpaceOnUse" -> GradientUnits.USER_SPACE_ON_USE else -> GradientUnits.OBJECT_BOUNDING_BOX } - val gradientTransform: Matrix = def.getString("gradientTransform")?.let { CSS.parseTransform(it) } ?: Matrix() + val gradientTransform: MMatrix = def.getString("gradientTransform")?.let { CSS.parseTransform(it) } ?: MMatrix() val spreadMethod = when ((def.getString("spreadMethod") ?: "pad").lowercase()) { "pad" -> CycleMethod.NO_CYCLE "repeat" -> CycleMethod.REPEAT @@ -203,7 +202,7 @@ class SVG(val root: Xml, val warningProcessor: ((message: String) -> Unit)? = nu } val attributes: Map = parseAttributesAndStyles(xml) - var transform: Matrix? = attributes["transform"]?.let { CSS.parseTransform(it) } + var transform: MMatrix? = attributes["transform"]?.let { CSS.parseTransform(it) } var opacity: Double = attributes["opacity"]?.toDoubleOrNull() ?: 1.0 val children = xml.allNodeChildren.mapNotNull { diff --git a/korim/src/commonMain/kotlin/com/soywiz/korim/vector/format/SvgPath.kt b/korim/src/commonMain/kotlin/com/soywiz/korim/vector/format/SvgPath.kt index 6625191bf6..16fe64aea8 100644 --- a/korim/src/commonMain/kotlin/com/soywiz/korim/vector/format/SvgPath.kt +++ b/korim/src/commonMain/kotlin/com/soywiz/korim/vector/format/SvgPath.kt @@ -5,7 +5,7 @@ import com.soywiz.korio.util.StrReader import com.soywiz.korio.util.isDigit import com.soywiz.korio.util.isWhitespaceFast import com.soywiz.korio.util.toStringDecimal -import com.soywiz.korma.geom.Matrix +import com.soywiz.korma.geom.MMatrix import com.soywiz.korma.geom.vector.VectorBuilder import com.soywiz.korma.geom.vector.VectorPath import com.soywiz.korma.geom.vector.rLineTo @@ -349,6 +349,6 @@ object SvgPath { fun VectorPath.toSvgPathString(separator: String = " ", decimalPlaces: Int = 1): String = SvgPath.toSvgPathString(this, separator, decimalPlaces) -fun VectorBuilder.pathSvg(path: String, m: Matrix? = null) { +fun VectorBuilder.pathSvg(path: String, m: MMatrix? = null) { write(SvgPath.parse(path), m) } diff --git a/korim/src/commonMain/kotlin/com/soywiz/korim/vector/rasterizer/Rasterizer.kt b/korim/src/commonMain/kotlin/com/soywiz/korim/vector/rasterizer/Rasterizer.kt index a3c47d0c63..7b17464b78 100644 --- a/korim/src/commonMain/kotlin/com/soywiz/korim/vector/rasterizer/Rasterizer.kt +++ b/korim/src/commonMain/kotlin/com/soywiz/korim/vector/rasterizer/Rasterizer.kt @@ -3,7 +3,7 @@ package com.soywiz.korim.vector.rasterizer import com.soywiz.kds.IntArrayList import com.soywiz.kds.iterators.fastForEach import com.soywiz.korma.annotations.KormaExperimental -import com.soywiz.korma.geom.Rectangle +import com.soywiz.korma.geom.MRectangle import com.soywiz.korma.geom.vector.PolygonScanline import com.soywiz.korma.geom.vector.RastScale import com.soywiz.korma.geom.vector.Winding @@ -16,7 +16,7 @@ typealias RasterizerCallback = (x0: Int, x1: Int, y: Int) -> Unit @OptIn(KormaExperimental::class) class Rasterizer : RastScale() { var debug: Boolean = false - private val tempRect = Rectangle() + private val tempRect = MRectangle() var quality: Int = 2 data class Stats( @@ -53,7 +53,7 @@ class Rasterizer : RastScale() { clip.reset() } - fun rasterizeFill(bounds: Rectangle, quality: Int = this.quality, stats: Stats? = null, winding: Winding = Winding.NON_ZERO, callback: RasterizerCallback) { + fun rasterizeFill(bounds: MRectangle, quality: Int = this.quality, stats: Stats? = null, winding: Winding = Winding.NON_ZERO, callback: RasterizerCallback) { stats?.reset() //for (e in path.edges) println("e: ${e.toString(1.0 / RAST_FIXED_SCALE)}") diff --git a/korim/src/commonMain/kotlin/com/soywiz/korim/vector/renderer/Renderer.kt b/korim/src/commonMain/kotlin/com/soywiz/korim/vector/renderer/Renderer.kt index 8f64629218..e9dfea7bd4 100644 --- a/korim/src/commonMain/kotlin/com/soywiz/korim/vector/renderer/Renderer.kt +++ b/korim/src/commonMain/kotlin/com/soywiz/korim/vector/renderer/Renderer.kt @@ -3,7 +3,7 @@ package com.soywiz.korim.vector.renderer import com.soywiz.korim.bitmap.Bitmap import com.soywiz.korim.paint.BitmapPaint import com.soywiz.korim.vector.Context2d -import com.soywiz.korma.geom.Matrix +import com.soywiz.korma.geom.MMatrix import com.soywiz.korma.geom.vector.VectorPath import com.soywiz.korma.geom.vector.Winding import com.soywiz.korma.geom.vector.rect @@ -41,13 +41,13 @@ abstract class Renderer { y: Double, width: Double = image.width.toDouble(), height: Double = image.height.toDouble(), - transform: Matrix = Matrix() + transform: MMatrix = MMatrix() ) { render( Context2d.State( transform = transform, path = VectorPath().apply { - if (transform.getType() == Matrix.Type.IDENTITY) { + if (transform.getType() == MMatrix.Type.IDENTITY) { rect(x, y, width, height) } else { transformed(transform) { @@ -57,7 +57,7 @@ abstract class Renderer { }, fillStyle = BitmapPaint( image, - transform = Matrix() + transform = MMatrix() .scale(width / image.width.toDouble(), height / image.height.toDouble()) .translate(x, y) ) @@ -67,7 +67,7 @@ abstract class Renderer { inline fun drawImage( image: Bitmap, x: Number, y: Number, width: Number = image.width, height: Number = image.height, - transform: Matrix = Matrix() + transform: MMatrix = MMatrix() ) = drawImage(image, x.toDouble(), y.toDouble(), width.toDouble(), height.toDouble(), transform) open fun dispose() { diff --git a/korim/src/commonTest/kotlin/com/soywiz/korim/RectangleExt.kt b/korim/src/commonTest/kotlin/com/soywiz/korim/RectangleExt.kt index 24d3994055..d35c753622 100644 --- a/korim/src/commonTest/kotlin/com/soywiz/korim/RectangleExt.kt +++ b/korim/src/commonTest/kotlin/com/soywiz/korim/RectangleExt.kt @@ -2,10 +2,10 @@ package com.soywiz.korim import com.soywiz.korim.bitmap.Bitmap32 import com.soywiz.korim.color.Colors -import com.soywiz.korma.geom.Rectangle +import com.soywiz.korma.geom.MRectangle import com.soywiz.korma.geom.bounds -fun Iterable.render(): Bitmap32 { +fun Iterable.render(): Bitmap32 { val colors = listOf(Colors.RED, Colors.GREEN, Colors.BLUE, Colors.BLACK) val bounds = this.bounds() val out = Bitmap32(bounds.width.toInt(), bounds.height.toInt(), premultiplied = false) diff --git a/korim/src/commonTest/kotlin/com/soywiz/korim/bitmap/BitmapResizedTest.kt b/korim/src/commonTest/kotlin/com/soywiz/korim/bitmap/BitmapResizedTest.kt index 111e334f6a..09f2a7b1a9 100644 --- a/korim/src/commonTest/kotlin/com/soywiz/korim/bitmap/BitmapResizedTest.kt +++ b/korim/src/commonTest/kotlin/com/soywiz/korim/bitmap/BitmapResizedTest.kt @@ -4,7 +4,7 @@ import com.soywiz.korim.color.Colors import com.soywiz.korio.async.suspendTest import com.soywiz.korma.geom.Anchor import com.soywiz.korma.geom.ScaleMode -import com.soywiz.korma.geom.Size +import com.soywiz.korma.geom.MSize import kotlin.test.Test import kotlin.test.assertEquals @@ -20,7 +20,7 @@ class BitmapResizedTest { fun testResizedUpTo() = suspendTest { val bmp = Bitmap32(128, 256, Colors.RED) val out = bmp.resizedUpTo(32, 32) - assertEquals(Size(16, 32), out.size) + assertEquals(MSize(16, 32), out.size) //out.writeTo("/tmp/demo.png".uniVfs, PNG) } } diff --git a/korim/src/commonTest/kotlin/com/soywiz/korim/bitmap/DemoTest.kt b/korim/src/commonTest/kotlin/com/soywiz/korim/bitmap/DemoTest.kt index 1ca3622e00..502c7e38b7 100644 --- a/korim/src/commonTest/kotlin/com/soywiz/korim/bitmap/DemoTest.kt +++ b/korim/src/commonTest/kotlin/com/soywiz/korim/bitmap/DemoTest.kt @@ -11,7 +11,7 @@ import com.soywiz.korio.async.suspendTest import com.soywiz.korio.async.suspendTestNoBrowser import com.soywiz.korio.file.std.MemoryVfs import com.soywiz.korio.stream.openAsync -import com.soywiz.korma.geom.Size +import com.soywiz.korma.geom.MSize import com.soywiz.krypto.encoding.fromBase64 import kotlin.native.concurrent.ThreadLocal import kotlin.test.Test @@ -33,7 +33,7 @@ class DemoTest { @Test fun test2() = suspendTest { - assertEquals(Size(8, 8), debugBmpFont.glyphs.values.first()!!.bmp.size) + assertEquals(MSize(8, 8), debugBmpFont.glyphs.values.first()!!.bmp.size) } } diff --git a/korim/src/commonTest/kotlin/com/soywiz/korim/bitmap/NativeImageTest.kt b/korim/src/commonTest/kotlin/com/soywiz/korim/bitmap/NativeImageTest.kt index 1da2d7847a..bf96cf0d17 100644 --- a/korim/src/commonTest/kotlin/com/soywiz/korim/bitmap/NativeImageTest.kt +++ b/korim/src/commonTest/kotlin/com/soywiz/korim/bitmap/NativeImageTest.kt @@ -6,7 +6,7 @@ import com.soywiz.korim.color.RgbaArray import com.soywiz.korim.vector.buildShape import com.soywiz.korim.vector.render import com.soywiz.korio.async.suspendTest -import com.soywiz.korma.geom.Size +import com.soywiz.korma.geom.MSize import com.soywiz.korma.geom.vector.Winding import com.soywiz.korma.geom.vector.circle import kotlin.test.Test @@ -74,7 +74,7 @@ class NativeImageTest { circle(50, 50, 25) } }.render() - assertEquals(Size(100, 100), image.size) + assertEquals(MSize(100, 100), image.size) assertEquals(1.0, image.getRgbaRaw(10, 50).ad) assertEquals(0.0, image.getRgbaRaw(50, 50).ad) } @@ -87,7 +87,7 @@ class NativeImageTest { circle(50, 50, 25) } }.render() - assertEquals(Size(100, 100), image.size) + assertEquals(MSize(100, 100), image.size) assertEquals(1.0, image.getRgbaRaw(10, 50).ad) assertEquals(1.0, image.getRgbaRaw(50, 50).ad) } diff --git a/korim/src/commonTest/kotlin/com/soywiz/korim/bitmap/trace/BitmapTracerTest.kt b/korim/src/commonTest/kotlin/com/soywiz/korim/bitmap/trace/BitmapTracerTest.kt index 2b0e0a008e..727d86d704 100644 --- a/korim/src/commonTest/kotlin/com/soywiz/korim/bitmap/trace/BitmapTracerTest.kt +++ b/korim/src/commonTest/kotlin/com/soywiz/korim/bitmap/trace/BitmapTracerTest.kt @@ -3,7 +3,7 @@ package com.soywiz.korim.bitmap.trace import com.soywiz.korim.bitmap.Bitmap32 import com.soywiz.korim.bitmap.context2d import com.soywiz.korim.color.Colors -import com.soywiz.korma.geom.Rectangle +import com.soywiz.korma.geom.MRectangle import com.soywiz.korma.geom.vector.Winding import com.soywiz.korma.geom.vector.circle import com.soywiz.korma.geom.vector.rect @@ -17,10 +17,10 @@ class BitmapTracerTest { fun testSmokeTrace() { val bmp = Bitmap32(300, 200, premultiplied = true).context2d { fill(Colors.WHITE, winding = Winding.EVEN_ODD) { - rect(Rectangle.fromBounds(2, 2, 18, 18)) - rectHole(Rectangle.fromBounds(6, 6, 9, 12)) - rectHole(Rectangle.fromBounds(10, 5, 15, 12)) - rect(Rectangle.fromBounds(50, 2, 68, 18)) + rect(MRectangle.fromBounds(2, 2, 18, 18)) + rectHole(MRectangle.fromBounds(6, 6, 9, 12)) + rectHole(MRectangle.fromBounds(10, 5, 15, 12)) + rect(MRectangle.fromBounds(50, 2, 68, 18)) circle(100, 100, 40) circle(100, 100, 20) roundRect(200, 50, 50, 50, 5, 5) diff --git a/korim/src/commonTest/kotlin/com/soywiz/korim/bitmap/vector/Bitmap32Context2dTest.kt b/korim/src/commonTest/kotlin/com/soywiz/korim/bitmap/vector/Bitmap32Context2dTest.kt index 262b6b8fb2..a8e71ef2a2 100644 --- a/korim/src/commonTest/kotlin/com/soywiz/korim/bitmap/vector/Bitmap32Context2dTest.kt +++ b/korim/src/commonTest/kotlin/com/soywiz/korim/bitmap/vector/Bitmap32Context2dTest.kt @@ -14,7 +14,7 @@ import com.soywiz.korim.paint.* import com.soywiz.korio.async.suspendTest import com.soywiz.korio.util.OS import com.soywiz.korma.geom.IPoint -import com.soywiz.korma.geom.Matrix +import com.soywiz.korma.geom.MMatrix import com.soywiz.korma.geom.vector.VectorBuilder import com.soywiz.korma.geom.vector.lineTo import com.soywiz.korma.geom.vector.moveTo @@ -48,7 +48,7 @@ class Bitmap32Context2dTest { //32.0, 8.0, 1.0, stops = DoubleArrayList(0.0, 1.0), colors = IntArrayList(Colors.BLUE.value, Colors.RED.value), - transform = Matrix().scale(2.0, 0.75) + transform = MMatrix().scale(2.0, 0.75) ) ) if (true) { @@ -88,7 +88,7 @@ class Bitmap32Context2dTest { val rendered = NativeImage(128, 128).context2d { rect(0, 0, 100, 100) - fill(BitmapPaint(img, Matrix())) + fill(BitmapPaint(img, MMatrix())) } val bmp = rendered.toBMP32() diff --git a/korim/src/commonTest/kotlin/com/soywiz/korim/font/TTfTest.kt b/korim/src/commonTest/kotlin/com/soywiz/korim/font/TTfTest.kt index 6822588d79..2ed3f9bdef 100644 --- a/korim/src/commonTest/kotlin/com/soywiz/korim/font/TTfTest.kt +++ b/korim/src/commonTest/kotlin/com/soywiz/korim/font/TTfTest.kt @@ -3,7 +3,7 @@ package com.soywiz.korim.font import com.soywiz.korio.async.suspendTest import com.soywiz.korio.file.std.resourcesVfs import com.soywiz.korio.lang.* -import com.soywiz.korma.geom.Rectangle +import com.soywiz.korma.geom.MRectangle import kotlin.test.* class TTfTest { @@ -17,7 +17,7 @@ class TTfTest { val colorPath = glyph.colorEntry!!.getColorShape() assertEquals(1275, glyph.advanceWidth) assertEquals( - Rectangle(x = 32, y = -256, width = 1216, height = 1216), + MRectangle(x = 32, y = -256, width = 1216, height = 1216), glyph.metrics1px.bounds ) //colorPath.scaled(0.01, 0.01).render().showImageAndWait() diff --git a/korim/src/commonTest/kotlin/com/soywiz/korim/format/ASETest.kt b/korim/src/commonTest/kotlin/com/soywiz/korim/format/ASETest.kt index 1dff02f74d..5d6ad6c4f8 100644 --- a/korim/src/commonTest/kotlin/com/soywiz/korim/format/ASETest.kt +++ b/korim/src/commonTest/kotlin/com/soywiz/korim/format/ASETest.kt @@ -8,7 +8,7 @@ import com.soywiz.korio.async.suspendTest import com.soywiz.korio.file.std.resourcesVfs import com.soywiz.korio.util.OS import com.soywiz.korma.geom.RectangleInt -import com.soywiz.korma.geom.Size +import com.soywiz.korma.geom.MSize import kotlin.test.* class ASETest { @@ -114,7 +114,7 @@ class ASETest { listOf(0, 1, 2, 3, 4, 5, 6, 7, 8), tileSet.texturesMap.keys.toList().sorted() ) - assertEquals(Size(16, 144), tileSet.base.size) + assertEquals(MSize(16, 144), tileSet.base.size) for (n in 0..8) { assertEquals(RectangleInt(0, (n * 16), 16, 16), tileSet.texturesMap[n]!!.slice.rect) } diff --git a/korim/src/commonTest/kotlin/com/soywiz/korim/format/JPEGInfoTest.kt b/korim/src/commonTest/kotlin/com/soywiz/korim/format/JPEGInfoTest.kt index 717dbbd92b..3e6823f00e 100644 --- a/korim/src/commonTest/kotlin/com/soywiz/korim/format/JPEGInfoTest.kt +++ b/korim/src/commonTest/kotlin/com/soywiz/korim/format/JPEGInfoTest.kt @@ -2,7 +2,7 @@ package com.soywiz.korim.format import com.soywiz.korio.async.suspendTest import com.soywiz.korio.file.std.resourcesVfs -import com.soywiz.korma.geom.Size +import com.soywiz.korma.geom.MSize import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertNotNull @@ -12,7 +12,7 @@ class JPEGInfoTest { fun test() = suspendTest { val header = resourcesVfs["Portrait_3.jpg"].readImageInfo(JPEGInfo) assertNotNull(header) - assertEquals(Size(1800, 1200), header.size) + assertEquals(MSize(1800, 1200), header.size) assertEquals(ImageOrientation.ROTATE_180, header.orientation) } @@ -20,7 +20,7 @@ class JPEGInfoTest { fun test2() = suspendTest { val header = resourcesVfs["exif1.jpeg"].readImageInfo(JPEGInfo) assertNotNull(header) - assertEquals(Size(3024, 4032), header.size) + assertEquals(MSize(3024, 4032), header.size) assertEquals(ImageOrientation.ROTATE_180, header.orientation) } } diff --git a/korim/src/commonTest/kotlin/com/soywiz/korim/format/NativeEncodingTest.kt b/korim/src/commonTest/kotlin/com/soywiz/korim/format/NativeEncodingTest.kt index 5fd1ee3115..9d7b89dde5 100644 --- a/korim/src/commonTest/kotlin/com/soywiz/korim/format/NativeEncodingTest.kt +++ b/korim/src/commonTest/kotlin/com/soywiz/korim/format/NativeEncodingTest.kt @@ -13,7 +13,7 @@ class NativeEncodingTest { fun test() = suspendTest { if (Platform.isJsNodeJs) RegisteredImageFormats.register(PNG) val bytes = nativeImageFormatProvider.encodeSuspend(Bitmap32(10, 10, Colors.RED), ImageEncodingProps("image.png")) - assertEquals(Size(10, 10), PNG.decodeHeader(bytes.openSync())!!.size) + assertEquals(MSize(10, 10), PNG.decodeHeader(bytes.openSync())!!.size) val image = nativeImageFormatProvider.decodeSuspend(bytes) assertEquals(Colors.RED, image.toBMP32()[0, 0]) diff --git a/korim/src/commonTest/kotlin/com/soywiz/korim/paint/GradientPaintTest.kt b/korim/src/commonTest/kotlin/com/soywiz/korim/paint/GradientPaintTest.kt index efb8d7c78e..66fd006da3 100644 --- a/korim/src/commonTest/kotlin/com/soywiz/korim/paint/GradientPaintTest.kt +++ b/korim/src/commonTest/kotlin/com/soywiz/korim/paint/GradientPaintTest.kt @@ -5,7 +5,7 @@ import com.soywiz.korim.color.RGBA import com.soywiz.korim.color.RgbaArray import com.soywiz.korim.vector.Context2d import com.soywiz.korim.vector.CycleMethod -import com.soywiz.korma.geom.Matrix +import com.soywiz.korma.geom.MMatrix import kotlin.test.Test import kotlin.test.assertEquals @@ -16,8 +16,8 @@ class GradientPaintTest { run { val filler = GradientFiller().set( - LinearGradientPaint(0.0, 0.0, 100.0, 100.0, transform = Matrix().scale(0.5).pretranslate(300, 0)), - Context2d.State(transform = Matrix(a = 2.0, b = 0.0, c = 0.0, d = 2.0, tx = 100.0, ty = 20.0)) + LinearGradientPaint(0.0, 0.0, 100.0, 100.0, transform = MMatrix().scale(0.5).pretranslate(300, 0)), + Context2d.State(transform = MMatrix(a = 2.0, b = 0.0, c = 0.0, d = 2.0, tx = 100.0, ty = 20.0)) ) assertEquals(-0.5, filler.getRatio(300.0, 20.0), absoluteTolerance = 0.1) assertEquals(1.5, filler.getRatio(500.0, 220.0), absoluteTolerance = 0.1) @@ -25,7 +25,7 @@ class GradientPaintTest { run { val filler = GradientFiller().set( LinearGradientPaint(150.0, 0.0, 200.0, 50.0), - Context2d.State(transform = Matrix(a = 2.0, b = 0.0, c = 0.0, d = 2.0, tx = 100.0, ty = 20.0)) + Context2d.State(transform = MMatrix(a = 2.0, b = 0.0, c = 0.0, d = 2.0, tx = 100.0, ty = 20.0)) ) assertEquals(-0.5, filler.getRatio(300.0, 20.0), absoluteTolerance = 0.1) assertEquals(1.5, filler.getRatio(500.0, 220.0), absoluteTolerance = 0.1) @@ -37,7 +37,7 @@ class GradientPaintTest { run { val filler = GradientFiller().set( RadialGradientPaint(150, 150, 30, 130, 180, 70), - Context2d.State(transform = Matrix(a = 2.0, b = 0.0, c = 0.0, d = 2.0, tx = 100.0, ty = 20.0)) + Context2d.State(transform = MMatrix(a = 2.0, b = 0.0, c = 0.0, d = 2.0, tx = 100.0, ty = 20.0)) ) assertEquals(2.038292349534667, filler.getRatio(300.0, 220.0), absoluteTolerance = 0.01) assertEquals(-0.39444872453601043, filler.getRatio(400.0, 320.0), absoluteTolerance = 0.01) diff --git a/korim/src/commonTest/kotlin/com/soywiz/korim/qr/QRTest.kt b/korim/src/commonTest/kotlin/com/soywiz/korim/qr/QRTest.kt index ce2489f272..9f552d4ef0 100644 --- a/korim/src/commonTest/kotlin/com/soywiz/korim/qr/QRTest.kt +++ b/korim/src/commonTest/kotlin/com/soywiz/korim/qr/QRTest.kt @@ -1,6 +1,6 @@ package com.soywiz.korim.qr -import com.soywiz.korma.geom.Size +import com.soywiz.korma.geom.MSize import kotlin.test.Test import kotlin.test.assertEquals @@ -8,6 +8,6 @@ class QRTest { @Test fun name() { val img = QR().email("test@test.com") - assertEquals(Size(29, 29), img.size) + assertEquals(MSize(29, 29), img.size) } } diff --git a/korim/src/commonTest/kotlin/com/soywiz/korim/style/CSSTest.kt b/korim/src/commonTest/kotlin/com/soywiz/korim/style/CSSTest.kt index ec494b6b94..f903cfcc00 100644 --- a/korim/src/commonTest/kotlin/com/soywiz/korim/style/CSSTest.kt +++ b/korim/src/commonTest/kotlin/com/soywiz/korim/style/CSSTest.kt @@ -31,7 +31,7 @@ class CSSTest { @Test fun test2() { assertEquals( - Matrix(a=-1.0, b=0.0, c=0.0, d=-1.0, tx=132.47, ty=97.81), + MMatrix(a=-1.0, b=0.0, c=0.0, d=-1.0, tx=132.47, ty=97.81), CSS.parseTransform("matrix(-1 0 0-1 132.47 97.81)") ) } diff --git a/korim/src/commonTest/kotlin/com/soywiz/korim/text/RichTextDataPlacementTest.kt b/korim/src/commonTest/kotlin/com/soywiz/korim/text/RichTextDataPlacementTest.kt index 773b6f2250..699180ce00 100644 --- a/korim/src/commonTest/kotlin/com/soywiz/korim/text/RichTextDataPlacementTest.kt +++ b/korim/src/commonTest/kotlin/com/soywiz/korim/text/RichTextDataPlacementTest.kt @@ -23,7 +23,7 @@ class RichTextDataPlacementTest { val texts = fonts.map { RichTextData("HELLO WORLD", font = it, textSize = 32.0) } - val placements = texts.map { it.place(Rectangle(0, 0, 300, 100), align = TextAlignment.MIDDLE_CENTER) } + val placements = texts.map { it.place(MRectangle(0, 0, 300, 100), align = TextAlignment.MIDDLE_CENTER) } for (font in fonts) logger.debug { font.naturalFontMetrics } diff --git a/korim/src/commonTest/kotlin/com/soywiz/korim/text/RichTextDataRendererText.kt b/korim/src/commonTest/kotlin/com/soywiz/korim/text/RichTextDataRendererText.kt index 951fa7a523..2db9506fac 100644 --- a/korim/src/commonTest/kotlin/com/soywiz/korim/text/RichTextDataRendererText.kt +++ b/korim/src/commonTest/kotlin/com/soywiz/korim/text/RichTextDataRendererText.kt @@ -2,8 +2,6 @@ package com.soywiz.korim.text import com.soywiz.korim.bitmap.* import com.soywiz.korim.color.* -import com.soywiz.korim.font.* -import com.soywiz.korim.format.* import com.soywiz.korio.async.* import com.soywiz.korma.geom.* import com.soywiz.korma.geom.vector.* @@ -14,7 +12,7 @@ class RichTextDataRendererText { fun test() = suspendTest { val nativeImage = NativeImage(512, 512) nativeImage.context2d { - val textBounds = Rectangle(50, 50, 150, 100) + val textBounds = MRectangle(50, 50, 150, 100) stroke(Colors.BLUE, lineWidth = 2.0) { rect(textBounds) } diff --git a/korim/src/commonTest/kotlin/com/soywiz/korim/util/NinePatchToolsTest.kt b/korim/src/commonTest/kotlin/com/soywiz/korim/util/NinePatchToolsTest.kt index 0f1f6ab5e1..cae8c0613d 100644 --- a/korim/src/commonTest/kotlin/com/soywiz/korim/util/NinePatchToolsTest.kt +++ b/korim/src/commonTest/kotlin/com/soywiz/korim/util/NinePatchToolsTest.kt @@ -2,7 +2,7 @@ package com.soywiz.korim.util import com.soywiz.kds.DoubleArrayList import com.soywiz.kds.doubleArrayListOf -import com.soywiz.korma.geom.Size +import com.soywiz.korma.geom.MSize import com.soywiz.korma.geom.pointArrayListOf import com.soywiz.korma.geom.range.until import kotlin.test.Test @@ -44,8 +44,8 @@ class NinePatchToolsTest { pointArrayListOf(10.0, 10.0), pointArrayListOf(15.0, 15.0), ), - oldSize = Size(15.0, 15.0), - newSize = Size(32.0, 64.0) + oldSize = MSize(15.0, 15.0), + newSize = MSize(32.0, 64.0) ) assertEquals( diff --git a/korim/src/commonTest/kotlin/com/soywiz/korim/vector/NinePatchShapeTest.kt b/korim/src/commonTest/kotlin/com/soywiz/korim/vector/NinePatchShapeTest.kt index 1aaae30ec6..5db06034b2 100644 --- a/korim/src/commonTest/kotlin/com/soywiz/korim/vector/NinePatchShapeTest.kt +++ b/korim/src/commonTest/kotlin/com/soywiz/korim/vector/NinePatchShapeTest.kt @@ -6,7 +6,7 @@ import com.soywiz.korim.util.NinePatchSlices2D import com.soywiz.korim.vector.format.readSVG import com.soywiz.korio.async.suspendTest import com.soywiz.korio.file.std.resourcesVfs -import com.soywiz.korma.geom.Size +import com.soywiz.korma.geom.MSize import com.soywiz.korma.geom.range.until import kotlin.test.Test import kotlin.test.assertEquals @@ -16,7 +16,7 @@ class NinePatchShapeTest { @Test fun test() = suspendTest { val ninePatch = resourcesVfs["chat-bubble.svg"].readSVG().toShape().toNinePatchFromGuides(guideColor = Colors.FUCHSIA) - assertEquals(Size(128, 128), ninePatch.size) + assertEquals(MSize(128, 128), ninePatch.size) assertEquals(NinePatchSlices2D( NinePatchSlices(30.0 until 33.0, 80.0 until 100.0), NinePatchSlices(40.0 until 80.0) diff --git a/korim/src/commonTest/kotlin/com/soywiz/korim/vector/NinePatchVectorTest.kt b/korim/src/commonTest/kotlin/com/soywiz/korim/vector/NinePatchVectorTest.kt index 11e14948ed..c14a1a26e2 100644 --- a/korim/src/commonTest/kotlin/com/soywiz/korim/vector/NinePatchVectorTest.kt +++ b/korim/src/commonTest/kotlin/com/soywiz/korim/vector/NinePatchVectorTest.kt @@ -1,6 +1,6 @@ package com.soywiz.korim.vector -import com.soywiz.korma.geom.Size +import com.soywiz.korma.geom.MSize import com.soywiz.korma.geom.shape.buildVectorPath import com.soywiz.korma.geom.vector.rect import com.soywiz.korma.geom.vector.roundRect @@ -20,8 +20,8 @@ class NinePatchVectorTest { M0,0 L100,0 L100,100 L0,100 Z """.trimIndent(), """ - ${vector.scaleNinePatch(Size(200, 200)).toSvgString()} - ${vector.scaleNinePatch(Size(50, 50)).toSvgString()} + ${vector.scaleNinePatch(MSize(200, 200)).toSvgString()} + ${vector.scaleNinePatch(MSize(50, 50)).toSvgString()} ${vector.toSvgString()} """.trimIndent() @@ -39,7 +39,7 @@ class NinePatchVectorTest { M25,0 L75,0 Q100,0,100,24 L100,75 Q100,100,75,100 L24,100 Q0,100,0,75 L0,24 Q0,0,24,0 Z """.trimIndent(), """ - ${vector.scaleNinePatch(Size(200, 200)).roundDecimalPlaces(1).toSvgString()} + ${vector.scaleNinePatch(MSize(200, 200)).roundDecimalPlaces(1).toSvgString()} ${vector.toSvgString()} """.trimIndent() @@ -58,8 +58,8 @@ class NinePatchVectorTest { M25,0 L75,0 Q100,0,100,24 L100,75 Q100,100,75,100 L24,100 Q0,100,0,75 L0,24 Q0,0,24,0 Z """.trimIndent(), """ - ${vector.scaleNinePatch(Size(50, 50)).roundDecimalPlaces(1).toSvgString()} - ${vector.scaleNinePatch(Size(50, 10)).roundDecimalPlaces(1).toSvgString()} + ${vector.scaleNinePatch(MSize(50, 50)).roundDecimalPlaces(1).toSvgString()} + ${vector.scaleNinePatch(MSize(50, 10)).roundDecimalPlaces(1).toSvgString()} ${vector.toSvgString()} """.trimIndent() diff --git a/korim/src/commonTest/kotlin/com/soywiz/korim/vector/ShapeTest.kt b/korim/src/commonTest/kotlin/com/soywiz/korim/vector/ShapeTest.kt index 51298361f6..0898faf9bf 100644 --- a/korim/src/commonTest/kotlin/com/soywiz/korim/vector/ShapeTest.kt +++ b/korim/src/commonTest/kotlin/com/soywiz/korim/vector/ShapeTest.kt @@ -1,8 +1,8 @@ package com.soywiz.korim.vector import com.soywiz.korim.color.Colors -import com.soywiz.korma.geom.Matrix -import com.soywiz.korma.geom.Rectangle +import com.soywiz.korma.geom.MMatrix +import com.soywiz.korma.geom.MRectangle import com.soywiz.korma.geom.shape.buildVectorPath import com.soywiz.korma.geom.vector.StrokeInfo import com.soywiz.korma.geom.vector.VectorBuilder @@ -26,7 +26,7 @@ class ShapeTest { clip = null, paint = Colors.GREEN, //paint = BitmapPaint(Bitmap32(100, 100, Colors.RED, premultiplied = false), Matrix()), - transform = Matrix() + transform = MMatrix() ) assertEquals( //"""""", @@ -42,7 +42,7 @@ class ShapeTest { scale(2, 2) translate(200, 100) fill( - createLinearGradient(50, 50, 75, 120, transform = Matrix(2, 0, 0, 2)).addColorStop(0.0, Colors.RED) + createLinearGradient(50, 50, 75, 120, transform = MMatrix(2, 0, 0, 2)).addColorStop(0.0, Colors.RED) .addColorStop(1.0, Colors.BLUE) ) { rect(50, 10, 300, 200) @@ -61,7 +61,7 @@ class ShapeTest { @Test fun testEmptyBounds() { - fun createStrokeShape(block: VectorBuilder.() -> Unit): PolylineShape = PolylineShape(buildVectorPath { block() }, null, Colors.RED, Matrix(), StrokeInfo()) + fun createStrokeShape(block: VectorBuilder.() -> Unit): PolylineShape = PolylineShape(buildVectorPath { block() }, null, Colors.RED, MMatrix(), StrokeInfo()) val shape1 = createStrokeShape { moveTo(100, 100) } val shape2 = createStrokeShape { moveTo(100, 100); lineTo(200, 100) } val shape3 = createStrokeShape { moveTo(100, 100); lineTo(200, 200) } @@ -69,12 +69,12 @@ class ShapeTest { assertEquals(shape2.bounds, shape2.getBounds(includeStrokes = true)) assertEquals(shape3.bounds, shape3.getBounds(includeStrokes = true)) - assertEquals(Rectangle(100, 100, 0, 0), shape1.getBounds(includeStrokes = false)) - assertEquals(Rectangle(100, 100, 100, 0), shape2.getBounds(includeStrokes = false)) - assertEquals(Rectangle(100, 100, 100, 100), shape3.getBounds(includeStrokes = false)) + assertEquals(MRectangle(100, 100, 0, 0), shape1.getBounds(includeStrokes = false)) + assertEquals(MRectangle(100, 100, 100, 0), shape2.getBounds(includeStrokes = false)) + assertEquals(MRectangle(100, 100, 100, 100), shape3.getBounds(includeStrokes = false)) - assertEquals(Rectangle(99.5, 99.5, 1.0, 1.0), shape1.getBounds(includeStrokes = true)) - assertEquals(Rectangle(99.5, 99.5, 101.0, 1.0), shape2.getBounds(includeStrokes = true)) - assertEquals(Rectangle(99.5, 99.5, 101.0, 101.0), shape3.getBounds(includeStrokes = true)) + assertEquals(MRectangle(99.5, 99.5, 1.0, 1.0), shape1.getBounds(includeStrokes = true)) + assertEquals(MRectangle(99.5, 99.5, 101.0, 1.0), shape2.getBounds(includeStrokes = true)) + assertEquals(MRectangle(99.5, 99.5, 101.0, 101.0), shape3.getBounds(includeStrokes = true)) } } diff --git a/korim/src/commonTest/kotlin/com/soywiz/korim/vector/rasterizer/RasterizerTest.kt b/korim/src/commonTest/kotlin/com/soywiz/korim/vector/rasterizer/RasterizerTest.kt index 8b53576dd5..c5d5fcd599 100644 --- a/korim/src/commonTest/kotlin/com/soywiz/korim/vector/rasterizer/RasterizerTest.kt +++ b/korim/src/commonTest/kotlin/com/soywiz/korim/vector/rasterizer/RasterizerTest.kt @@ -7,7 +7,7 @@ import com.soywiz.korim.color.Colors import com.soywiz.korim.color.RGBA import com.soywiz.korio.async.suspendTest import com.soywiz.korio.util.niceStr -import com.soywiz.korma.geom.Rectangle +import com.soywiz.korma.geom.MRectangle import com.soywiz.korma.geom.cosine import com.soywiz.korma.geom.degrees import com.soywiz.korma.geom.sine @@ -43,7 +43,7 @@ class RasterizerTest { rast.path.close() val log = arrayListOf() val stats = Rasterizer.Stats() - rast.rasterizeFill(Rectangle(0, 0, 10, 10), quality = 8, stats = stats) { a, b, y -> + rast.rasterizeFill(MRectangle(0, 0, 10, 10), quality = 8, stats = stats) { a, b, y -> log += "rast(${(a.toDouble() / RastScale.RAST_FIXED_SCALE).niceStr}, ${(a.toDouble() / RastScale.RAST_FIXED_SCALE).niceStr}, ${(a.toDouble() / RastScale.RAST_FIXED_SCALE).niceStr})" //println(log.last()) } diff --git a/korim/src/darwinMain/kotlin/com/soywiz/korim/format/cg/CgExt.kt b/korim/src/darwinMain/kotlin/com/soywiz/korim/format/cg/CgExt.kt index 48a48b066b..71d808f738 100644 --- a/korim/src/darwinMain/kotlin/com/soywiz/korim/format/cg/CgExt.kt +++ b/korim/src/darwinMain/kotlin/com/soywiz/korim/format/cg/CgExt.kt @@ -1,8 +1,8 @@ package com.soywiz.korim.format.cg -import com.soywiz.korma.geom.Rectangle +import com.soywiz.korma.geom.MRectangle import kotlinx.cinterop.CValue import platform.CoreGraphics.CGRect import platform.CoreGraphics.CGRectMake -fun Rectangle.toCG(): CValue = CGRectMake(x.cg, y.cg, width.cg, height.cg) +fun MRectangle.toCG(): CValue = CGRectMake(x.cg, y.cg, width.cg, height.cg) diff --git a/korim/src/darwinMain/kotlin/com/soywiz/korim/format/cg/CgRenderer.kt b/korim/src/darwinMain/kotlin/com/soywiz/korim/format/cg/CgRenderer.kt index efd091ceb5..37eeda2524 100644 --- a/korim/src/darwinMain/kotlin/com/soywiz/korim/format/cg/CgRenderer.kt +++ b/korim/src/darwinMain/kotlin/com/soywiz/korim/format/cg/CgRenderer.kt @@ -5,10 +5,8 @@ package com.soywiz.korim.format.cg import com.soywiz.kmem.* import com.soywiz.korim.bitmap.* import com.soywiz.korim.color.* -import com.soywiz.korim.font.* import com.soywiz.korim.vector.* import com.soywiz.korim.format.* -import com.soywiz.korim.internal.* import com.soywiz.korim.paint.* import com.soywiz.korma.geom.* import com.soywiz.korma.geom.vector.* @@ -128,7 +126,7 @@ class CoreGraphicsRenderer(val bmp: Bitmap32, val antialiasing: Boolean) : com.s override val width: Int get() = bmp.width override val height: Int get() = bmp.height - fun Matrix.toCGAffineTransform() = CGAffineTransformMake(a.cg, b.cg, c.cg, d.cg, tx.cg, ty.cg) + fun MMatrix.toCGAffineTransform() = CGAffineTransformMake(a.cg, b.cg, c.cg, d.cg, tx.cg, ty.cg) private fun cgDrawBitmap(bmp: Bitmap32, ctx: CGContextRef?, colorSpace: CPointer?, tiled: Boolean = false) { val image = transferBitmap32ToCGImage(bmp, colorSpace) diff --git a/korim/src/jsMain/kotlin/com/soywiz/korim/format/NativeImageFormatProviderJs.kt b/korim/src/jsMain/kotlin/com/soywiz/korim/format/NativeImageFormatProviderJs.kt index 022a03bec1..31c87d1c09 100644 --- a/korim/src/jsMain/kotlin/com/soywiz/korim/format/NativeImageFormatProviderJs.kt +++ b/korim/src/jsMain/kotlin/com/soywiz/korim/format/NativeImageFormatProviderJs.kt @@ -366,7 +366,7 @@ class CanvasContext2dRenderer(private val canvas: HTMLCanvasElementLike) : Rende } } - fun CanvasTransform.transform(m: Matrix) { + fun CanvasTransform.transform(m: MMatrix) { transform(m.a, m.b, m.c, m.d, m.tx, m.ty) } @@ -378,7 +378,7 @@ class CanvasContext2dRenderer(private val canvas: HTMLCanvasElementLike) : Rende } } - override fun drawImage(image: Bitmap, x: Double, y: Double, width: Double, height: Double, transform: Matrix) { + override fun drawImage(image: Bitmap, x: Double, y: Double, width: Double, height: Double, transform: MMatrix) { ctx.save() try { transform.run { ctx.setTransform(a, b, c, d, tx, ty) } diff --git a/korim/src/jvmMain/kotlin/com/soywiz/korim/awt/AwtExt.kt b/korim/src/jvmMain/kotlin/com/soywiz/korim/awt/AwtExt.kt index b1cc35f3ed..0a823efa4a 100644 --- a/korim/src/jvmMain/kotlin/com/soywiz/korim/awt/AwtExt.kt +++ b/korim/src/jvmMain/kotlin/com/soywiz/korim/awt/AwtExt.kt @@ -4,9 +4,8 @@ import com.soywiz.kmem.* import com.soywiz.korim.bitmap.* import com.soywiz.korim.color.* import com.soywiz.korim.format.* -import com.soywiz.korio.async.* import com.soywiz.korma.geom.* -import com.soywiz.korma.geom.Rectangle +import com.soywiz.korma.geom.MRectangle import kotlinx.coroutines.* import java.awt.* import java.awt.Point @@ -66,7 +65,7 @@ fun awtShowImage(image: BufferedImage): JFrame { (g as? Graphics2D)?.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC) (g as? Graphics2D)?.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY) val scaleMode = ScaleMode.SHOW_ALL - val imageSize = Size(image.width, image.height) + val imageSize = MSize(image.width, image.height) val containerSize = g.clipBounds.toKorma() val out = containerSize.place(imageSize, Anchor.MIDDLE_CENTER, scaleMode).toInt() g.drawImage(image, out.x, out.y, out.width, out.height, null) @@ -90,10 +89,10 @@ fun awtShowImage(image: BufferedImage): JFrame { } // @TODO: Move to KorMA -private fun java.awt.Rectangle.toKorma(): Rectangle = Rectangle(this.x, this.y, this.width, this.height) +private fun java.awt.Rectangle.toKorma(): MRectangle = MRectangle(this.x, this.y, this.width, this.height) // @TODO: Move to KorMA -private fun Rectangle.place(item: Size, anchor: Anchor, scale: ScaleMode, out: Rectangle = Rectangle()): Rectangle { +private fun MRectangle.place(item: MSize, anchor: Anchor, scale: ScaleMode, out: MRectangle = MRectangle()): MRectangle { val outSize = scale(item, this.size) val x = (this.width - outSize.width) * anchor.sx val y = (this.height - outSize.height) * anchor.sy diff --git a/korim/src/jvmMain/kotlin/com/soywiz/korim/awt/AwtNativeImage.kt b/korim/src/jvmMain/kotlin/com/soywiz/korim/awt/AwtNativeImage.kt index 8e6c3c2526..5399a1b5bb 100644 --- a/korim/src/jvmMain/kotlin/com/soywiz/korim/awt/AwtNativeImage.kt +++ b/korim/src/jvmMain/kotlin/com/soywiz/korim/awt/AwtNativeImage.kt @@ -10,8 +10,6 @@ import com.soywiz.korim.bitmap.ensureNative import com.soywiz.korim.color.BGRA import com.soywiz.korim.color.Colors import com.soywiz.korim.color.RGBA -import com.soywiz.korim.color.RgbaArray -import com.soywiz.korim.color.arraycopy import com.soywiz.korim.paint.BitmapPaint import com.soywiz.korim.paint.ColorPaint import com.soywiz.korim.paint.GradientFiller @@ -22,7 +20,7 @@ import com.soywiz.korim.paint.Paint import com.soywiz.korim.paint.TransformedPaint import com.soywiz.korim.vector.Context2d import com.soywiz.korim.vector.CycleMethod -import com.soywiz.korma.geom.Matrix +import com.soywiz.korma.geom.MMatrix import com.soywiz.korma.geom.vector.LineCap import com.soywiz.korma.geom.vector.LineJoin import com.soywiz.korma.geom.vector.VectorPath @@ -39,14 +37,12 @@ import java.awt.Rectangle import java.awt.RenderingHints import java.awt.RenderingHints.* import java.awt.Transparency -import java.awt.color.ColorSpace import java.awt.geom.AffineTransform import java.awt.geom.Point2D import java.awt.geom.Rectangle2D import java.awt.image.BufferedImage import java.awt.image.ColorConvertOp import java.awt.image.ColorModel -import java.awt.image.DataBufferByte import java.awt.image.DataBufferInt import java.awt.image.Raster import java.awt.image.WritableRaster @@ -284,7 +280,7 @@ class AwtContext2dRender(val awtImage: BufferedImage, val antialiasing: Boolean // } //} - override fun drawImage(image: Bitmap, x: Double, y: Double, width: Double, height: Double, transform: Matrix) { + override fun drawImage(image: Bitmap, x: Double, y: Double, width: Double, height: Double, transform: MMatrix) { //transform.toAwt() //BufferedImageOp @@ -543,12 +539,12 @@ class AwtContext2dRender(val awtImage: BufferedImage, val antialiasing: Boolean } } -fun AffineTransform.setToMatrix(t: Matrix) { +fun AffineTransform.setToMatrix(t: MMatrix) { setTransform(t.a, t.b, t.c, t.d, t.tx, t.ty) } -fun Matrix.toAwt() = AffineTransform(a, b, c, d, tx, ty) -fun AffineTransform.toMatrix() = Matrix(scaleX, shearY, shearX, scaleY, translateX, translateY) +fun MMatrix.toAwt() = AffineTransform(a, b, c, d, tx, ty) +fun AffineTransform.toMatrix() = MMatrix(scaleX, shearY, shearX, scaleY, translateX, translateY) fun convertColor(c: RGBA): java.awt.Color = java.awt.Color(c.r, c.g, c.b, c.a) diff --git a/korim/src/jvmTest/kotlin/com/soywiz/korim/awt/AwtNativeImageTest.kt b/korim/src/jvmTest/kotlin/com/soywiz/korim/awt/AwtNativeImageTest.kt index 53e6f553ca..f9b3ed33af 100644 --- a/korim/src/jvmTest/kotlin/com/soywiz/korim/awt/AwtNativeImageTest.kt +++ b/korim/src/jvmTest/kotlin/com/soywiz/korim/awt/AwtNativeImageTest.kt @@ -1,13 +1,13 @@ package com.soywiz.korim.awt -import com.soywiz.korma.geom.Matrix +import com.soywiz.korma.geom.MMatrix import kotlin.test.Test import kotlin.test.assertEquals class AwtNativeImageTest { @Test fun testMatrixAwtTransform() { - val matrix = Matrix(1, 2, 3, 4, 5, 6) + val matrix = MMatrix(1, 2, 3, 4, 5, 6) assertEquals(matrix, matrix.clone().toAwt().toMatrix()) } } diff --git a/korim/src/jvmTest/kotlin/com/soywiz/korim/format/ImageFormatsNativeTest.kt b/korim/src/jvmTest/kotlin/com/soywiz/korim/format/ImageFormatsNativeTest.kt index 15f407417c..8a3b591ac8 100644 --- a/korim/src/jvmTest/kotlin/com/soywiz/korim/format/ImageFormatsNativeTest.kt +++ b/korim/src/jvmTest/kotlin/com/soywiz/korim/format/ImageFormatsNativeTest.kt @@ -1,6 +1,5 @@ package com.soywiz.korim.format -import com.soywiz.klogger.* import com.soywiz.korio.async.* import com.soywiz.korio.file.std.* import com.soywiz.korma.geom.* @@ -34,7 +33,7 @@ class ImageFormatsNativeTest { @Test fun svg() = suspendTest { val bi = resourcesVfs["logo.svg"].readBitmapInfo(formats)!! - assertEquals(Size(60, 60), bi.size) + assertEquals(MSize(60, 60), bi.size) val bitmap = resourcesVfs["logo.svg"].readBitmap(formats) //bitmap.showImageAndWait() //val logs = Console.capture {} diff --git a/korim/src/macosMain/kotlin/com.soywiz.korim.format/ns/NSExt.kt b/korim/src/macosMain/kotlin/com.soywiz.korim.format/ns/NSExt.kt index a9854f4170..7e6467ed72 100644 --- a/korim/src/macosMain/kotlin/com.soywiz.korim.format/ns/NSExt.kt +++ b/korim/src/macosMain/kotlin/com.soywiz.korim.format/ns/NSExt.kt @@ -31,5 +31,5 @@ fun Bitmap32.toNSImage(): NSImage { fun IPoint.toNSPoint(): CValue = NSMakePoint(x.toDouble(), y.cg.toDouble()) fun IPointInt.toNSPoint(): CValue = NSMakePoint(x.cg.toDouble(), y.cg.toDouble()) -fun CValue.toPoint(): Point = useContents { Point(this.x, this.y) } -fun CValue.toRectangle(): Rectangle = useContents { Rectangle(this.origin.x, this.origin.y, this.size.width, this.size.height) } +fun CValue.toPoint(): MPoint = useContents { MPoint(this.x, this.y) } +fun CValue.toRectangle(): MRectangle = useContents { MRectangle(this.origin.x, this.origin.y, this.size.width, this.size.height) } diff --git a/korim/src/mingwMain/kotlin/com/soywiz/korim/format/GdiNativeImage.kt b/korim/src/mingwMain/kotlin/com/soywiz/korim/format/GdiNativeImage.kt index 6258ef8ab9..f5793aa842 100644 --- a/korim/src/mingwMain/kotlin/com/soywiz/korim/format/GdiNativeImage.kt +++ b/korim/src/mingwMain/kotlin/com/soywiz/korim/format/GdiNativeImage.kt @@ -176,7 +176,7 @@ class GdiRenderer(val bitmap: Bitmap32, val antialiasing: Boolean) : BufferedRen GdipCreateMatrix(pmatrix) val matrix = pmatrix[0] //val transform = Matrix().copyFrom(style.transform) - val transform = Matrix().apply { + val transform = MMatrix().apply { identity() multiply(this, style.transform) multiply(this, state.transform) diff --git a/korim/src/nativeTest/kotlin/com/soywiz/korim/format/NativeImageFormatProviderTest.kt b/korim/src/nativeTest/kotlin/com/soywiz/korim/format/NativeImageFormatProviderTest.kt index 3a1aa8e32a..1019f9f3ed 100644 --- a/korim/src/nativeTest/kotlin/com/soywiz/korim/format/NativeImageFormatProviderTest.kt +++ b/korim/src/nativeTest/kotlin/com/soywiz/korim/format/NativeImageFormatProviderTest.kt @@ -15,12 +15,12 @@ class NativeImageFormatProviderTest { val bmp5 = nativeImageFormatProvider.decode(resourcesVfs["kotlin8.png"]) val bmp6 = nativeImageFormatProvider.decode(resourcesVfs["kotlin24.png"]) val bmp7 = nativeImageFormatProvider.decode(resourcesVfs["kotlin32.png"]) - assertEquals(Size(190, 190), bmp1.size) - assertEquals(Size(190, 190), bmp2.size) - assertEquals(Size(190, 190), bmp3.size) + assertEquals(MSize(190, 190), bmp1.size) + assertEquals(MSize(190, 190), bmp2.size) + assertEquals(MSize(190, 190), bmp3.size) //assertEquals(Size(190, 190), bmp4.size) - assertEquals(Size(190, 190), bmp5.size) - assertEquals(Size(190, 190), bmp6.size) - assertEquals(Size(190, 190), bmp7.size) + assertEquals(MSize(190, 190), bmp5.size) + assertEquals(MSize(190, 190), bmp6.size) + assertEquals(MSize(190, 190), bmp7.size) } } diff --git a/korma/src/commonMain/kotlin/com/soywiz/korma/algo/AStar.kt b/korma/src/commonMain/kotlin/com/soywiz/korma/algo/AStar.kt index 9945fa9535..d39cc17e4c 100644 --- a/korma/src/commonMain/kotlin/com/soywiz/korma/algo/AStar.kt +++ b/korma/src/commonMain/kotlin/com/soywiz/korma/algo/AStar.kt @@ -3,7 +3,7 @@ package com.soywiz.korma.algo import com.soywiz.kds.BooleanArray2 import com.soywiz.kds.IntPriorityQueue import com.soywiz.korma.geom.IPointIntArrayList -import com.soywiz.korma.geom.Point +import com.soywiz.korma.geom.MPoint import com.soywiz.korma.geom.PointIntArrayList class AStar(val width: Int, val height: Int, val isBlocking: (x: Int, y: Int) -> Boolean) { @@ -31,7 +31,7 @@ class AStar(val width: Int, val height: Int, val isBlocking: (x: Int, y: Int) -> val first = getNode(x0, y0) val dest = getNode(x1, y1) var closest = first - var closestDist = Point.distance(x0, y0, x1, y1) + var closestDist = MPoint.distance(x0, y0, x1, y1) if (!first.value) { queue.add(first.index) first.weight = 0 @@ -39,7 +39,7 @@ class AStar(val width: Int, val height: Int, val isBlocking: (x: Int, y: Int) -> while (queue.isNotEmpty()) { val last = AStarNode(queue.removeHead()) - val dist = Point.distance(last.posX, last.posY, dest.posX, dest.posY) + val dist = MPoint.distance(last.posX, last.posY, dest.posX, dest.posY) if (dist < closestDist) { closestDist = dist closest = last diff --git a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/AABB3D.kt b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/AABB3D.kt index 6c607708da..027f3289fd 100644 --- a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/AABB3D.kt +++ b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/AABB3D.kt @@ -4,26 +4,26 @@ import kotlin.math.max import kotlin.math.min -data class AABB3D(val min: Vector3 = Vector3(), val max: Vector3) { - var minX get() = min.x; set(value) { min.x = value } - var minY get() = min.y; set(value) { min.y = value } - var minZ get() = min.z; set(value) { min.z = value } +data class AABB3D(val min: MVector3 = MVector3(), val max: MVector3) { + var minX: Float get() = min.x; set(value) { min.x = value } + var minY: Float get() = min.y; set(value) { min.y = value } + var minZ: Float get() = min.z; set(value) { min.z = value } - var maxX get() = max.x; set(value) { max.x = value } - var maxY get() = max.y; set(value) { max.y = value } - var maxZ get() = max.z; set(value) { max.z = value } + var maxX: Float get() = max.x; set(value) { max.x = value } + var maxY: Float get() = max.y; set(value) { max.y = value } + var maxZ: Float get() = max.z; set(value) { max.z = value } - val sizeX get() = maxX - minX - val sizeY get() = maxY - minY - val sizeZ get() = maxZ - minZ + val sizeX: Float get() = maxX - minX + val sizeY: Float get() = maxY - minY + val sizeZ: Float get() = maxZ - minZ companion object { operator fun invoke(min: Float = Float.POSITIVE_INFINITY, max: Float = Float.NEGATIVE_INFINITY): AABB3D = - AABB3D(Vector3(min, min, min), Vector3(max, max, max)) + AABB3D(MVector3(min, min, min), MVector3(max, max, max)) fun fromSphere(pos: IVector3, radius: Float): AABB3D = AABB3D( - Vector3(pos.x - radius, pos.y - radius, pos.z - radius), - Vector3(pos.x + radius, pos.y + radius, pos.z + radius) + MVector3(pos.x - radius, pos.y - radius, pos.z - radius), + MVector3(pos.x + radius, pos.y + radius, pos.z + radius) ) } diff --git a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Anchor.kt b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Anchor.kt index 868f14fcaf..1c74850c59 100644 --- a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Anchor.kt +++ b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Anchor.kt @@ -3,28 +3,29 @@ package com.soywiz.korma.geom import com.soywiz.korma.interpolation.Interpolable import com.soywiz.korma.interpolation.interpolate +// @TODO: value class data class Anchor(val sx: Double, val sy: Double) : Interpolable { companion object { - operator fun invoke(sx: Int, sy: Int) = Anchor(sx.toDouble(), sy.toDouble()) - operator fun invoke(sx: Float, sy: Float) = Anchor(sx.toDouble(), sy.toDouble()) - - val TOP_LEFT = Anchor(0.0, 0.0) - val TOP_CENTER = Anchor(0.5, 0.0) - val TOP_RIGHT = Anchor(1.0, 0.0) - - val MIDDLE_LEFT = Anchor(0.0, 0.5) - val MIDDLE_CENTER = Anchor(0.5, 0.5) - val MIDDLE_RIGHT = Anchor(1.0, 0.5) - - val BOTTOM_LEFT = Anchor(0.0, 1.0) - val BOTTOM_CENTER = Anchor(0.5, 1.0) - val BOTTOM_RIGHT = Anchor(1.0, 1.0) - - val TOP get() = TOP_CENTER - val LEFT get() = MIDDLE_LEFT - val RIGHT get() = MIDDLE_RIGHT - val BOTTOM get() = BOTTOM_CENTER - val CENTER get() = MIDDLE_CENTER + operator fun invoke(sx: Int, sy: Int): Anchor = Anchor(sx.toDouble(), sy.toDouble()) + operator fun invoke(sx: Float, sy: Float): Anchor = Anchor(sx.toDouble(), sy.toDouble()) + + val TOP_LEFT: Anchor = Anchor(0.0, 0.0) + val TOP_CENTER: Anchor = Anchor(0.5, 0.0) + val TOP_RIGHT: Anchor = Anchor(1.0, 0.0) + + val MIDDLE_LEFT: Anchor = Anchor(0.0, 0.5) + val MIDDLE_CENTER: Anchor = Anchor(0.5, 0.5) + val MIDDLE_RIGHT: Anchor = Anchor(1.0, 0.5) + + val BOTTOM_LEFT: Anchor = Anchor(0.0, 1.0) + val BOTTOM_CENTER: Anchor = Anchor(0.5, 1.0) + val BOTTOM_RIGHT: Anchor = Anchor(1.0, 1.0) + + val TOP: Anchor get() = TOP_CENTER + val LEFT: Anchor get() = MIDDLE_LEFT + val RIGHT: Anchor get() = MIDDLE_RIGHT + val BOTTOM: Anchor get() = BOTTOM_CENTER + val CENTER: Anchor get() = MIDDLE_CENTER } override fun interpolateWith(ratio: Double, other: Anchor): Anchor = Anchor( diff --git a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Angle.kt b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Angle.kt index a34d81628f..4b035975b8 100644 --- a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Angle.kt +++ b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Angle.kt @@ -96,12 +96,13 @@ inline class Angle private constructor( inline fun between(x0: Int, y0: Int, x1: Int, y1: Int): Angle = between(x0.toDouble(), y0.toDouble(), x1.toDouble(), y1.toDouble()) inline fun between(x0: Float, y0: Float, x1: Float, y1: Float): Angle = between(x0.toDouble(), y0.toDouble(), x1.toDouble(), y1.toDouble()) inline fun between(p0: IPoint, p1: IPoint): Angle = between(p0.x, p0.y, p1.x, p1.y) + inline fun between(p0: Point, p1: Point): Angle = between(p0.x, p0.y, p1.x, p1.y) inline fun between(ox: Double, oy: Double, x1: Double, y1: Double, x2: Double, y2: Double): Angle = between(x1 - ox, y1 - oy, x2 - ox, y2 - oy) - inline fun between(o: IPoint, v1: IPoint, v2: IPoint): Angle = - between(o.x, o.y, v1.x, v1.y, v2.x, v2.y) + inline fun between(o: IPoint, v1: IPoint, v2: IPoint): Angle = between(o.x, o.y, v1.x, v1.y, v2.x, v2.y) + inline fun between(o: Point, v1: Point, v2: Point): Angle = between(o.x, o.y, v1.x, v1.y, v2.x, v2.y) } override fun compareTo(other: Angle): Int { diff --git a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/BoundsBuilder.kt b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/BoundsBuilder.kt index 3899f7ac69..5cbba19130 100644 --- a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/BoundsBuilder.kt +++ b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/BoundsBuilder.kt @@ -3,7 +3,7 @@ package com.soywiz.korma.geom import com.soywiz.kds.* class BoundsBuilder { - val tempRect = Rectangle() + val tempRect = MRectangle() companion object { val POOL: ConcurrentPool = ConcurrentPool({ it.reset() }) { BoundsBuilder() } @@ -70,12 +70,12 @@ class BoundsBuilder { fun add(x: Int, y: Int): BoundsBuilder = add(x.toDouble(), y.toDouble()) fun add(x: Float, y: Float): BoundsBuilder = add(x.toDouble(), y.toDouble()) - fun add(x: Double, y: Double, transform: Matrix?): BoundsBuilder = if (transform != null) add(transform.transformX(x, y), transform.transformY(x, y)) else add(x, y) - fun add(x: Int, y: Int, transform: Matrix?): BoundsBuilder = add(x.toDouble(), y.toDouble(), transform) - fun add(x: Float, y: Float, transform: Matrix?): BoundsBuilder = add(x.toDouble(), y.toDouble(), transform) + fun add(x: Double, y: Double, transform: MMatrix?): BoundsBuilder = if (transform != null) add(transform.transformX(x, y), transform.transformY(x, y)) else add(x, y) + fun add(x: Int, y: Int, transform: MMatrix?): BoundsBuilder = add(x.toDouble(), y.toDouble(), transform) + fun add(x: Float, y: Float, transform: MMatrix?): BoundsBuilder = add(x.toDouble(), y.toDouble(), transform) fun add(point: IPoint): BoundsBuilder = add(point.x, point.y) - fun add(point: IPoint, transform: Matrix): BoundsBuilder = add(point.x, point.y, transform) + fun add(point: IPoint, transform: MMatrix): BoundsBuilder = add(point.x, point.y, transform) fun addRect(x: Int, y: Int, width: Int, height: Int): BoundsBuilder = addRect(x.toDouble(), y.toDouble(), width.toDouble(), height.toDouble()) fun addRect(x: Double, y: Double, width: Double, height: Double): BoundsBuilder = add(x, y).add(x + width, y + height) @@ -107,15 +107,15 @@ class BoundsBuilder { return this } - fun add(ps: Iterable, transform: Matrix): BoundsBuilder { + fun add(ps: Iterable, transform: MMatrix): BoundsBuilder { for (p in ps) add(p, transform) return this } - fun add(ps: IPointArrayList, transform: Matrix): BoundsBuilder { + fun add(ps: IPointArrayList, transform: MMatrix): BoundsBuilder { for (n in 0 until ps.size) add(ps.getX(n), ps.getY(n), transform) return this } - fun add(rect: IRectangle, transform: Matrix?): BoundsBuilder { + fun add(rect: IRectangle, transform: MMatrix?): BoundsBuilder { if (rect.isNotEmpty) { add(rect.left, rect.top, transform) add(rect.right, rect.top, transform) @@ -125,9 +125,9 @@ class BoundsBuilder { return this } - fun getBoundsOrNull(out: Rectangle = Rectangle()): Rectangle? = if (npoints == 0) null else out.setBounds(xmin, ymin, xmax, ymax) + fun getBoundsOrNull(out: MRectangle = MRectangle()): MRectangle? = if (npoints == 0) null else out.setBounds(xmin, ymin, xmax, ymax) - fun getBounds(out: Rectangle = Rectangle()): Rectangle { + fun getBounds(out: MRectangle = MRectangle()): MRectangle { if (getBoundsOrNull(out) == null) { out.setBounds(0, 0, 0, 0) } diff --git a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Circle.kt b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Circle.kt index cbb24c8d21..82de222a8c 100644 --- a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Circle.kt +++ b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Circle.kt @@ -1,39 +1,37 @@ package com.soywiz.korma.geom -interface ICircle { - val center: IPoint - val radius: Double - val radiusSquared: Double get() = radius * radius -} - -val ICircle.centerX: Double get() = center.x -val ICircle.centerY: Double get() = center.y - data class Circle(override val center: IPoint, override val radius: Double) : ICircle { override val radiusSquared: Double = radius * radius - constructor(x: Double, y: Double, radius: Double) : this(IPoint(x, y), radius) -} - -fun ICircle.distanceToCenterSquared(p: IPoint): Double { - return Point.distanceSquared(p, center) + constructor(x: Double, y: Double, radius: Double) : this(Point(x, y).mutable, radius) } -// @TODO: Check if inside the circle -fun ICircle.distanceClosestSquared(p: IPoint): Double { - return distanceToCenterSquared(p) - radiusSquared -} - -// @TODO: Check if inside the circle -fun ICircle.distanceFarthestSquared(p: IPoint): Double { - return distanceToCenterSquared(p) + radiusSquared -} - -fun ICircle.projectedPoint(point: IPoint, out: Point = Point()): Point { - //if (point == this.center) return out.copyFrom(center) +interface ICircle { + val center: IPoint + val radius: Double + val radiusSquared: Double get() = radius * radius - val circle = this - val pos = point - val angle = Angle.between(circle.center, pos) - return out.setToPolar(circle.center, angle, circle.radius) + val centerX: Double get() = center.x + val centerY: Double get() = center.y + + fun distanceToCenterSquared(p: IPoint): Double = MPoint.distanceSquared(p, center) + fun distanceToCenterSquared(p: Point): Double = Point.distanceSquared(p, center.point) + // @TODO: Check if inside the circle + fun distanceClosestSquared(p: Point): Double = distanceToCenterSquared(p) - radiusSquared + fun distanceClosestSquared(p: IPoint): Double = distanceToCenterSquared(p) - radiusSquared + // @TODO: Check if inside the circle + fun distanceFarthestSquared(p: Point): Double = distanceToCenterSquared(p) + radiusSquared + fun distanceFarthestSquared(p: IPoint): Double = distanceToCenterSquared(p) + radiusSquared + fun projectedPoint(point: IPoint, out: MPoint = MPoint()): MPoint { + val circle = this + val pos = point + val center = circle.center + val angle = Angle.between(center, pos) + return out.setToPolar(center, angle, circle.radius) + } + fun projectedPoint(point: Point): Point { + val circle = this + val center = circle.center.point + return Point.fromPolar(center, Angle.between(center, point), circle.radius) + } } diff --git a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/EulerRotation.kt b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/EulerRotation.kt index bc67afd8c8..f7581a5622 100644 --- a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/EulerRotation.kt +++ b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/EulerRotation.kt @@ -1,12 +1,18 @@ package com.soywiz.korma.geom data class EulerRotation( + val x: Angle = 0.degrees, + val y: Angle = 0.degrees, + val z: Angle = 0.degrees +) + +data class MEulerRotation( var x: Angle = 0.degrees, var y: Angle = 0.degrees, var z: Angle = 0.degrees ) { companion object { - fun toQuaternion(roll: Angle, pitch: Angle, yaw: Angle, out: Quaternion = Quaternion()): Quaternion { + fun toQuaternion(roll: Angle, pitch: Angle, yaw: Angle, out: MQuaternion = MQuaternion()): MQuaternion { val cr = cos(roll * 0.5) val sr = sin(roll * 0.5) val cp = cos(pitch * 0.5) @@ -20,23 +26,23 @@ data class EulerRotation( (cy * cp * cr + sy * sp * sr) ) } - fun toQuaternion(euler: EulerRotation, out: Quaternion = Quaternion()): Quaternion = toQuaternion(euler.x, euler.y, euler.z, out) + fun toQuaternion(euler: MEulerRotation, out: MQuaternion = MQuaternion()): MQuaternion = toQuaternion(euler.x, euler.y, euler.z, out) } - fun toQuaternion(out: Quaternion = Quaternion()): Quaternion = toQuaternion(this, out) + fun toQuaternion(out: MQuaternion = MQuaternion()): MQuaternion = toQuaternion(this, out) - fun setQuaternion(x: Double, y: Double, z: Double, w: Double): EulerRotation = Quaternion.toEuler(x.toFloat(), y.toFloat(), z.toFloat(), w.toFloat(), this) - fun setQuaternion(x: Int, y: Int, z: Int, w: Int): EulerRotation = Quaternion.toEuler(x.toFloat(), y.toFloat(), z.toFloat(), w.toFloat(), this) - fun setQuaternion(x: Float, y: Float, z: Float, w: Float): EulerRotation = Quaternion.toEuler(x, y, z, w, this) + fun setQuaternion(x: Double, y: Double, z: Double, w: Double): MEulerRotation = MQuaternion.toEuler(x.toFloat(), y.toFloat(), z.toFloat(), w.toFloat(), this) + fun setQuaternion(x: Int, y: Int, z: Int, w: Int): MEulerRotation = MQuaternion.toEuler(x.toFloat(), y.toFloat(), z.toFloat(), w.toFloat(), this) + fun setQuaternion(x: Float, y: Float, z: Float, w: Float): MEulerRotation = MQuaternion.toEuler(x, y, z, w, this) - fun setQuaternion(quaternion: Quaternion): EulerRotation = Quaternion.toEuler(quaternion.x, quaternion.y, quaternion.z, quaternion.w, this) - fun setTo(x: Angle, y: Angle, z: Angle): EulerRotation = this + fun setQuaternion(quaternion: MQuaternion): MEulerRotation = MQuaternion.toEuler(quaternion.x, quaternion.y, quaternion.z, quaternion.w, this) + fun setTo(x: Angle, y: Angle, z: Angle): MEulerRotation = this .apply { this.x = x } .apply { this.y = y } .apply { this.z = z } - fun setTo(other: EulerRotation): EulerRotation = setTo(other.x, other.y, other.z) + fun setTo(other: MEulerRotation): MEulerRotation = setTo(other.x, other.y, other.z) - private val tempQuat: Quaternion by lazy { Quaternion() } - fun toMatrix(out: Matrix3D = Matrix3D()): Matrix3D = tempQuat.setEuler(this).toMatrix(out) + private val tempQuat: MQuaternion by lazy { MQuaternion() } + fun toMatrix(out: MMatrix3D = MMatrix3D()): MMatrix3D = tempQuat.setEuler(this).toMatrix(out) } diff --git a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/IRectangle.kt b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/IRectangle.kt deleted file mode 100644 index 8c1b9825b0..0000000000 --- a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/IRectangle.kt +++ /dev/null @@ -1,93 +0,0 @@ -package com.soywiz.korma.geom - -interface IRectangle { - val x: Double - val y: Double - val width: Double - val height: Double - - companion object { - inline operator fun invoke( - x: Double, - y: Double, - width: Double, - height: Double - ): IRectangle = Rectangle(x, y, width, height) - - inline operator fun invoke(x: Float, y: Float, width: Float, height: Float): IRectangle = - Rectangle(x, y, width, height) - - inline operator fun invoke(x: Int, y: Int, width: Int, height: Int): IRectangle = - Rectangle(x, y, width, height) - - // Creates a rectangle from 2 points where the (x,y) is the top left point - // with the same width and height as the point. The 2 points provided can be - // in any arbitrary order, the rectangle will be created from the projected - // rectangle of the 2 points. - // - // Here is one example - // Rect XY point1 - // │ │ - // ▼ ▼ - // ┌────────┐ - // │ │ - // │ │ - // └────────┘ - // ▲ - // │ - // point2 - // - // Here is another example - // point1 (Rect XY) - // │ - // ▼ - // ┌────────┐ - // │ │ - // │ │ - // └────────┘ - // ▲ - // │ - // point2 - operator fun invoke(point1: IPoint, point2: IPoint): Rectangle { - val left = minOf(point1.x, point2.x) - val top = minOf(point1.y, point2.y) - val right = maxOf(point1.x, point2.x) - val bottom = maxOf(point1.y, point2.y) - return Rectangle(left, top, right - left, bottom - top) - } - } -} - -val IRectangle.area: Double get() = width * height -fun IRectangle.clone(): Rectangle = Rectangle(x, y, width, height) -val IRectangle.isNotEmpty: Boolean get() = width != 0.0 || height != 0.0 -val IRectangle.mutable: Rectangle get() = Rectangle(x, y, width, height) - -val IRectangle.left get() = x -val IRectangle.top get() = y -val IRectangle.right get() = x + width -val IRectangle.bottom get() = y + height - -val IRectangle.topLeft get() = Point(left, top) -val IRectangle.topRight get() = Point(right, top) -val IRectangle.bottomLeft get() = Point(left, bottom) -val IRectangle.bottomRight get() = Point(right, bottom) - -val IRectangle.centerX: Double get() = (right + left) * 0.5 -val IRectangle.centerY: Double get() = (bottom + top) * 0.5 -val IRectangle.center: Point get() = Point(centerX, centerY) - -/** - * Circle that touches or contains all the corners ([topLeft], [topRight], [bottomLeft], [bottomRight]) of the rectangle. - */ -fun IRectangle.outerCircle(): Circle { - val centerX = centerX - val centerY = centerY - return Circle(center, Point.distance(centerX, centerY, right, top)) -} - -operator fun IRectangle.contains(that: IPoint) = contains(that.x, that.y) -operator fun IRectangle.contains(that: IPointInt) = contains(that.x, that.y) -fun IRectangle.contains(x: Double, y: Double) = (x >= left && x < right) && (y >= top && y < bottom) -fun IRectangle.contains(x: Float, y: Float) = contains(x.toDouble(), y.toDouble()) -fun IRectangle.contains(x: Int, y: Int) = contains(x.toDouble(), y.toDouble()) diff --git a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Line.kt b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Line.kt index 7fb8c0b15e..4299540e45 100644 --- a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Line.kt +++ b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Line.kt @@ -5,16 +5,19 @@ import com.soywiz.korma.math.almostEquals import com.soywiz.kmem.clamp import com.soywiz.korma.math.isAlmostZero +// @TODO: value class +data class Line(val a: Point, val b: Point) + interface ILine { val a: IPoint val b: IPoint } -data class Line(override val a: Point, override val b: Point) : ILine { - private val temp = Point() +data class MLine(override val a: MPoint, override val b: MPoint) : ILine { + private val temp = MPoint() - fun clone(): Line = Line(a.copy(), b.copy()) - fun flipped(): Line = Line(b.copy(), a.copy()) + fun clone(): MLine = MLine(a.copy(), b.copy()) + fun flipped(): MLine = MLine(b.copy(), a.copy()) val minX: Double get() = kotlin.math.min(a.x, b.x) val maxX: Double get() = kotlin.math.max(a.x, b.x) @@ -22,43 +25,43 @@ data class Line(override val a: Point, override val b: Point) : ILine { val minY: Double get() = kotlin.math.min(a.y, b.y) val maxY: Double get() = kotlin.math.max(a.y, b.y) - fun round(): Line { + fun round(): MLine { a.round() b.round() return this } - fun setTo(a: IPoint, b: IPoint): Line { + fun setTo(a: IPoint, b: IPoint): MLine { return setTo(a.x, a.y, b.x, b.y) } - fun setTo(x0: Double, y0: Double, x1: Double, y1: Double): Line { + fun setTo(x0: Double, y0: Double, x1: Double, y1: Double): MLine { a.setTo(x0, y0) b.setTo(x1, y1) return this } - fun setToPolar(x: Double, y: Double, angle: Angle, length: Double = 1.0): Line { + fun setToPolar(x: Double, y: Double, angle: Angle, length: Double = 1.0): MLine { setTo(x, y, x + angle.cosine * length, y + angle.sine * length) return this } - fun directionVector(out: Point = Point()): Point { + fun directionVector(out: MPoint = MPoint()): MPoint { out.setTo(dx, dy) return out } - fun getMinimumDistance(p: Point): Double { + fun getMinimumDistance(p: MPoint): Double { val v = a val w = b - val l2 = Point.distanceSquared(v, w) - if (l2 == 0.0) return Point.distanceSquared(p, a) - val t = (Point.dot(p - v, w - v) / l2).clamp(0.0, 1.0) - return Point.distance(p, v + (w - v) * t); + val l2 = MPoint.distanceSquared(v, w) + if (l2 == 0.0) return MPoint.distanceSquared(p, a) + val t = (MPoint.dot(p - v, w - v) / l2).clamp(0.0, 1.0) + return MPoint.distance(p, v + (w - v) * t); } @KormaExperimental - fun scalePoints(scale: Double): Line { + fun scalePoints(scale: Double): MLine { val dx = this.dx val dy = this.dy x0 -= dx * scale @@ -81,10 +84,10 @@ data class Line(override val a: Point, override val b: Point) : ILine { return this } - constructor() : this(Point(), Point()) - constructor(x0: Double, y0: Double, x1: Double, y1: Double) : this(Point(x0, y0), Point(x1, y1)) - constructor(x0: Float, y0: Float, x1: Float, y1: Float) : this(Point(x0, y0), Point(x1, y1)) - constructor(x0: Int, y0: Int, x1: Int, y1: Int) : this(Point(x0, y0), Point(x1, y1)) + constructor() : this(MPoint(), MPoint()) + constructor(x0: Double, y0: Double, x1: Double, y1: Double) : this(MPoint(x0, y0), MPoint(x1, y1)) + constructor(x0: Float, y0: Float, x1: Float, y1: Float) : this(MPoint(x0, y0), MPoint(x1, y1)) + constructor(x0: Int, y0: Int, x1: Int, y1: Int) : this(MPoint(x0, y0), MPoint(x1, y1)) var x0: Double by a::x var y0: Double by a::y @@ -100,17 +103,17 @@ data class Line(override val a: Point, override val b: Point) : ILine { fun containsBoundsXY(x: Double, y: Double): Boolean = containsX(x) && containsY(y) val angle: Angle get() = Angle.between(a, b) - val length: Double get() = Point.distance(a, b) - val lengthSquared: Double get() = Point.distanceSquared(a, b) + val length: Double get() = MPoint.distance(a, b) + val lengthSquared: Double get() = MPoint.distanceSquared(a, b) override fun toString(): String = "Line($a, $b)" - fun getLineIntersectionPoint(line: Line, out: Point = Point()): Point? { + fun getLineIntersectionPoint(line: MLine, out: MPoint = MPoint()): MPoint? { return getIntersectXY(x0, y0, x1, y1, line.x0, line.y0, line.x1, line.y1, out) } - fun getIntersectionPoint(line: Line, out: Point = Point()): Point? = getSegmentIntersectionPoint(line, out) - fun getSegmentIntersectionPoint(line: Line, out: Point = Point()): Point? { + fun getIntersectionPoint(line: MLine, out: MPoint = MPoint()): MPoint? = getSegmentIntersectionPoint(line, out) + fun getSegmentIntersectionPoint(line: MLine, out: MPoint = MPoint()): MPoint? { if (getIntersectXY(x0, y0, x1, y1, line.x0, line.y0, line.x1, line.y1, out) != null) { if (this.containsBoundsXY(out.x, out.y) && line.containsBoundsXY(out.x, out.y)) { return out @@ -119,9 +122,9 @@ data class Line(override val a: Point, override val b: Point) : ILine { return null } - fun intersectsLine(line: Line): Boolean = getLineIntersectionPoint(line, temp) != null - fun intersects(line: Line): Boolean = intersectsSegment(line) - fun intersectsSegment(line: Line): Boolean { + fun intersectsLine(line: MLine): Boolean = getLineIntersectionPoint(line, temp) != null + fun intersects(line: MLine): Boolean = intersectsSegment(line) + fun intersectsSegment(line: MLine): Boolean { return getSegmentIntersectionPoint(line, temp) != null //val line1 = this //val line2 = line @@ -144,10 +147,10 @@ data class Line(override val a: Point, override val b: Point) : ILine { // (q.y <= max(p.y, r.y)) && (q.y >= min(p.y, r.y))) companion object { - fun fromPointAndDirection(point: IPoint, direction: IPoint, scale: Double = 1.0, out: Line = Line()): Line { + fun fromPointAndDirection(point: IPoint, direction: IPoint, scale: Double = 1.0, out: MLine = MLine()): MLine { return out.setTo(point.x, point.y, point.x + direction.x * scale, point.y + direction.y * scale) } - fun fromPointAngle(point: IPoint, angle: Angle, length: Double = 1.0, out: Line = Line()): Line = + fun fromPointAngle(point: IPoint, angle: Angle, length: Double = 1.0, out: MLine = MLine()): MLine = out.setToPolar(point.x, point.y, angle, length) fun length(Ax: Double, Ay: Double, Bx: Double, By: Double): Double = kotlin.math.hypot(Bx - Ax, By - Ay) @@ -168,21 +171,21 @@ data class Line(override val a: Point, override val b: Point) : ILine { return true } - fun getIntersectXY(Ax: Double, Ay: Double, Bx: Double, By: Double, Cx: Double, Cy: Double, Dx: Double, Dy: Double, out: Point = Point()): Point? { + fun getIntersectXY(Ax: Double, Ay: Double, Bx: Double, By: Double, Cx: Double, Cy: Double, Dx: Double, Dy: Double, out: MPoint = MPoint()): MPoint? { return if (getIntersectXY(Ax, Ay, Bx, By, Cx, Cy, Dx, Dy) { x, y -> out.setTo(x, y) }) out else null } - fun getIntersectXY(a: IPoint, b: IPoint, c: IPoint, d: IPoint, out: Point = Point()): IPoint? { + fun getIntersectXY(a: IPoint, b: IPoint, c: IPoint, d: IPoint, out: MPoint = MPoint()): IPoint? { return getIntersectXY(a.x, a.y, b.x, b.y, c.x, c.y, d.x, d.y, out) } } } data class LineIntersection( - val line: Line = Line(), - val intersection: Point = Point() + val line: MLine = MLine(), + val intersection: MPoint = MPoint() ) { - val normalVector: Line = Line() + val normalVector: MLine = MLine() fun setFrom(x0: Double, y0: Double, x1: Double, y1: Double, ix: Double, iy: Double, normalLength: Double) { line.setTo(x0, y0, x1, y1) @@ -193,22 +196,22 @@ data class LineIntersection( override fun toString(): String = "LineIntersection($line, intersection=$intersection)" } -fun Line.Companion.projectedPoint( +fun MLine.Companion.projectedPoint( v1x: Double, v1y: Double, v2x: Double, v2y: Double, px: Double, py: Double, - out: Point = Point() -): Point { + out: MPoint = MPoint() +): MPoint { // return this.getIntersectionPoint(Line(point, Point.fromPolar(point, this.angle + 90.degrees)))!! // get dot product of e1, e2 val e1x = v2x - v1x val e1y = v2y - v1y val e2x = px - v1x val e2y = py - v1y - val valDp = Point.dot(e1x, e1y, e2x, e2y) + val valDp = MPoint.dot(e1x, e1y, e2x, e2y) // get length of vectors val lenLineE1 = kotlin.math.hypot(e1x, e1y) @@ -228,26 +231,26 @@ fun Line.Companion.projectedPoint( return out.setTo((v1x + (projLenOfLine * e1x) / lenLineE1), (v1y + (projLenOfLine * e1y) / lenLineE1)) } -fun Line.Companion.projectedPoint( +fun MLine.Companion.projectedPoint( v1: IPoint, v2: IPoint, point: IPoint, - out: Point = Point() -): Point = projectedPoint(v1.x, v1.y, v2.x, v2.y, point.x, point.y, out) + out: MPoint = MPoint() +): MPoint = projectedPoint(v1.x, v1.y, v2.x, v2.y, point.x, point.y, out) -fun Line.Companion.lineIntersectionPoint( - l1: Line, - l2: Line, - out: Point = Point() -): Point? = l1.getLineIntersectionPoint(l2, out) +fun MLine.Companion.lineIntersectionPoint( + l1: MLine, + l2: MLine, + out: MPoint = MPoint() +): MPoint? = l1.getLineIntersectionPoint(l2, out) -fun Line.Companion.segmentIntersectionPoint( - l1: Line, - l2: Line, - out: Point = Point() -): Point? = l1.getSegmentIntersectionPoint(l2, out) +fun MLine.Companion.segmentIntersectionPoint( + l1: MLine, + l2: MLine, + out: MPoint = MPoint() +): MPoint? = l1.getSegmentIntersectionPoint(l2, out) // @TODO: Should we create a common interface make projectedPoint part of it? (for ecample to project other kind of shapes) // https://math.stackexchange.com/questions/62633/orthogonal-projection-of-a-point-onto-a-line // http://www.sunshine2k.de/coding/java/PointOnLine/PointOnLine.html -fun ILine.projectedPoint(point: IPoint, out: Point = Point()): Point = Line.projectedPoint(a, b, point, out) +fun ILine.projectedPoint(point: IPoint, out: MPoint = MPoint()): MPoint = MLine.projectedPoint(a, b, point, out) diff --git a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Margin.kt b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Margin.kt index a38190cbd5..ede9a96d12 100644 --- a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Margin.kt +++ b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Margin.kt @@ -2,7 +2,24 @@ package com.soywiz.korma.geom import com.soywiz.kds.* -interface Margin { +// @TODO: value class +data class Margin( + val top: Double, + val right: Double, + val bottom: Double, + val left: Double, +) + +// @TODO: value class +data class MarginInt( + val top: Int, + val right: Int, + val bottom: Int, + val left: Int, +) + +@Deprecated("Use Margin") +interface IMargin { val top: Double val right: Double val bottom: Double @@ -13,29 +30,30 @@ interface Margin { right: Double = this.right, bottom: Double = this.bottom, left: Double = this.left, - ): Margin = MutableMargin(top, right, bottom, left) + ): IMargin = MMargin(top, right, bottom, left) companion object { - val EMPTY: Margin = MutableMargin() + val EMPTY: IMargin = MMargin() - operator fun invoke(top: Double, right: Double, bottom: Double, left: Double): Margin = MutableMargin(top, right, bottom, left) - operator fun invoke(vertical: Double, horizontal: Double): Margin = MutableMargin(vertical, horizontal) - operator fun invoke(margin: Double): Margin = MutableMargin(margin) + operator fun invoke(top: Double, right: Double, bottom: Double, left: Double): IMargin = MMargin(top, right, bottom, left) + operator fun invoke(vertical: Double, horizontal: Double): IMargin = MMargin(vertical, horizontal) + operator fun invoke(margin: Double): IMargin = MMargin(margin) } } -val Margin.leftPlusRight: Double get() = left + right -val Margin.topPlusBottom: Double get() = top + bottom +val IMargin.leftPlusRight: Double get() = left + right +val IMargin.topPlusBottom: Double get() = top + bottom -val Margin.horizontal: Double get() = (left + right) / 2 -val Margin.vertical: Double get() = (top + bottom) / 2 +val IMargin.horizontal: Double get() = (left + right) / 2 +val IMargin.vertical: Double get() = (top + bottom) / 2 -data class MutableMargin( +@Deprecated("Use Margin") +data class MMargin( override var top: Double = 0.0, override var right: Double = 0.0, override var bottom: Double = 0.0, override var left: Double = 0.0 -) : Margin { +) : IMargin { constructor(vertical: Double, horizontal: Double) : this(vertical, horizontal, vertical, horizontal) constructor(margin: Double) : this(margin, margin, margin, margin) @@ -47,43 +65,43 @@ data class MutableMargin( this.left = left this.bottom = bottom } - fun copyFrom(other: Margin) { + fun copyFrom(other: IMargin) { setTo(other.top, other.right, other.bottom, other.left) } } -typealias IMarginInt = MarginInt - -interface MarginInt { +@Deprecated("Use MarginInt") +interface IMarginInt { val top: Int val right: Int val bottom: Int val left: Int companion object { - val ZERO: IMarginInt = MarginInt(0) - operator fun invoke(top: Int, right: Int, bottom: Int, left: Int): MarginInt = MutableMarginInt(top, right, bottom, left) - operator fun invoke(vertical: Int, horizontal: Int): MarginInt = MutableMarginInt(vertical, horizontal) - operator fun invoke(margin: Int): MarginInt = MutableMarginInt(margin) + val ZERO: IMarginInt = IMarginInt(0) + operator fun invoke(top: Int, right: Int, bottom: Int, left: Int): IMarginInt = MMarginInt(top, right, bottom, left) + operator fun invoke(vertical: Int, horizontal: Int): IMarginInt = MMarginInt(vertical, horizontal) + operator fun invoke(margin: Int): IMarginInt = MMarginInt(margin) } } val IMarginInt.isNotZero: Boolean get() = top != 0 || left != 0 || right != 0 || bottom != 0 -val MarginInt.leftPlusRight: Int get() = left + right -val MarginInt.topPlusBottom: Int get() = top + bottom +val IMarginInt.leftPlusRight: Int get() = left + right +val IMarginInt.topPlusBottom: Int get() = top + bottom -val MarginInt.horizontal: Int get() = (left + right) / 2 -val MarginInt.vertical: Int get() = (top + bottom) / 2 +val IMarginInt.horizontal: Int get() = (left + right) / 2 +val IMarginInt.vertical: Int get() = (top + bottom) / 2 -data class MutableMarginInt( +@Deprecated("Use MarginInt") +data class MMarginInt( override var top: Int = 0, override var right: Int = 0, override var bottom: Int = 0, override var left: Int = 0 -) : MarginInt { +) : IMarginInt { companion object { - val POOL: ConcurrentPool = ConcurrentPool({ it.setTo(0) }) { MutableMarginInt() } + val POOL: ConcurrentPool = ConcurrentPool({ it.setTo(0) }) { MMarginInt() } } constructor(vertical: Int, horizontal: Int) : this(vertical, horizontal, vertical, horizontal) @@ -97,7 +115,7 @@ data class MutableMarginInt( this.left = left this.bottom = bottom } - fun copyFrom(other: MarginInt) { + fun copyFrom(other: IMarginInt) { setTo(other.top, other.right, other.bottom, other.left) } } diff --git a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Matrix.kt b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Matrix.kt index 59bb3ef083..d4aaa0553d 100644 --- a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Matrix.kt +++ b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Matrix.kt @@ -6,6 +6,7 @@ import com.soywiz.kds.* import com.soywiz.korma.interpolation.Interpolable import com.soywiz.korma.interpolation.MutableInterpolable import com.soywiz.korma.interpolation.interpolate +import kotlin.jvm.* import kotlin.math.PI import kotlin.math.abs import kotlin.math.atan2 @@ -16,23 +17,43 @@ import kotlin.math.hypot import kotlin.math.sin data class Matrix( - var a: Double = 1.0, - var b: Double = 0.0, - var c: Double = 0.0, - var d: Double = 1.0, - var tx: Double = 0.0, - var ty: Double = 0.0 -) : MutableInterpolable, Interpolable { + val a: Double, + val b: Double, + val c: Double, + val d: Double, + val tx: Double, + val ty: Double +) + +@Deprecated("Use Matrix instead") +interface IMatrix { + val a: Double + val b: Double + val c: Double + val d: Double + val tx: Double + val ty: Double +} + +@Deprecated("Use Matrix instead") +data class MMatrix( + override var a: Double = 1.0, + override var b: Double = 0.0, + override var c: Double = 0.0, + override var d: Double = 1.0, + override var tx: Double = 0.0, + override var ty: Double = 0.0 +) : MutableInterpolable, Interpolable, IMatrix { companion object { - val POOL: ConcurrentPool = ConcurrentPool({ it.identity() }) { Matrix() } + val POOL: ConcurrentPool = ConcurrentPool({ it.identity() }) { MMatrix() } inline operator fun invoke(a: Float, b: Float = 0f, c: Float = 0f, d: Float = 1f, tx: Float = 0f, ty: Float = 0f) = - Matrix(a.toDouble(), b.toDouble(), c.toDouble(), d.toDouble(), tx.toDouble(), ty.toDouble()) + MMatrix(a.toDouble(), b.toDouble(), c.toDouble(), d.toDouble(), tx.toDouble(), ty.toDouble()) inline operator fun invoke(a: Int, b: Int = 0, c: Int = 0, d: Int = 1, tx: Int = 0, ty: Int = 0) = - Matrix(a.toDouble(), b.toDouble(), c.toDouble(), d.toDouble(), tx.toDouble(), ty.toDouble()) + MMatrix(a.toDouble(), b.toDouble(), c.toDouble(), d.toDouble(), tx.toDouble(), ty.toDouble()) - operator fun invoke(m: Matrix, out: Matrix = Matrix()): Matrix = out.copyFrom(m) + operator fun invoke(m: MMatrix, out: MMatrix = MMatrix()): MMatrix = out.copyFrom(m) fun transformXf(a: Float, b: Float, c: Float, d: Float, tx: Float, ty: Float, px: Float, py: Float): Float = a * px + c * py + tx fun transformYf(a: Float, b: Float, c: Float, d: Float, tx: Float, ty: Float, px: Float, py: Float): Float = d * py + b * px + ty @@ -84,7 +105,7 @@ data class Matrix( } } - fun setTo(a: Double, b: Double, c: Double, d: Double, tx: Double, ty: Double): Matrix { + fun setTo(a: Double, b: Double, c: Double, d: Double, tx: Double, ty: Double): MMatrix { this.a = a this.b = b this.c = c @@ -94,19 +115,19 @@ data class Matrix( return this } - fun setTo(a: Float, b: Float, c: Float, d: Float, tx: Float, ty: Float): Matrix = setTo(a.toDouble(), b.toDouble(), c.toDouble(), d.toDouble(), tx.toDouble(), ty.toDouble()) - fun setTo(a: Int, b: Int, c: Int, d: Int, tx: Int, ty: Int): Matrix = setTo(a.toDouble(), b.toDouble(), c.toDouble(), d.toDouble(), tx.toDouble(), ty.toDouble()) + fun setTo(a: Float, b: Float, c: Float, d: Float, tx: Float, ty: Float): MMatrix = setTo(a.toDouble(), b.toDouble(), c.toDouble(), d.toDouble(), tx.toDouble(), ty.toDouble()) + fun setTo(a: Int, b: Int, c: Int, d: Int, tx: Int, ty: Int): MMatrix = setTo(a.toDouble(), b.toDouble(), c.toDouble(), d.toDouble(), tx.toDouble(), ty.toDouble()) - fun copyTo(that: Matrix = Matrix()): Matrix { + fun copyTo(that: MMatrix = MMatrix()): MMatrix { that.copyFrom(this) return that } - fun copyFromInverted(that: Matrix): Matrix { + fun copyFromInverted(that: MMatrix): MMatrix { return invert(that) } - fun copyFrom(that: Matrix?): Matrix { + fun copyFrom(that: MMatrix?): MMatrix { if (that != null) { setTo(that.a, that.b, that.c, that.d, that.tx, that.ty) } else { @@ -133,7 +154,7 @@ data class Matrix( tx = tx1 } - fun skew(skewX: Angle, skewY: Angle): Matrix { + fun skew(skewX: Angle, skewY: Angle): MMatrix { val sinX = sin(skewX) val cosX = cos(skewX) val sinY = sin(skewY) @@ -166,21 +187,21 @@ data class Matrix( fun pretranslate(dx: Int, dy: Int) = pretranslate(dx.toDouble(), dy.toDouble()) fun prerotate(angle: Angle) = this.apply { - val m = Matrix() + val m = MMatrix() m.rotate(angle) this.premultiply(m) } fun preskew(skewX: Angle, skewY: Angle) = this.apply { - val m = Matrix() + val m = MMatrix() m.skew(skewX, skewY) this.premultiply(m) } - fun premultiply(m: Matrix) = this.premultiply(m.a, m.b, m.c, m.d, m.tx, m.ty) - fun postmultiply(m: Matrix) = multiply(this, m) + fun premultiply(m: MMatrix) = this.premultiply(m.a, m.b, m.c, m.d, m.tx, m.ty) + fun postmultiply(m: MMatrix) = multiply(this, m) - fun premultiply(la: Double, lb: Double, lc: Double, ld: Double, ltx: Double, lty: Double): Matrix = setTo( + fun premultiply(la: Double, lb: Double, lc: Double, ld: Double, ltx: Double, lty: Double): MMatrix = setTo( la * a + lb * c, la * b + lb * d, lc * a + ld * c, @@ -188,10 +209,10 @@ data class Matrix( ltx * a + lty * c + tx, ltx * b + lty * d + ty ) - fun premultiply(la: Float, lb: Float, lc: Float, ld: Float, ltx: Float, lty: Float): Matrix = premultiply(la.toDouble(), lb.toDouble(), lc.toDouble(), ld.toDouble(), ltx.toDouble(), lty.toDouble()) - fun premultiply(la: Int, lb: Int, lc: Int, ld: Int, ltx: Int, lty: Int): Matrix = premultiply(la.toDouble(), lb.toDouble(), lc.toDouble(), ld.toDouble(), ltx.toDouble(), lty.toDouble()) + fun premultiply(la: Float, lb: Float, lc: Float, ld: Float, ltx: Float, lty: Float): MMatrix = premultiply(la.toDouble(), lb.toDouble(), lc.toDouble(), ld.toDouble(), ltx.toDouble(), lty.toDouble()) + fun premultiply(la: Int, lb: Int, lc: Int, ld: Int, ltx: Int, lty: Int): MMatrix = premultiply(la.toDouble(), lb.toDouble(), lc.toDouble(), ld.toDouble(), ltx.toDouble(), lty.toDouble()) - fun multiply(l: Matrix, r: Matrix): Matrix = setTo( + fun multiply(l: MMatrix, r: MMatrix): MMatrix = setTo( l.a * r.a + l.b * r.c, l.a * r.b + l.b * r.d, l.c * r.a + l.d * r.c, @@ -201,9 +222,9 @@ data class Matrix( ) /** Transform point without translation */ - fun deltaTransformPoint(point: IPoint, out: Point = Point()) = deltaTransformPoint(point.x, point.y, out) - fun deltaTransformPoint(x: Float, y: Float, out: Point = Point()): Point = deltaTransformPoint(x.toDouble(), y.toDouble(), out) - fun deltaTransformPoint(x: Double, y: Double, out: Point = Point()): Point { + fun deltaTransformPoint(point: IPoint, out: MPoint = MPoint()) = deltaTransformPoint(point.x, point.y, out) + fun deltaTransformPoint(x: Float, y: Float, out: MPoint = MPoint()): MPoint = deltaTransformPoint(x.toDouble(), y.toDouble(), out) + fun deltaTransformPoint(x: Double, y: Double, out: MPoint = MPoint()): MPoint { out.x = deltaTransformX(x, y) out.y = deltaTransformY(x, y) return out @@ -217,7 +238,7 @@ data class Matrix( fun isIdentity() = getType() == Type.IDENTITY - fun invert(matrixToInvert: Matrix = this): Matrix { + fun invert(matrixToInvert: MMatrix = this): MMatrix { val src = matrixToInvert val dst = this val norm = src.a * src.d - src.b * src.c @@ -236,17 +257,17 @@ data class Matrix( return this } - fun concat(value: Matrix): Matrix = this.multiply(this, value) - fun preconcat(value: Matrix): Matrix = this.multiply(this, value) - fun postconcat(value: Matrix): Matrix = this.multiply(value, this) + fun concat(value: MMatrix): MMatrix = this.multiply(this, value) + fun preconcat(value: MMatrix): MMatrix = this.multiply(this, value) + fun postconcat(value: MMatrix): MMatrix = this.multiply(value, this) - fun inverted(out: Matrix = Matrix()) = out.invert(this) + fun inverted(out: MMatrix = MMatrix()) = out.invert(this) fun setTransform( transform: Transform, pivotX: Double = 0.0, pivotY: Double = 0.0, - ): Matrix { + ): MMatrix { return setTransform( transform.x, transform.y, transform.scaleX, transform.scaleY, @@ -265,7 +286,7 @@ data class Matrix( skewY: Angle = Angle.ZERO, pivotX: Double = 0.0, pivotY: Double = 0.0, - ): Matrix { + ): MMatrix { // +0.0 drops the negative -0.0 this.a = cos(rotation + skewY) * scaleX + 0.0 this.b = sin(rotation + skewY) * scaleX + 0.0 @@ -281,13 +302,13 @@ data class Matrix( } return this } - fun setTransform(x: Float = 0f, y: Float = 0f, scaleX: Float = 1f, scaleY: Float = 1f, rotation: Angle = Angle.ZERO, skewX: Angle = Angle.ZERO, skewY: Angle = Angle.ZERO): Matrix = + fun setTransform(x: Float = 0f, y: Float = 0f, scaleX: Float = 1f, scaleY: Float = 1f, rotation: Angle = Angle.ZERO, skewX: Angle = Angle.ZERO, skewY: Angle = Angle.ZERO): MMatrix = setTransform(x.toDouble(), y.toDouble(), scaleX.toDouble(), scaleY.toDouble(), rotation, skewX, skewY) - fun clone(): Matrix = Matrix(a, b, c, d, tx, ty) + fun clone(): MMatrix = MMatrix(a, b, c, d, tx, ty) - operator fun times(that: Matrix): Matrix = Matrix().multiply(this, that) - operator fun times(scale: Double): Matrix = Matrix().copyFrom(this).scale(scale) + operator fun times(that: MMatrix): MMatrix = MMatrix().multiply(this, that) + operator fun times(scale: Double): MMatrix = MMatrix().copyFrom(this).scale(scale) fun toTransform(out: Transform = Transform()): Transform { out.setMatrixNoReturn(this) @@ -295,10 +316,10 @@ data class Matrix( } // Transform points - fun transform(p: IPoint, out: Point = Point()): Point = transform(p.x, p.y, out) - fun transform(px: Double, py: Double, out: Point = Point()): Point = out.setTo(transformX(px, py), transformY(px, py)) - fun transform(px: Float, py: Float, out: Point = Point()): Point = out.setTo(transformX(px, py), transformY(px, py)) - fun transform(px: Int, py: Int, out: Point = Point()): Point = out.setTo(transformX(px, py), transformY(px, py)) + fun transform(p: IPoint, out: MPoint = MPoint()): MPoint = transform(p.x, p.y, out) + fun transform(px: Double, py: Double, out: MPoint = MPoint()): MPoint = out.setTo(transformX(px, py), transformY(px, py)) + fun transform(px: Float, py: Float, out: MPoint = MPoint()): MPoint = out.setTo(transformX(px, py), transformY(px, py)) + fun transform(px: Int, py: Int, out: MPoint = MPoint()): MPoint = out.setTo(transformX(px, py), transformY(px, py)) fun transformX(p: IPoint): Double = transformX(p.x, p.y) fun transformX(px: Double, py: Double): Double = this.a * px + this.c * py + this.tx @@ -321,7 +342,7 @@ data class Matrix( fun transformYf(px: Int, py: Int): Float = transformY(px.toDouble(), py.toDouble()).toFloat() @Suppress("DuplicatedCode") - fun transformRectangle(rectangle: Rectangle, delta: Boolean = false) { + fun transformRectangle(rectangle: MRectangle, delta: Boolean = false) { val a = this.af val b = this.bf val c = this.cf @@ -374,12 +395,12 @@ data class Matrix( rectangle.height = ceil((if (y1 > y3) y1 else y3) - rectangle.y) } - fun copyFromArray(value: FloatArray, offset: Int = 0): Matrix = setTo( + fun copyFromArray(value: FloatArray, offset: Int = 0): MMatrix = setTo( value[offset + 0], value[offset + 1], value[offset + 2], value[offset + 3], value[offset + 4], value[offset + 5] ) - fun copyFromArray(value: DoubleArray, offset: Int = 0): Matrix = setTo( + fun copyFromArray(value: DoubleArray, offset: Int = 0): MMatrix = setTo( value[offset + 0].toFloat(), value[offset + 1].toFloat(), value[offset + 2].toFloat(), value[offset + 3].toFloat(), value[offset + 4].toFloat(), value[offset + 5].toFloat() ) @@ -393,15 +414,7 @@ data class Matrix( var scaleX: Double = 1.0, var scaleY: Double = 1.0, var skewX: Angle = 0.radians, var skewY: Angle = 0.radians, var rotation: Angle = 0.radians - ) : MutableInterpolable, Interpolable, XY, XYf { - - override var xf: Float - get() = x.toFloat() - set(value) { x = value.toDouble() } - - override var yf: Float - get() = y.toFloat() - set(value) { y = value.toDouble() } + ) : MutableInterpolable, Interpolable, IMPoint { var scaleAvg: Double get() = (scaleX + scaleY) * 0.5 @@ -432,7 +445,7 @@ data class Matrix( rotation = 0.0.radians } - fun setMatrixNoReturn(matrix: Matrix, pivotX: Double = 0.0, pivotY: Double = 0.0) { + fun setMatrixNoReturn(matrix: MMatrix, pivotX: Double = 0.0, pivotY: Double = 0.0) { val a = matrix.a val b = matrix.b val c = matrix.c @@ -465,12 +478,12 @@ data class Matrix( } } - fun setMatrix(matrix: Matrix, pivotX: Double = 0.0, pivotY: Double = 0.0): Transform { + fun setMatrix(matrix: MMatrix, pivotX: Double = 0.0, pivotY: Double = 0.0): Transform { setMatrixNoReturn(matrix, pivotX, pivotY) return this } - fun toMatrix(out: Matrix = Matrix()): Matrix = out.setTransform(x, y, scaleX, scaleY, rotation, skewX, skewY) + fun toMatrix(out: MMatrix = MMatrix()): MMatrix = out.setTransform(x, y, scaleX, scaleY, rotation, skewX, skewY) fun copyFrom(that: Transform) = setTo(that.x, that.y, that.scaleX, that.scaleY, that.rotation, that.skewX, that.skewY) fun setTo(x: Double, y: Double, scaleX: Double, scaleY: Double, rotation: Angle, skewX: Angle, skewY: Angle): Transform { @@ -509,13 +522,13 @@ data class Matrix( fun clone() = Transform().copyFrom(this) } - class Computed(val matrix: Matrix, val transform: Transform) { + class Computed(val matrix: MMatrix, val transform: Transform) { companion object; - constructor(matrix: Matrix) : this(matrix, Transform().also { it.setMatrixNoReturn(matrix) }) + constructor(matrix: MMatrix) : this(matrix, Transform().also { it.setMatrixNoReturn(matrix) }) constructor(transform: Transform) : this(transform.toMatrix(), transform) } - override fun setToInterpolated(ratio: Double, l: Matrix, r: Matrix) = this.setTo( + override fun setToInterpolated(ratio: Double, l: MMatrix, r: MMatrix) = this.setTo( a = ratio.interpolate(l.a, r.a), b = ratio.interpolate(l.b, r.b), c = ratio.interpolate(l.c, r.c), @@ -524,10 +537,10 @@ data class Matrix( ty = ratio.interpolate(l.ty, r.ty) ) - override fun interpolateWith(ratio: Double, other: Matrix): Matrix = - Matrix().setToInterpolated(ratio, this, other) + override fun interpolateWith(ratio: Double, other: MMatrix): MMatrix = + MMatrix().setToInterpolated(ratio, this, other) - inline fun keepMatrix(callback: (Matrix) -> T): T { + inline fun keepMatrix(callback: (MMatrix) -> T): T { val a = this.a val b = this.b val c = this.c @@ -548,3 +561,14 @@ data class Matrix( override fun toString(): String = "Matrix(a=$a, b=$b, c=$c, d=$d, tx=$tx, ty=$ty)" } + +@JvmName("multiplyNullable") +fun MMatrix.multiply(l: MMatrix?, r: MMatrix?): MMatrix { + when { + l != null && r != null -> multiply(l, r) + l != null -> copyFrom(l) + r != null -> copyFrom(r) + else -> identity() + } + return this +} diff --git a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Matrix3D.kt b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Matrix4.kt similarity index 74% rename from korma/src/commonMain/kotlin/com/soywiz/korma/geom/Matrix3D.kt rename to korma/src/commonMain/kotlin/com/soywiz/korma/geom/Matrix4.kt index e4a571d081..4c64c12953 100644 --- a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Matrix3D.kt +++ b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Matrix4.kt @@ -8,10 +8,21 @@ import kotlin.math.sqrt import kotlin.math.tan import kotlin.native.concurrent.ThreadLocal +// @TODO: WIP +// @TODO: value class +data class Matrix4( + val v00: Float, val v01: Float, val v02: Float, val v03: Float, + val v10: Float, val v11: Float, val v12: Float, val v13: Float, + val v20: Float, val v21: Float, val v22: Float, val v23: Float, + val v30: Float, val v31: Float, val v32: Float, val v33: Float, +) + enum class MajorOrder { ROW, COLUMN } +typealias MMatrix4 = MMatrix3D + // Stored as four consecutive column vectors (effectively stored in column-major order) see https://en.wikipedia.org/wiki/Row-_and_column-major_order -class Matrix3D { +class MMatrix3D { val data: FloatArray = floatArrayOf( 1f, 0f, 0f, 0f, // column-0 0f, 1f, 0f, 0f, // column-1 @@ -40,7 +51,7 @@ class Matrix3D { const val M23 = 14 const val M33 = 15 - operator fun invoke(m: Matrix3D) = Matrix3D().copyFrom(m) + operator fun invoke(m: MMatrix3D) = MMatrix3D().copyFrom(m) fun rowMajorIndex(row: Int, column: Int) = row * 4 + column fun columnMajorIndex(row: Int, column: Int) = column * 4 + row @@ -85,9 +96,9 @@ class Matrix3D { var v32: Float get() = data[M32]; set(v) { data[M32] = v } var v33: Float get() = data[M33]; set(v) { data[M33] = v } - val transposed: Matrix3D get() = this.clone().transpose() + val transposed: MMatrix3D get() = this.clone().transpose() - fun transpose(): Matrix3D = setColumns( + fun transpose(): MMatrix3D = setColumns( v00, v01, v02, v03, v10, v11, v12, v13, v20, v21, v22, v23, @@ -99,7 +110,7 @@ class Matrix3D { a10: Float, a11: Float, a12: Float, a13: Float, a20: Float, a21: Float, a22: Float, a23: Float, a30: Float, a31: Float, a32: Float, a33: Float - ): Matrix3D = this.apply { + ): MMatrix3D = this.apply { v00 = a00; v01 = a01; v02 = a02; v03 = a03 v10 = a10; v11 = a11; v12 = a12; v13 = a13 v20 = a20; v21 = a21; v22 = a22; v23 = a23 @@ -111,7 +122,7 @@ class Matrix3D { a01: Float, a11: Float, a21: Float, a31: Float, a02: Float, a12: Float, a22: Float, a32: Float, a03: Float, a13: Float, a23: Float, a33: Float - ): Matrix3D { + ): MMatrix3D { v00 = a00; v01 = a01; v02 = a02; v03 = a03 v10 = a10; v11 = a11; v12 = a12; v13 = a13 v20 = a20; v21 = a21; v22 = a22; v23 = a23 @@ -119,21 +130,21 @@ class Matrix3D { return this } - fun setColumns4x4(f: FloatArray, offset: Int): Matrix3D = setColumns( + fun setColumns4x4(f: FloatArray, offset: Int): MMatrix3D = setColumns( f[offset + 0], f[offset + 1], f[offset + 2], f[offset + 3], f[offset + 4], f[offset + 5], f[offset + 6], f[offset + 7], f[offset + 8], f[offset + 9], f[offset + 10], f[offset + 11], f[offset + 12], f[offset + 13], f[offset + 14], f[offset + 15] ) - fun setRows4x4(f: FloatArray, offset: Int): Matrix3D = setRows( + fun setRows4x4(f: FloatArray, offset: Int): MMatrix3D = setRows( f[offset + 0], f[offset + 1], f[offset + 2], f[offset + 3], f[offset + 4], f[offset + 5], f[offset + 6], f[offset + 7], f[offset + 8], f[offset + 9], f[offset + 10], f[offset + 11], f[offset + 12], f[offset + 13], f[offset + 14], f[offset + 15] ) - fun setColumns3x3(f: FloatArray, offset: Int): Matrix3D = setColumns( + fun setColumns3x3(f: FloatArray, offset: Int): MMatrix3D = setColumns( f[offset + 0], f[offset + 1], f[offset + 2], 0f, f[offset + 3], f[offset + 4], f[offset + 5], 0f, f[offset + 6], f[offset + 7], f[offset + 8], 0f, @@ -161,29 +172,29 @@ class Matrix3D { 0f, 0f, 0f, 1f ) - fun setRow(row: Int, a: Float, b: Float, c: Float, d: Float): Matrix3D { + fun setRow(row: Int, a: Float, b: Float, c: Float, d: Float): MMatrix3D { data[columnMajorIndex(row, 0)] = a data[columnMajorIndex(row, 1)] = b data[columnMajorIndex(row, 2)] = c data[columnMajorIndex(row, 3)] = d return this } - fun setRow(row: Int, a: Double, b: Double, c: Double, d: Double): Matrix3D = setRow(row, a.toFloat(), b.toFloat(), c.toFloat(), d.toFloat()) - fun setRow(row: Int, a: Int, b: Int, c: Int, d: Int): Matrix3D = setRow(row, a.toFloat(), b.toFloat(), c.toFloat(), d.toFloat()) - fun setRow(row: Int, data: FloatArray): Matrix3D = setRow(row, data[0], data[1], data[2], data[3]) - fun setRow(row: Int, data: Vector3D): Matrix3D = setRow(row, data.x, data.y, data.w, data.z) + fun setRow(row: Int, a: Double, b: Double, c: Double, d: Double): MMatrix3D = setRow(row, a.toFloat(), b.toFloat(), c.toFloat(), d.toFloat()) + fun setRow(row: Int, a: Int, b: Int, c: Int, d: Int): MMatrix3D = setRow(row, a.toFloat(), b.toFloat(), c.toFloat(), d.toFloat()) + fun setRow(row: Int, data: FloatArray): MMatrix3D = setRow(row, data[0], data[1], data[2], data[3]) + fun setRow(row: Int, data: MVector4): MMatrix3D = setRow(row, data.x, data.y, data.w, data.z) - fun setColumn(column: Int, a: Float, b: Float, c: Float, d: Float): Matrix3D { + fun setColumn(column: Int, a: Float, b: Float, c: Float, d: Float): MMatrix3D { data[columnMajorIndex(0, column)] = a data[columnMajorIndex(1, column)] = b data[columnMajorIndex(2, column)] = c data[columnMajorIndex(3, column)] = d return this } - fun setColumn(column: Int, a: Double, b: Double, c: Double, d: Double): Matrix3D = setColumn(column, a.toFloat(), b.toFloat(), c.toFloat(), d.toFloat()) - fun setColumn(column: Int, a: Int, b: Int, c: Int, d: Int): Matrix3D = setColumn(column, a.toFloat(), b.toFloat(), c.toFloat(), d.toFloat()) - fun setColumn(column: Int, data: FloatArray): Matrix3D = setColumn(column, data[0], data[1], data[2], data[3]) - fun setColumn(column: Int, data: Vector3D): Matrix3D = setColumn(column, data.x, data.y, data.w, data.z) + fun setColumn(column: Int, a: Double, b: Double, c: Double, d: Double): MMatrix3D = setColumn(column, a.toFloat(), b.toFloat(), c.toFloat(), d.toFloat()) + fun setColumn(column: Int, a: Int, b: Int, c: Int, d: Int): MMatrix3D = setColumn(column, a.toFloat(), b.toFloat(), c.toFloat(), d.toFloat()) + fun setColumn(column: Int, data: FloatArray): MMatrix3D = setColumn(column, data[0], data[1], data[2], data[3]) + fun setColumn(column: Int, data: MVector4): MMatrix3D = setColumn(column, data.x, data.y, data.w, data.z) fun getRow(n: Int, target: FloatArray = FloatArray(4)): FloatArray { val m = n * 4 @@ -202,7 +213,7 @@ class Matrix3D { return target } - fun getRowVector(n: Int, target: Vector3D = Vector3D()): Vector3D { + fun getRowVector(n: Int, target: MVector4 = MVector4()): MVector4 { val m = n * 4 target.x = data[m + 0] target.y = data[m + 1] @@ -211,7 +222,7 @@ class Matrix3D { return target } - fun getColumnVector(n: Int, target: Vector3D = Vector3D()): Vector3D { + fun getColumnVector(n: Int, target: MVector4 = MVector4()): MVector4 { target.x = data[n + 0] target.y = data[n + 4] target.z = data[n + 8] @@ -260,7 +271,7 @@ class Matrix3D { 0f, 0f, 0f, 1f ) - fun setToTranslation(x: Float, y: Float, z: Float, w: Float = 1f): Matrix3D = this.setRows( + fun setToTranslation(x: Float, y: Float, z: Float, w: Float = 1f): MMatrix3D = this.setRows( 1f, 0f, 0f, x, 0f, 1f, 0f, y, 0f, 0f, 1f, z, @@ -269,7 +280,7 @@ class Matrix3D { fun setToTranslation(x: Double, y: Double, z: Double, w: Double = 1.0) = setToTranslation(x.toFloat(), y.toFloat(), z.toFloat(), w.toFloat()) fun setToTranslation(x: Int, y: Int, z: Int, w: Int = 1) = setToTranslation(x.toFloat(), y.toFloat(), z.toFloat(), w.toFloat()) - fun setToScale(x: Float, y: Float, z: Float, w: Float = 1f): Matrix3D = this.setRows( + fun setToScale(x: Float, y: Float, z: Float, w: Float = 1f): MMatrix3D = this.setRows( x, 0f, 0f, 0f, 0f, y, 0f, 0f, 0f, 0f, z, 0f, @@ -278,7 +289,7 @@ class Matrix3D { fun setToScale(x: Double, y: Double, z: Double, w: Double = 1.0) = setToScale(x.toFloat(), y.toFloat(), z.toFloat(), w.toFloat()) fun setToScale(x: Int, y: Int, z: Int, w: Int = 1) = setToScale(x.toFloat(), y.toFloat(), z.toFloat(), w.toFloat()) - fun setToShear(x: Float, y: Float, z: Float): Matrix3D = this.setRows( + fun setToShear(x: Float, y: Float, z: Float): MMatrix3D = this.setRows( 1f, y, z, 0f, x, 1f, z, 0f, x, y, 1f, 0f, @@ -287,7 +298,7 @@ class Matrix3D { fun setToShear(x: Double, y: Double, z: Double) = setToShear(x.toFloat(), y.toFloat(), z.toFloat()) fun setToShear(x: Int, y: Int, z: Int) = setToShear(x.toFloat(), y.toFloat(), z.toFloat()) - fun setToRotationX(angle: Angle): Matrix3D { + fun setToRotationX(angle: Angle): MMatrix3D { val c = cos(angle).toFloat() val s = sin(angle).toFloat() return this.setRows( @@ -298,7 +309,7 @@ class Matrix3D { ) } - fun setToRotationY(angle: Angle): Matrix3D { + fun setToRotationY(angle: Angle): MMatrix3D { val c = cos(angle).toFloat() val s = sin(angle).toFloat() return this.setRows( @@ -309,7 +320,7 @@ class Matrix3D { ) } - fun setToRotationZ(angle: Angle): Matrix3D { + fun setToRotationZ(angle: Angle): MMatrix3D { val c = cos(angle).toFloat() val s = sin(angle).toFloat() return this.setRows( @@ -320,7 +331,7 @@ class Matrix3D { ) } - fun setToRotation(angle: Angle, x: Float, y: Float, z: Float): Matrix3D { + fun setToRotation(angle: Angle, x: Float, y: Float, z: Float): MMatrix3D { val mag = sqrt(x * x + y * y + z * z) val norm = 1.0 / mag @@ -340,11 +351,11 @@ class Matrix3D { 0.0, 0.0, 0.0, 1.0 ) } - fun setToRotation(angle: Angle, direction: Vector3D): Matrix3D = setToRotation(angle, direction.x, direction.y, direction.z) - fun setToRotation(angle: Angle, x: Double, y: Double, z: Double): Matrix3D = setToRotation(angle, x.toFloat(), y.toFloat(), z.toFloat()) - fun setToRotation(angle: Angle, x: Int, y: Int, z: Int): Matrix3D = setToRotation(angle, x.toFloat(), y.toFloat(), z.toFloat()) + fun setToRotation(angle: Angle, direction: MVector4): MMatrix3D = setToRotation(angle, direction.x, direction.y, direction.z) + fun setToRotation(angle: Angle, x: Double, y: Double, z: Double): MMatrix3D = setToRotation(angle, x.toFloat(), y.toFloat(), z.toFloat()) + fun setToRotation(angle: Angle, x: Int, y: Int, z: Int): MMatrix3D = setToRotation(angle, x.toFloat(), y.toFloat(), z.toFloat()) - fun multiply(l: Matrix3D, r: Matrix3D) = this.setRows( + fun multiply(l: MMatrix3D, r: MMatrix3D) = this.setRows( (l.v00 * r.v00) + (l.v01 * r.v10) + (l.v02 * r.v20) + (l.v03 * r.v30), (l.v00 * r.v01) + (l.v01 * r.v11) + (l.v02 * r.v21) + (l.v03 * r.v31), (l.v00 * r.v02) + (l.v01 * r.v12) + (l.v02 * r.v22) + (l.v03 * r.v32), @@ -419,12 +430,12 @@ class Matrix3D { rv30.toFloat(), rv31.toFloat(), rv32.toFloat(), rv33.toFloat(), ) - fun multiply(scale: Float, l: Matrix3D = this): Matrix3D { + fun multiply(scale: Float, l: MMatrix3D = this): MMatrix3D { for (n in 0 until 16) this.data[n] = l.data[n] * scale return this } - fun copyFrom(that: Matrix3D): Matrix3D { + fun copyFrom(that: MMatrix3D): MMatrix3D { for (n in 0 until 16) this.data[n] = that.data[n] return this } @@ -435,23 +446,23 @@ class Matrix3D { fun transform3(x: Float, y: Float, z: Float, w: Float = 1f): Float = (v30 * x) + (v31 * y) + (v32 * z) + (v33 * w) /** [[THIS MATRIX]] * VECTOR */ - fun transform(x: Float, y: Float, z: Float, w: Float = 1f, out: Vector3D = Vector3D(0, 0, 0, 0)): Vector3D = out.setTo( + fun transform(x: Float, y: Float, z: Float, w: Float = 1f, out: MVector4 = MVector4(0, 0, 0, 0)): MVector4 = out.setTo( transform0(x, y, z, w), transform1(x, y, z, w), transform2(x, y, z, w), transform3(x, y, z, w) ) - fun transform(x: Float, y: Float, z: Float, out: Vector3 = Vector3(0, 0, 0)): Vector3 = out.setTo( + fun transform(x: Float, y: Float, z: Float, out: MVector3 = MVector3(0, 0, 0)): MVector3 = out.setTo( transform0(x, y, z, 0f), transform1(x, y, z, 0f), transform2(x, y, z, 0f), ) - fun transform(v: Vector3D, out: Vector3D = Vector3D()): Vector3D = transform(v.x, v.y, v.z, v.w, out) - fun transform(v: Vector3, out: Vector3 = Vector3()): Vector3 = transform(v.x, v.y, v.z, out) + fun transform(v: MVector4, out: MVector4 = MVector4()): MVector4 = transform(v.x, v.y, v.z, v.w, out) + fun transform(v: MVector3, out: MVector3 = MVector3()): MVector3 = transform(v.x, v.y, v.z, out) - fun setToOrtho(left: Float, right: Float, bottom: Float, top: Float, near: Float = 0f, far: Float = 1f): Matrix3D { + fun setToOrtho(left: Float, right: Float, bottom: Float, top: Float, near: Float = 0f, far: Float = 1f): MMatrix3D { val sx = 2f / (right - left) val sy = 2f / (top - bottom) val sz = -2f / (far - near) @@ -468,15 +479,15 @@ class Matrix3D { ) } - fun setToOrtho(rect: Rectangle, near: Double = 0.0, far: Double = 1.0): Matrix3D = setToOrtho(rect.left, rect.right, rect.bottom, rect.top, near, far) - fun setToOrtho(rect: Rectangle, near: Float = 0f, far: Float = 1f): Matrix3D = setToOrtho(rect.left, rect.right, rect.bottom, rect.top, near.toDouble(), far.toDouble()) - fun setToOrtho(rect: Rectangle, near: Int = 0, far: Int = 1): Matrix3D = setToOrtho(rect.left, rect.right, rect.bottom, rect.top, near.toDouble(), far.toDouble()) - fun setToOrtho(left: Double, right: Double, bottom: Double, top: Double, near: Double, far: Double): Matrix3D = + fun setToOrtho(rect: MRectangle, near: Double = 0.0, far: Double = 1.0): MMatrix3D = setToOrtho(rect.left, rect.right, rect.bottom, rect.top, near, far) + fun setToOrtho(rect: MRectangle, near: Float = 0f, far: Float = 1f): MMatrix3D = setToOrtho(rect.left, rect.right, rect.bottom, rect.top, near.toDouble(), far.toDouble()) + fun setToOrtho(rect: MRectangle, near: Int = 0, far: Int = 1): MMatrix3D = setToOrtho(rect.left, rect.right, rect.bottom, rect.top, near.toDouble(), far.toDouble()) + fun setToOrtho(left: Double, right: Double, bottom: Double, top: Double, near: Double, far: Double): MMatrix3D = setToOrtho(left.toFloat(), right.toFloat(), bottom.toFloat(), top.toFloat(), near.toFloat(), far.toFloat()) - fun setToOrtho(left: Int, right: Int, bottom: Int, top: Int, near: Int, far: Int): Matrix3D = + fun setToOrtho(left: Int, right: Int, bottom: Int, top: Int, near: Int, far: Int): MMatrix3D = setToOrtho(left.toFloat(), right.toFloat(), bottom.toFloat(), top.toFloat(), near.toFloat(), far.toFloat()) - fun setToFrustum(left: Float, right: Float, bottom: Float, top: Float, zNear: Float = 0f, zFar: Float = 1f): Matrix3D { + fun setToFrustum(left: Float, right: Float, bottom: Float, top: Float, zNear: Float = 0f, zFar: Float = 1f): MMatrix3D { if (zNear <= 0.0f || zFar <= zNear) { throw Exception("Error: Required zNear > 0 and zFar > zNear, but zNear $zNear, zFar $zFar") } @@ -500,36 +511,36 @@ class Matrix3D { 0f, 0f, -1f, 0f ) } - fun setToFrustum(rect: Rectangle, zNear: Double = 0.0, zFar: Double = 1.0): Matrix3D = setToFrustum(rect.left, rect.right, rect.bottom, rect.top, zNear.toDouble(), zFar.toDouble()) - fun setToFrustum(rect: Rectangle, zNear: Float = 0f, zFar: Float = 1f): Matrix3D = setToFrustum(rect.left, rect.right, rect.bottom, rect.top, zNear.toDouble(), zFar.toDouble()) - fun setToFrustum(rect: Rectangle, zNear: Int = 0, zFar: Int = 1): Matrix3D = setToFrustum(rect.left, rect.right, rect.bottom, rect.top, zNear.toDouble(), zFar.toDouble()) + fun setToFrustum(rect: MRectangle, zNear: Double = 0.0, zFar: Double = 1.0): MMatrix3D = setToFrustum(rect.left, rect.right, rect.bottom, rect.top, zNear.toDouble(), zFar.toDouble()) + fun setToFrustum(rect: MRectangle, zNear: Float = 0f, zFar: Float = 1f): MMatrix3D = setToFrustum(rect.left, rect.right, rect.bottom, rect.top, zNear.toDouble(), zFar.toDouble()) + fun setToFrustum(rect: MRectangle, zNear: Int = 0, zFar: Int = 1): MMatrix3D = setToFrustum(rect.left, rect.right, rect.bottom, rect.top, zNear.toDouble(), zFar.toDouble()) - fun setToFrustum(left: Double, right: Double, bottom: Double, top: Double, zNear: Double = 0.0, zFar: Double = 1.0): Matrix3D + fun setToFrustum(left: Double, right: Double, bottom: Double, top: Double, zNear: Double = 0.0, zFar: Double = 1.0): MMatrix3D = setToFrustum(left.toFloat(), right.toFloat(), bottom.toFloat(), top.toFloat(), zNear.toFloat(), zFar.toFloat()) - fun setToFrustum(left: Int, right: Int, bottom: Int, top: Int, zNear: Int = 0, zFar: Int = 1): Matrix3D + fun setToFrustum(left: Int, right: Int, bottom: Int, top: Int, zNear: Int = 0, zFar: Int = 1): MMatrix3D = setToFrustum(left.toFloat(), right.toFloat(), bottom.toFloat(), top.toFloat(), zNear.toFloat(), zFar.toFloat()) - fun setToPerspective(fovy: Angle, aspect: Float, zNear: Float, zFar: Float): Matrix3D { + fun setToPerspective(fovy: Angle, aspect: Float, zNear: Float, zFar: Float): MMatrix3D { val top = tan(fovy.radians / 2f) * zNear val bottom = -1.0f * top val left = aspect * bottom val right = aspect * top return setToFrustum(left.toFloat(), right.toFloat(), bottom.toFloat(), top.toFloat(), zNear, zFar) } - fun setToPerspective(fovy: Angle, aspect: Double, zNear: Double, zFar: Double): Matrix3D + fun setToPerspective(fovy: Angle, aspect: Double, zNear: Double, zFar: Double): MMatrix3D = setToPerspective(fovy, aspect.toFloat(), zNear.toFloat(), zFar.toFloat()) - fun extractTranslation(out: Vector3D = Vector3D()): Vector3D = getRowVector(3, out).also { it.w = 1f } + fun extractTranslation(out: MVector4 = MVector4()): MVector4 = getRowVector(3, out).also { it.w = 1f } - fun extractScale(out: Vector3D = Vector3D()): Vector3D { + fun extractScale(out: MVector4 = MVector4()): MVector4 { val x = getRowVector(0).length3 val y = getRowVector(1).length3 val z = getRowVector(2).length3 return out.setTo(x, y, z, 1f) } - fun extractRotation(row_normalise: Boolean = true, out: Quaternion = Quaternion()): Quaternion + fun extractRotation(row_normalise: Boolean = true, out: MQuaternion = MQuaternion()): MQuaternion { val v1 = this.getRowVector(0) val v2 = this.getRowVector(1) @@ -579,9 +590,9 @@ class Matrix3D { return out } - fun extractProjection(out: Vector3D = Vector3D()) = this.getColumnVector(3, out) + fun extractProjection(out: MVector4 = MVector4()) = this.getColumnVector(3, out) - override fun equals(other: Any?): Boolean = (other is Matrix3D) && this.data.contentEquals(other.data) + override fun equals(other: Any?): Boolean = (other is MMatrix3D) && this.data.contentEquals(other.data) override fun hashCode(): Int = data.contentHashCode() override fun toString(): String = buildString { @@ -598,340 +609,340 @@ class Matrix3D { append(")") } - fun clone(): Matrix3D = Matrix3D().copyFrom(this) + fun clone(): MMatrix3D = MMatrix3D().copyFrom(this) } -fun Matrix3D.copyToFloatWxH(out: FloatArray, rows: Int, columns: Int, order: MajorOrder) { +fun MMatrix3D.copyToFloatWxH(out: FloatArray, rows: Int, columns: Int, order: MajorOrder) { copyToFloatWxH(out, rows, columns, order, 0) } -fun Matrix3D.copyToFloatWxH(out: FloatArray, rows: Int, columns: Int, order: MajorOrder, offset: Int) { +fun MMatrix3D.copyToFloatWxH(out: FloatArray, rows: Int, columns: Int, order: MajorOrder, offset: Int) { var n = offset if (order == MajorOrder.ROW) { - for (column in 0 until columns) for (row in 0 until rows) out[n++] = data[Matrix3D.rowMajorIndex(row, column)] + for (column in 0 until columns) for (row in 0 until rows) out[n++] = data[MMatrix3D.rowMajorIndex(row, column)] } else { - for (column in 0 until columns) for (row in 0 until rows) out[n++] = data[Matrix3D.columnMajorIndex(row, column)] + for (column in 0 until columns) for (row in 0 until rows) out[n++] = data[MMatrix3D.columnMajorIndex(row, column)] } } -fun Matrix3D.copyToFloat2x2(out: FloatArray, order: MajorOrder) = copyToFloatWxH(out, 2, 2, order, 0) -fun Matrix3D.copyToFloat3x3(out: FloatArray, order: MajorOrder) = copyToFloatWxH(out, 3, 3, order, 0) -fun Matrix3D.copyToFloat4x4(out: FloatArray, order: MajorOrder) = copyToFloatWxH(out, 4, 4, order, 0) +fun MMatrix3D.copyToFloat2x2(out: FloatArray, order: MajorOrder) = copyToFloatWxH(out, 2, 2, order, 0) +fun MMatrix3D.copyToFloat3x3(out: FloatArray, order: MajorOrder) = copyToFloatWxH(out, 3, 3, order, 0) +fun MMatrix3D.copyToFloat4x4(out: FloatArray, order: MajorOrder) = copyToFloatWxH(out, 4, 4, order, 0) -fun Matrix3D.copyToFloat2x2(out: FloatArray, order: MajorOrder, offset: Int) = copyToFloatWxH(out, 2, 2, order, offset) -fun Matrix3D.copyToFloat3x3(out: FloatArray, order: MajorOrder, offset: Int) = copyToFloatWxH(out, 3, 3, order, offset) -fun Matrix3D.copyToFloat4x4(out: FloatArray, order: MajorOrder, offset: Int) = copyToFloatWxH(out, 4, 4, order, offset) +fun MMatrix3D.copyToFloat2x2(out: FloatArray, order: MajorOrder, offset: Int) = copyToFloatWxH(out, 2, 2, order, offset) +fun MMatrix3D.copyToFloat3x3(out: FloatArray, order: MajorOrder, offset: Int) = copyToFloatWxH(out, 3, 3, order, offset) +fun MMatrix3D.copyToFloat4x4(out: FloatArray, order: MajorOrder, offset: Int) = copyToFloatWxH(out, 4, 4, order, offset) -fun Matrix3D.setRows( +fun MMatrix3D.setRows( a00: Double, a01: Double, a02: Double, a03: Double, a10: Double, a11: Double, a12: Double, a13: Double, a20: Double, a21: Double, a22: Double, a23: Double, a30: Double, a31: Double, a32: Double, a33: Double -): Matrix3D = setRows( +): MMatrix3D = setRows( a00.toFloat(), a01.toFloat(), a02.toFloat(), a03.toFloat(), a10.toFloat(), a11.toFloat(), a12.toFloat(), a13.toFloat(), a20.toFloat(), a21.toFloat(), a22.toFloat(), a23.toFloat(), a30.toFloat(), a31.toFloat(), a32.toFloat(), a33.toFloat() ) -fun Matrix3D.setRows( +fun MMatrix3D.setRows( a00: Float, a01: Float, a02: Float, a03: Float, a10: Float, a11: Float, a12: Float, a13: Float, a20: Float, a21: Float, a22: Float, a23: Float, a30: Float, a31: Float, a32: Float, a33: Float -): Matrix3D = setRows( +): MMatrix3D = setRows( a00, a01, a02, a03, a10, a11, a12, a13, a20, a21, a22, a23, a30, a31, a32, a33 ) -fun Matrix3D.setColumns( +fun MMatrix3D.setColumns( a00: Double, a10: Double, a20: Double, a30: Double, a01: Double, a11: Double, a21: Double, a31: Double, a02: Double, a12: Double, a22: Double, a32: Double, a03: Double, a13: Double, a23: Double, a33: Double -): Matrix3D = setColumns( +): MMatrix3D = setColumns( a00.toFloat(), a10.toFloat(), a20.toFloat(), a30.toFloat(), a01.toFloat(), a11.toFloat(), a21.toFloat(), a31.toFloat(), a02.toFloat(), a12.toFloat(), a22.toFloat(), a32.toFloat(), a03.toFloat(), a13.toFloat(), a23.toFloat(), a33.toFloat() ) -fun Matrix3D.setColumns( +fun MMatrix3D.setColumns( a00: Float, a10: Float, a20: Float, a30: Float, a01: Float, a11: Float, a21: Float, a31: Float, a02: Float, a12: Float, a22: Float, a32: Float, a03: Float, a13: Float, a23: Float, a33: Float -): Matrix3D = setColumns( +): MMatrix3D = setColumns( a00, a10, a20, a30, a01, a11, a21, a31, a02, a12, a22, a32, a03, a13, a23, a33 ) -fun Matrix3D.setRows3x3( +fun MMatrix3D.setRows3x3( a00: Double, a01: Double, a02: Double, a10: Double, a11: Double, a12: Double, a20: Double, a21: Double, a22: Double -): Matrix3D = setRows( +): MMatrix3D = setRows( a00.toFloat(), a01.toFloat(), a02.toFloat(), 0f, a10.toFloat(), a11.toFloat(), a12.toFloat(), 0f, a20.toFloat(), a21.toFloat(), a22.toFloat(), 0f, 0f, 0f, 0f, 1f ) -fun Matrix3D.setRows3x3( +fun MMatrix3D.setRows3x3( a00: Float, a01: Float, a02: Float, a10: Float, a11: Float, a12: Float, a20: Float, a21: Float, a22: Float -): Matrix3D = setRows( +): MMatrix3D = setRows( a00, a01, a02, 0f, a10, a11, a12, 0f, a20, a21, a22, 0f, 0f, 0f, 0f, 1f ) -fun Matrix3D.setColumns3x3( +fun MMatrix3D.setColumns3x3( a00: Double, a10: Double, a20: Double, a01: Double, a11: Double, a21: Double, a02: Double, a12: Double, a22: Double -): Matrix3D = setColumns( +): MMatrix3D = setColumns( a00.toFloat(), a10.toFloat(), a20.toFloat(), 0f, a01.toFloat(), a11.toFloat(), a21.toFloat(), 0f, a02.toFloat(), a12.toFloat(), a22.toFloat(), 0f, 0f, 0f, 0f, 1f ) -fun Matrix3D.setColumns3x3( +fun MMatrix3D.setColumns3x3( a00: Float, a10: Float, a20: Float, a01: Float, a11: Float, a21: Float, a02: Float, a12: Float, a22: Float -): Matrix3D = setColumns( +): MMatrix3D = setColumns( a00, a10, a20, 0f, a01, a11, a21, 0f, a02, a12, a22, 0f, 0f, 0f, 0f, 1f ) -fun Matrix3D.setRows2x2( +fun MMatrix3D.setRows2x2( a00: Double, a01: Double, a10: Double, a11: Double -): Matrix3D = setRows( +): MMatrix3D = setRows( a00.toFloat(), a01.toFloat(), 0f, 0f, a10.toFloat(), a11.toFloat(), 0f, 0f, 0f, 0f, 1f, 0f, 0f, 0f, 0f, 1f ) -fun Matrix3D.setRows2x2( +fun MMatrix3D.setRows2x2( a00: Float, a01: Float, a10: Float, a11: Float -): Matrix3D = setRows( +): MMatrix3D = setRows( a00, a01, 0f, 0f, a10, a11, 0f, 0f, 0f, 0f, 1f, 0f, 0f, 0f, 0f, 1f ) -fun Matrix3D.Companion.fromRows( +fun MMatrix3D.Companion.fromRows( a00: Double, a01: Double, a02: Double, a03: Double, a10: Double, a11: Double, a12: Double, a13: Double, a20: Double, a21: Double, a22: Double, a23: Double, a30: Double, a31: Double, a32: Double, a33: Double -): Matrix3D = Matrix3D().setRows( +): MMatrix3D = MMatrix3D().setRows( a00.toFloat(), a01.toFloat(), a02.toFloat(), a03.toFloat(), a10.toFloat(), a11.toFloat(), a12.toFloat(), a13.toFloat(), a20.toFloat(), a21.toFloat(), a22.toFloat(), a23.toFloat(), a30.toFloat(), a31.toFloat(), a32.toFloat(), a33.toFloat() ) -fun Matrix3D.Companion.fromRows( +fun MMatrix3D.Companion.fromRows( a00: Float, a01: Float, a02: Float, a03: Float, a10: Float, a11: Float, a12: Float, a13: Float, a20: Float, a21: Float, a22: Float, a23: Float, a30: Float, a31: Float, a32: Float, a33: Float -): Matrix3D = Matrix3D().setRows( +): MMatrix3D = MMatrix3D().setRows( a00, a01, a02, a03, a10, a11, a12, a13, a20, a21, a22, a23, a30, a31, a32, a33 ) -fun Matrix3D.Companion.fromColumns( +fun MMatrix3D.Companion.fromColumns( a00: Double, a10: Double, a20: Double, a30: Double, a01: Double, a11: Double, a21: Double, a31: Double, a02: Double, a12: Double, a22: Double, a32: Double, a03: Double, a13: Double, a23: Double, a33: Double -): Matrix3D = Matrix3D().setColumns( +): MMatrix3D = MMatrix3D().setColumns( a00.toFloat(), a10.toFloat(), a20.toFloat(), a30.toFloat(), a01.toFloat(), a11.toFloat(), a21.toFloat(), a31.toFloat(), a02.toFloat(), a12.toFloat(), a22.toFloat(), a32.toFloat(), a03.toFloat(), a13.toFloat(), a23.toFloat(), a33.toFloat() ) -fun Matrix3D.Companion.fromColumns( +fun MMatrix3D.Companion.fromColumns( a00: Float, a10: Float, a20: Float, a30: Float, a01: Float, a11: Float, a21: Float, a31: Float, a02: Float, a12: Float, a22: Float, a32: Float, a03: Float, a13: Float, a23: Float, a33: Float -): Matrix3D = Matrix3D().setColumns( +): MMatrix3D = MMatrix3D().setColumns( a00, a10, a20, a30, a01, a11, a21, a31, a02, a12, a22, a32, a03, a13, a23, a33 ) -fun Matrix3D.setColumns2x2( +fun MMatrix3D.setColumns2x2( a00: Double, a10: Double, a01: Double, a11: Double -): Matrix3D = setColumns( +): MMatrix3D = setColumns( a00.toFloat(), a10.toFloat(), 0f, 0f, a01.toFloat(), a11.toFloat(), 0f, 0f, 0f, 0f, 1f, 0f, 0f, 0f, 0f, 1f ) -fun Matrix3D.setColumns2x2( +fun MMatrix3D.setColumns2x2( a00: Float, a10: Float, a01: Float, a11: Float -): Matrix3D = setColumns( +): MMatrix3D = setColumns( a00, a10, 0f, 0f, a01, a11, 0f, 0f, 0f, 0f, 1f, 0f, 0f, 0f, 0f, 1f ) -fun Matrix3D.Companion.fromRows3x3( +fun MMatrix3D.Companion.fromRows3x3( a00: Double, a01: Double, a02: Double, a10: Double, a11: Double, a12: Double, a20: Double, a21: Double, a22: Double -): Matrix3D = Matrix3D().setRows3x3( +): MMatrix3D = MMatrix3D().setRows3x3( a00.toFloat(), a01.toFloat(), a02.toFloat(), a10.toFloat(), a11.toFloat(), a12.toFloat(), a20.toFloat(), a21.toFloat(), a22.toFloat() ) -fun Matrix3D.Companion.fromRows3x3( +fun MMatrix3D.Companion.fromRows3x3( a00: Float, a01: Float, a02: Float, a10: Float, a11: Float, a12: Float, a20: Float, a21: Float, a22: Float -): Matrix3D = Matrix3D().setRows3x3( +): MMatrix3D = MMatrix3D().setRows3x3( a00, a01, a02, a10, a11, a12, a20, a21, a22 ) -fun Matrix3D.Companion.fromColumns3x3( +fun MMatrix3D.Companion.fromColumns3x3( a00: Double, a10: Double, a20: Double, a01: Double, a11: Double, a21: Double, a02: Double, a12: Double, a22: Double -): Matrix3D = Matrix3D().setColumns3x3( +): MMatrix3D = MMatrix3D().setColumns3x3( a00.toFloat(), a10.toFloat(), a20.toFloat(), a01.toFloat(), a11.toFloat(), a21.toFloat(), a02.toFloat(), a12.toFloat(), a22.toFloat() ) -fun Matrix3D.Companion.fromColumns3x3( +fun MMatrix3D.Companion.fromColumns3x3( a00: Float, a10: Float, a20: Float, a01: Float, a11: Float, a21: Float, a02: Float, a12: Float, a22: Float -): Matrix3D = Matrix3D().setColumns3x3( +): MMatrix3D = MMatrix3D().setColumns3x3( a00, a10, a20, a01, a11, a21, a02, a12, a22 ) -fun Matrix3D.Companion.fromRows2x2( +fun MMatrix3D.Companion.fromRows2x2( a00: Double, a01: Double, a10: Double, a11: Double -): Matrix3D = Matrix3D().setRows2x2( +): MMatrix3D = MMatrix3D().setRows2x2( a00.toFloat(), a01.toFloat(), a10.toFloat(), a11.toFloat() ) -fun Matrix3D.Companion.fromRows2x2( +fun MMatrix3D.Companion.fromRows2x2( a00: Float, a01: Float, a10: Float, a11: Float -): Matrix3D = Matrix3D().setRows2x2( +): MMatrix3D = MMatrix3D().setRows2x2( a00, a01, a10, a11 ) -fun Matrix3D.Companion.fromColumns2x2( +fun MMatrix3D.Companion.fromColumns2x2( a00: Double, a10: Double, a01: Double, a11: Double -): Matrix3D = Matrix3D().setColumns2x2( +): MMatrix3D = MMatrix3D().setColumns2x2( a00.toFloat(), a10.toFloat(), a01.toFloat(), a11.toFloat() ) -fun Matrix3D.Companion.fromColumns2x2( +fun MMatrix3D.Companion.fromColumns2x2( a00: Float, a10: Float, a01: Float, a11: Float -): Matrix3D = Matrix3D().setColumns2x2( +): MMatrix3D = MMatrix3D().setColumns2x2( a00, a10, a01, a11 ) -operator fun Matrix3D.times(that: Matrix3D): Matrix3D = Matrix3D().multiply(this, that) -operator fun Matrix3D.times(value: Float): Matrix3D = Matrix3D(this).multiply(value) -operator fun Matrix3D.times(value: Double): Matrix3D = this * value.toFloat() -operator fun Matrix3D.times(value: Int): Matrix3D = this * value.toFloat() +operator fun MMatrix3D.times(that: MMatrix3D): MMatrix3D = MMatrix3D().multiply(this, that) +operator fun MMatrix3D.times(value: Float): MMatrix3D = MMatrix3D(this).multiply(value) +operator fun MMatrix3D.times(value: Double): MMatrix3D = this * value.toFloat() +operator fun MMatrix3D.times(value: Int): MMatrix3D = this * value.toFloat() -operator fun Matrix3D.div(value: Float): Matrix3D = this * (1f / value) -operator fun Matrix3D.div(value: Double): Matrix3D = this / value.toFloat() -operator fun Matrix3D.div(value: Int): Matrix3D = this / value.toFloat() +operator fun MMatrix3D.div(value: Float): MMatrix3D = this * (1f / value) +operator fun MMatrix3D.div(value: Double): MMatrix3D = this / value.toFloat() +operator fun MMatrix3D.div(value: Int): MMatrix3D = this / value.toFloat() -fun Matrix3D.multiply(scale: Double, l: Matrix3D = this) = multiply(scale.toFloat(), l) -fun Matrix3D.multiply(scale: Int, l: Matrix3D = this) = multiply(scale.toFloat(), l) +fun MMatrix3D.multiply(scale: Double, l: MMatrix3D = this) = multiply(scale.toFloat(), l) +fun MMatrix3D.multiply(scale: Int, l: MMatrix3D = this) = multiply(scale.toFloat(), l) @PublishedApi @ThreadLocal -internal val tempMat3D = Matrix3D() +internal val tempMat3D = MMatrix3D() -fun Matrix3D.translate(x: Float, y: Float, z: Float, w: Float = 1f, temp: Matrix3D = tempMat3D) = this.apply { +fun MMatrix3D.translate(x: Float, y: Float, z: Float, w: Float = 1f, temp: MMatrix3D = tempMat3D) = this.apply { temp.setToTranslation(x, y, z, w) this.multiply(this, temp) } -fun Matrix3D.translate(x: Double, y: Double, z: Double, w: Double = 1.0, temp: Matrix3D = tempMat3D) = this.translate(x.toFloat(), y.toFloat(), z.toFloat(), w.toFloat(), temp) -fun Matrix3D.translate(x: Int, y: Int, z: Int, w: Int = 1, temp: Matrix3D = tempMat3D) = this.translate(x.toFloat(), y.toFloat(), z.toFloat(), w.toFloat(), temp) +fun MMatrix3D.translate(x: Double, y: Double, z: Double, w: Double = 1.0, temp: MMatrix3D = tempMat3D) = this.translate(x.toFloat(), y.toFloat(), z.toFloat(), w.toFloat(), temp) +fun MMatrix3D.translate(x: Int, y: Int, z: Int, w: Int = 1, temp: MMatrix3D = tempMat3D) = this.translate(x.toFloat(), y.toFloat(), z.toFloat(), w.toFloat(), temp) -fun Matrix3D.rotate(angle: Angle, x: Float, y: Float, z: Float, temp: Matrix3D = tempMat3D) = this.apply { +fun MMatrix3D.rotate(angle: Angle, x: Float, y: Float, z: Float, temp: MMatrix3D = tempMat3D) = this.apply { temp.setToRotation(angle, x, y, z) this.multiply(this, temp) } -fun Matrix3D.rotate(angle: Angle, x: Double, y: Double, z: Double, temp: Matrix3D = tempMat3D) = this.rotate(angle, x.toFloat(), y.toFloat(), z.toFloat(), temp) -fun Matrix3D.rotate(angle: Angle, x: Int, y: Int, z: Int, temp: Matrix3D = tempMat3D) = this.rotate(angle, x.toFloat(), y.toFloat(), z.toFloat(), temp) +fun MMatrix3D.rotate(angle: Angle, x: Double, y: Double, z: Double, temp: MMatrix3D = tempMat3D) = this.rotate(angle, x.toFloat(), y.toFloat(), z.toFloat(), temp) +fun MMatrix3D.rotate(angle: Angle, x: Int, y: Int, z: Int, temp: MMatrix3D = tempMat3D) = this.rotate(angle, x.toFloat(), y.toFloat(), z.toFloat(), temp) -fun Matrix3D.scale(x: Float, y: Float, z: Float, w: Float = 1f, temp: Matrix3D = tempMat3D) = this.apply { +fun MMatrix3D.scale(x: Float, y: Float, z: Float, w: Float = 1f, temp: MMatrix3D = tempMat3D) = this.apply { temp.setToScale(x, y, z, w) this.multiply(this, temp) } -fun Matrix3D.scale(x: Double, y: Double, z: Double, w: Double = 1.0, temp: Matrix3D = tempMat3D) = this.scale(x.toFloat(), y.toFloat(), z.toFloat(), w.toFloat(), temp) -fun Matrix3D.scale(x: Int, y: Int, z: Int, w: Int = 1, temp: Matrix3D = tempMat3D) = this.scale(x.toFloat(), y.toFloat(), z.toFloat(), w.toFloat(), temp) +fun MMatrix3D.scale(x: Double, y: Double, z: Double, w: Double = 1.0, temp: MMatrix3D = tempMat3D) = this.scale(x.toFloat(), y.toFloat(), z.toFloat(), w.toFloat(), temp) +fun MMatrix3D.scale(x: Int, y: Int, z: Int, w: Int = 1, temp: MMatrix3D = tempMat3D) = this.scale(x.toFloat(), y.toFloat(), z.toFloat(), w.toFloat(), temp) -fun Matrix3D.setToRotation(quat: Quaternion, temp: Matrix3D = tempMat3D) = this.apply { +fun MMatrix3D.setToRotation(quat: MQuaternion, temp: MMatrix3D = tempMat3D) = this.apply { quat.toMatrix(temp) this.multiply(this, temp) } -fun Matrix3D.setToRotation(euler: EulerRotation, temp: Matrix3D = tempMat3D) = this.apply { +fun MMatrix3D.setToRotation(euler: MEulerRotation, temp: MMatrix3D = tempMat3D) = this.apply { euler.toMatrix(temp) this.multiply(this, temp) } -fun Matrix3D.rotate(x: Angle, y: Angle, z: Angle, temp: Matrix3D = tempMat3D) = this.apply { +fun MMatrix3D.rotate(x: Angle, y: Angle, z: Angle, temp: MMatrix3D = tempMat3D) = this.apply { rotate(x, 1f, 0f, 0f) rotate(y, 0f, 1f, 0f) rotate(z, 0f, 0f, 1f) } -fun Matrix3D.rotate(euler: EulerRotation, temp: Matrix3D = tempMat3D) = this.apply { +fun MMatrix3D.rotate(euler: MEulerRotation, temp: MMatrix3D = tempMat3D) = this.apply { temp.setToRotation(euler) this.multiply(this, temp) } -fun Matrix3D.rotate(quat: Quaternion, temp: Matrix3D = tempMat3D) = this.apply { +fun MMatrix3D.rotate(quat: MQuaternion, temp: MMatrix3D = tempMat3D) = this.apply { temp.setToRotation(quat) this.multiply(this, temp) } -private val tempVec1 = Vector3D() -private val tempVec2 = Vector3D() -private val tempVec3 = Vector3D() +private val tempVec1 = MVector4() +private val tempVec2 = MVector4() +private val tempVec3 = MVector4() -fun Matrix3D.setToLookAt( - eye: Vector3D, - target: Vector3D, - up: Vector3D -): Matrix3D { +fun MMatrix3D.setToLookAt( + eye: MVector4, + target: MVector4, + up: MVector4 +): MMatrix3D { val z = tempVec1.sub(eye, target) if (z.length3Squared == 0f) z.z = 1f z.normalize() @@ -955,11 +966,11 @@ fun Matrix3D.setToLookAt( ) } -inline fun Matrix3D.translate(v: Vector3D, temp: Matrix3D = tempMat3D) = translate(v.x, v.y, v.z, v.w, temp) -inline fun Matrix3D.rotate(angle: Angle, v: Vector3D, temp: Matrix3D = tempMat3D) = rotate(angle, v.x, v.y, v.z, temp) -inline fun Matrix3D.scale(v: Vector3D, temp: Matrix3D = tempMat3D) = scale(v.x, v.y, v.z, v.w, temp) +inline fun MMatrix3D.translate(v: MVector4, temp: MMatrix3D = tempMat3D) = translate(v.x, v.y, v.z, v.w, temp) +inline fun MMatrix3D.rotate(angle: Angle, v: MVector4, temp: MMatrix3D = tempMat3D) = rotate(angle, v.x, v.y, v.z, temp) +inline fun MMatrix3D.scale(v: MVector4, temp: MMatrix3D = tempMat3D) = scale(v.x, v.y, v.z, v.w, temp) -fun Matrix3D.setTRS(translation: Position3D, rotation: Quaternion, scale: Scale3D): Matrix3D { +fun MMatrix3D.setTRS(translation: Position3D, rotation: MQuaternion, scale: Scale3D): MMatrix3D { val rx = rotation.x.toFloat() val ry = rotation.y.toFloat() val rz = rotation.z.toFloat() @@ -989,12 +1000,12 @@ fun Matrix3D.setTRS(translation: Position3D, rotation: Quaternion, scale: Scale3 ) } -private val tempMat1 = Matrix3D() +private val tempMat1 = MMatrix3D() -fun Matrix3D.getTRS(position: Position3D, rotation: Quaternion, scale: Scale3D): Matrix3D = this.apply { +fun MMatrix3D.getTRS(position: Position3D, rotation: MQuaternion, scale: Scale3D): MMatrix3D = this.apply { val det = determinant position.setTo(v03, v13, v23, 1f) - scale.setTo(Vector3D.length(v00, v10, v20) * det.sign, Vector3D.length(v01, v11, v21), Vector3D.length(v02, v12, v22), 1f) + scale.setTo(MVector4.length(v00, v10, v20) * det.sign, MVector4.length(v01, v11, v21), MVector4.length(v02, v12, v22), 1f) val invSX = 1f / scale.x val invSY = 1f / scale.y val invSZ = 1f / scale.z @@ -1006,7 +1017,7 @@ fun Matrix3D.getTRS(position: Position3D, rotation: Quaternion, scale: Scale3D): )) } -fun Matrix3D.invert(m: Matrix3D = this): Matrix3D { +fun MMatrix3D.invert(m: MMatrix3D = this): MMatrix3D { val target = this m.apply { val t11 = v12 * v23 * v31 - v13 * v22 * v31 + v13 * v21 * v32 - v11 * v23 * v32 - v12 * v21 * v33 + v11 * v22 * v33 @@ -1047,16 +1058,26 @@ fun Matrix3D.invert(m: Matrix3D = this): Matrix3D { } } -inline fun Matrix3D.setToMap(filter: (Float) -> Float) = setRows( +inline fun MMatrix3D.setToMap(filter: (Float) -> Float) = setRows( filter(v00), filter(v01), filter(v02), filter(v03), filter(v10), filter(v11), filter(v12), filter(v13), filter(v20), filter(v21), filter(v22), filter(v23), filter(v30), filter(v31), filter(v32), filter(v33) ) -fun Matrix3D.setToInterpolated(a: Matrix3D, b: Matrix3D, ratio: Double) = setColumns( +fun MMatrix3D.setToInterpolated(a: MMatrix3D, b: MMatrix3D, ratio: Double) = setColumns( ratio.interpolate(a.v00, b.v00), ratio.interpolate(a.v10, b.v10), ratio.interpolate(a.v20, b.v20), ratio.interpolate(a.v30, b.v30), ratio.interpolate(a.v01, b.v01), ratio.interpolate(a.v11, b.v11), ratio.interpolate(a.v21, b.v21), ratio.interpolate(a.v31, b.v31), ratio.interpolate(a.v02, b.v02), ratio.interpolate(a.v12, b.v12), ratio.interpolate(a.v22, b.v22), ratio.interpolate(a.v32, b.v32), ratio.interpolate(a.v03, b.v03), ratio.interpolate(a.v13, b.v13), ratio.interpolate(a.v23, b.v23), ratio.interpolate(a.v33, b.v33) ) + +fun MMatrix3D.copyFrom(that: MMatrix): MMatrix3D = that.toMatrix3D(this) + +fun MMatrix.toMatrix3D(out: MMatrix3D = MMatrix3D()): MMatrix3D = out.setRows( + a, c, 0.0, tx, + b, d, 0.0, ty, + 0.0, 0.0, 1.0, 0.0, + 0.0, 0.0, 0.0, 1.0 +) + diff --git a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/MatrixExt.kt b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/MatrixExt.kt deleted file mode 100644 index 1193274424..0000000000 --- a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/MatrixExt.kt +++ /dev/null @@ -1,23 +0,0 @@ -package com.soywiz.korma.geom - -import kotlin.jvm.JvmName - -fun Matrix3D.copyFrom(that: Matrix): Matrix3D = that.toMatrix3D(this) - -fun Matrix.toMatrix3D(out: Matrix3D = Matrix3D()): Matrix3D = out.setRows( - a, c, 0.0, tx, - b, d, 0.0, ty, - 0.0, 0.0, 1.0, 0.0, - 0.0, 0.0, 0.0, 1.0 -) - -@JvmName("multiplyNullable") -fun Matrix.multiply(l: Matrix?, r: Matrix?): Matrix { - when { - l != null && r != null -> multiply(l, r) - l != null -> copyFrom(l) - r != null -> copyFrom(r) - else -> identity() - } - return this -} diff --git a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Point.kt b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Point.kt index 42685781b7..55d39db146 100644 --- a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Point.kt +++ b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Point.kt @@ -11,121 +11,232 @@ import com.soywiz.kmem.clamp import com.soywiz.korma.math.isAlmostEquals import com.soywiz.korma.math.isAlmostZero import com.soywiz.korma.math.roundDecimalPlaces -import kotlin.math.absoluteValue -import kotlin.math.acos -import kotlin.math.ceil -import kotlin.math.floor -import kotlin.math.hypot -import kotlin.math.round +import kotlin.math.* +typealias Vector2D = Point +typealias IVector2D = IPoint +typealias MVector2D = MPoint + +////////////////////////////// +// VALUE CLASSES +////////////////////////////// + +fun test() { + val p = (Point(1, 2) + Point(3, 4)) * 2 +} + +data class Point(val x: Double, val y: Double) { + constructor(x: Int, y: Int) : this(x.toDouble(), y.toDouble()) + constructor(x: Float, y: Float) : this(x.toDouble(), y.toDouble()) + + operator fun plus(that: Point): Point = Point(x + that.x, y + that.y) + operator fun minus(that: Point): Point = Point(x - that.x, y - that.y) + operator fun times(that: Point): Point = Point(x * that.x, y * that.y) + operator fun div(that: Point): Point = Point(x / that.x, y / that.y) + + operator fun times(scale: Double): Point = Point(x * scale, y * scale) + operator fun times(scale: Float): Point = this * scale.toDouble() + operator fun times(scale: Int): Point = this * scale.toDouble() + + operator fun div(scale: Double): Point = Point(x / scale, y / scale) + operator fun div(scale: Float): Point = this / scale.toDouble() + operator fun div(scale: Int): Point = this / scale.toDouble() + + fun distanceTo(x: Double, y: Double): Double = hypot(x - this.x, y - this.y) + fun distanceTo(x: Float, y: Float): Double = this.distanceTo(x.toDouble(), y.toDouble()) + fun distanceTo(x: Int, y: Int): Double = this.distanceTo(x.toDouble(), y.toDouble()) + fun distanceTo(that: Point): Double = distanceTo(that.x, that.y) + + infix fun dot(that: Point): Double = this.x * that.x + this.y * that.y + + fun angleTo(other: Point): Angle = Angle.between(this.x, this.y, other.x, other.y) + val angle: Angle get() = Angle.between(0.0, 0.0, this.x, this.y) + + fun transformed(m: MMatrix): Point = Point(m.transformX(x, y), m.transformY(x, y)) + fun transformX(m: MMatrix?): Double = m?.transformX(x, y) ?: x + fun transformY(m: MMatrix?): Double = m?.transformY(x, y) ?: y + operator fun get(component: Int) = when (component) { + 0 -> x; 1 -> y + else -> throw IndexOutOfBoundsException("Point doesn't have $component component") + } + val length: Double get() = hypot(x, y) + val magnitude: Double get() = hypot(x, y) + val normalized: Point get() = this * (1.0 / magnitude) + + val int: PointInt get() = PointInt(x.toInt(), y.toInt()) + val intRound: PointInt get() = PointInt(x.roundToInt(), y.roundToInt()) + + fun roundDecimalPlaces(places: Int): Point = Point(x.roundDecimalPlaces(places), y.roundDecimalPlaces(places)) + fun round(): Point = Point(kotlin.math.round(x), kotlin.math.round(y)) + fun ceil(): Point = Point(kotlin.math.ceil(x), kotlin.math.ceil(y)) + fun floor(): Point = Point(kotlin.math.floor(x), kotlin.math.floor(y)) + + fun mutable(out: MPoint = MPoint()): MPoint = out.setTo(x, y) + val mutable: MPoint get() = mutable() + + //fun copy(x: Double = this.x, y: Double = this.y): Point = Point(x, y) + + fun isAlmostEquals(other: Point, epsilon: Double = 0.000001): Boolean = + this.x.isAlmostEquals(other.x, epsilon) && this.y.isAlmostEquals(other.y, epsilon) + + companion object { + /** Constructs a point from polar coordinates determined by an [angle] and a [length]. Angle 0 is pointing to the right, and the direction is counter-clock-wise */ + fun fromPolar(x: Double, y: Double, angle: Angle, length: Double = 1.0): Point = Point(x + angle.cosine * length, y + angle.sine * length) + fun fromPolar(base: Point, angle: Angle, length: Double = 1.0): Point = fromPolar(base.x, base.y, angle, length) + fun fromPolar(angle: Angle, length: Double = 1.0): Point = fromPolar(0.0, 0.0, angle, length) + + fun middle(a: Point, b: Point): Point = (a + b) * 0.5 + + fun angle(ax: Double, ay: Double, bx: Double, by: Double): Angle = Angle.between(ax, ay, bx, by) + fun angle(x1: Double, y1: Double, x2: Double, y2: Double, x3: Double, y3: Double): Angle = Angle.between(x1 - x2, y1 - y2, x1 - x3, y1 - y3) + //acos(((ax * bx) + (ay * by)) / (hypot(ax, ay) * hypot(bx, by))) + fun angleArc(a: Point, b: Point): Angle = Angle.fromRadians(acos(a dot b) / (a.length * b.length)) + fun angleFull(a: Point, b: Point): Angle = Angle.between(a, b) + + fun distance(a: Double, b: Double): Double = kotlin.math.abs(a - b) + fun distance(x1: Double, y1: Double, x2: Double, y2: Double): Double = kotlin.math.hypot(x1 - x2, y1 - y2) + fun distance(x1: Float, y1: Float, x2: Float, y2: Float): Double = distance(x1.toDouble(), y1.toDouble(), x2.toDouble(), y2.toDouble()) + fun distance(x1: Int, y1: Int, x2: Int, y2: Int): Double = distance(x1.toDouble(), y1.toDouble(), x2.toDouble(), y2.toDouble()) + fun distance(a: Point, b: Point): Double = distance(a.x, a.y, b.x, b.y) + fun distance(a: PointInt, b: PointInt): Double = distance(a.x, a.y, b.x, b.y) + fun distanceSquared(a: Point, b: Point): Double = distanceSquared(a.x, a.y, b.x, b.y) + fun distanceSquared(a: PointInt, b: PointInt): Int = distanceSquared(a.x, a.y, b.x, b.y) + fun distanceSquared(x1: Double, y1: Double, x2: Double, y2: Double): Double = square(x1 - x2) + square(y1 - y2) + fun distanceSquared(x1: Int, y1: Int, x2: Int, y2: Int): Int = square(x1 - x2) + square(y1 - y2) + + fun direction(a: Point, b: Point): Point = b - a + + fun compare(l: Point, r: Point): Int = compare(l.x, l.y, r.x, r.y) + fun compare(lx: Double, ly: Double, rx: Double, ry: Double): Int = ly.compareTo(ry).let { ret -> if (ret == 0) lx.compareTo(rx) else ret } + + private fun square(x: Double) = x * x + private fun square(x: Int) = x * x + + fun dot(aX: Double, aY: Double, bX: Double, bY: Double): Double = (aX * bX) + (aY * bY) + fun dot(a: Point, b: Point): Double = dot(a.x, a.y, b.x, b.y) + + fun isCollinear(xa: Double, ya: Double, x: Double, y: Double, xb: Double, yb: Double): Boolean = + (((x - xa) / (y - ya)) - ((xa - xb) / (ya - yb))).absoluteValue.isAlmostZero() + + fun isCollinear(xa: Int, ya: Int, x: Int, y: Int, xb: Int, yb: Int): Boolean = isCollinear( + xa.toDouble(), ya.toDouble(), + x.toDouble(), y.toDouble(), + xb.toDouble(), yb.toDouble(), + ) + + // https://algorithmtutor.com/Computational-Geometry/Determining-if-two-consecutive-segments-turn-left-or-right/ + /** < 0 left, > 0 right, 0 collinear */ + fun orientation(p1: Point, p2: Point, p3: Point): Double = + orientation(p1.x, p1.y, p2.x, p2.y, p3.x, p3.y) + fun orientation(ax: Double, ay: Double, bx: Double, by: Double, cx: Double, cy: Double): Double = + crossProduct(cx - ax, cy - ay, bx - ax, by - ay) + + fun crossProduct(ax: Double, ay: Double, bx: Double, by: Double): Double = (ax * by) - (bx * ay) + fun crossProduct(p1: Point, p2: Point): Double = crossProduct(p1.x, p1.y, p2.x, p2.y) + } +} + +data class PointInt(val x: Int, val y: Int) { + operator fun plus(that: PointInt): PointInt = PointInt(this.x + that.x, this.y + that.y) + operator fun minus(that: PointInt): PointInt = PointInt(this.x - that.x, this.y - that.y) + operator fun times(that: PointInt): PointInt = PointInt(this.x * that.x, this.y * that.y) + operator fun div(that: PointInt): PointInt = PointInt(this.x / that.x, this.y / that.y) + operator fun rem(that: PointInt): PointInt = PointInt(this.x % that.x, this.y % that.y) +} + +////////////////////////////// +// IMMUTABLE INTERFACES +////////////////////////////// + +@Deprecated("Use Point instead") interface IPoint { + companion object { + val ZERO: IPoint = MPoint(0, 0) + + operator fun invoke(): IPoint = MPoint(0.0, 0.0) + operator fun invoke(v: IPoint): IPoint = MPoint(v.x, v.y) + operator fun invoke(x: Double, y: Double): IPoint = MPoint(x, y) + operator fun invoke(x: Float, y: Float): IPoint = MPoint(x, y) + operator fun invoke(x: Int, y: Int): IPoint = MPoint(x, y) + } + val x: Double val y: Double - companion object { - val ZERO: IPoint = Point(0, 0) + val point: Point get() = Point(x, y) + + val niceStr: String get() = "(${x.niceStr}, ${y.niceStr})" + fun niceStr(decimalPlaces: Int): String = "(${x.niceStr(decimalPlaces)}, ${y.niceStr(decimalPlaces)})" + + operator fun plus(that: IPoint): IPoint = IPoint(x + that.x, y + that.y) + operator fun minus(that: IPoint): IPoint = IPoint(x - that.x, y - that.y) + operator fun times(that: IPoint): IPoint = IPoint(x * that.x, y * that.y) + operator fun div(that: IPoint): IPoint = IPoint(x / that.x, y / that.y) + + operator fun times(scale: Double): IPoint = IPoint(x * scale, y * scale) + operator fun times(scale: Float): IPoint = this * scale.toDouble() + operator fun times(scale: Int): IPoint = this * scale.toDouble() + + operator fun div(scale: Double): IPoint = IPoint(x / scale, y / scale) + operator fun div(scale: Float): IPoint = this / scale.toDouble() + operator fun div(scale: Int): IPoint = this / scale.toDouble() - operator fun invoke(): IPoint = Point(0.0, 0.0) - operator fun invoke(v: IPoint): IPoint = Point(v.x, v.y) - operator fun invoke(x: Double, y: Double): IPoint = Point(x, y) - operator fun invoke(x: Float, y: Float): IPoint = Point(x, y) - operator fun invoke(x: Int, y: Int): IPoint = Point(x, y) + fun distanceTo(x: Double, y: Double): Double = hypot(x - this.x, y - this.y) + fun distanceTo(x: Float, y: Float): Float = this.distanceTo(x.toDouble(), y.toDouble()).toFloat() + fun distanceTo(x: Int, y: Int): Double = this.distanceTo(x.toDouble(), y.toDouble()) + + fun distanceTo(that: IPoint): Double = distanceTo(that.x, that.y) + + infix fun dot(that: IPoint): Double = this.x * that.x + this.y * that.y + fun angleTo(other: IPoint): Angle = Angle.between(this.x, this.y, other.x, other.y) + val angle: Angle get() = Angle.between(0.0, 0.0, this.x, this.y) + fun transformed(mat: MMatrix, out: MPoint = MPoint()): MPoint = out.setToTransform(mat, this) + fun transformX(m: MMatrix?): Double = m?.transformX(this) ?: x + fun transformY(m: MMatrix?): Double = m?.transformY(this) ?: y + operator fun IPoint.get(component: Int) = when (component) { + 0 -> x; 1 -> y + else -> throw IndexOutOfBoundsException("IPoint doesn't have $component component") } + val unit: IPoint get() = this / this.length + val length: Double get() = hypot(x, y) + val magnitude: Double get() = hypot(x, y) + val normalized: IPoint + get() { + val imag = 1.0 / magnitude + return IPoint(x * imag, y * imag) + } + val mutable: MPoint get() = MPoint(x, y) + val immutable: IPoint get() = IPoint(x, y) + fun isAlmostEquals(other: IPoint, epsilon: Double = 0.000001): Boolean = + this.x.isAlmostEquals(other.x, epsilon) && this.y.isAlmostEquals(other.y, epsilon) + } -val IPoint.niceStr: String get() = "(${x.niceStr}, ${y.niceStr})" -fun IPoint.niceStr(decimalPlaces: Int): String = "(${x.niceStr(decimalPlaces)}, ${y.niceStr(decimalPlaces)})" +fun IPoint.copy(x: Double = this.x, y: Double = this.y): IPoint = IPoint(x, y) -interface XY : IPoint { +@Deprecated("Use Point instead") +interface IMPoint : IPoint { override var x: Double override var y: Double } -interface XYf { - var xf: Float - var yf: Float -} +////////////////////////////// +// MUTABLE IMPLEMENTATIONS +////////////////////////////// -fun Point.Companion.middle(a: IPoint, b: IPoint): Point = Point((a.x + b.x) * 0.5, (a.y + b.y) * 0.5) -fun Point.Companion.angle(a: IPoint, b: IPoint): Angle = Angle.fromRadians(acos((a.dot(b)) / (a.length * b.length))) -fun Point.Companion.compare(l: IPoint, r: IPoint): Int = Point.compare(l.x, l.y, r.x, r.y) -fun Point.Companion.distance(a: IPoint, b: IPoint): Double = Point.distance(a.x, a.y, b.x, b.y) -fun Point.copyFrom(that: IPoint) = setTo(that.x, that.y) -fun Point.add(p: IPoint) = this.setToAdd(this, p) -fun Point.sub(p: IPoint) = this.setToSub(this, p) - -operator fun IPoint.plus(that: IPoint): IPoint = IPoint(x + that.x, y + that.y) -operator fun IPoint.minus(that: IPoint): IPoint = IPoint(x - that.x, y - that.y) -operator fun IPoint.times(that: IPoint): IPoint = IPoint(x * that.x, y * that.y) -operator fun IPoint.div(that: IPoint): IPoint = IPoint(x / that.x, y / that.y) - -operator fun IPoint.times(scale: Double): IPoint = IPoint(x * scale, y * scale) -operator fun IPoint.div(scale: Double): IPoint = IPoint(x / scale, y / scale) -fun IPoint.distanceTo(x: Double, y: Double): Double = hypot(x - this.x, y - this.y) - -operator fun IPoint.times(scale: Int): IPoint = this * scale.toDouble() -operator fun IPoint.div(scale: Int): IPoint = this / scale.toDouble() -fun IPoint.distanceTo(x: Int, y: Int): Double = this.distanceTo(x.toDouble(), y.toDouble()) - -operator fun IPoint.times(scale: Float): IPoint = this * scale.toDouble() -operator fun IPoint.div(scale: Float): IPoint = this / scale.toDouble() -fun IPoint.distanceTo(x: Float, y: Float): Double = this.distanceTo(x.toDouble(), y.toDouble()) - -infix fun IPoint.dot(that: IPoint): Double = this.x * that.x + this.y * that.y -fun IPoint.distanceTo(that: IPoint): Double = distanceTo(that.x, that.y) -fun IPoint.angleTo(other: IPoint): Angle = Angle.between(this.x, this.y, other.x, other.y) -val IPoint.angle: Angle get() = Angle.between(0.0, 0.0, this.x, this.y) -fun IPoint.transformed(mat: Matrix, out: Point = Point()): Point = out.setToTransform(mat, this) -fun IPoint.transformX(m: Matrix?): Double = m?.transformX(this) ?: x -fun IPoint.transformY(m: Matrix?): Double = m?.transformY(this) ?: y -operator fun IPoint.get(component: Int) = when (component) { - 0 -> x; 1 -> y - else -> throw IndexOutOfBoundsException("IPoint doesn't have $component component") -} -val IPoint.unit: IPoint get() = this / this.length -val IPoint.length: Double get() = hypot(x, y) -val IPoint.magnitude: Double get() = hypot(x, y) -val IPoint.normalized: IPoint - get() { - val imag = 1.0 / magnitude - return IPoint(x * imag, y * imag) - } -val IPoint.mutable: Point get() = Point(x, y) -val IPoint.immutable: IPoint get() = IPoint(x, y) -fun IPoint.copy(x: Double = this.x, y: Double = this.y): IPoint = IPoint(x, y) -fun IPoint.isAlmostEquals(other: IPoint, epsilon: Double = 0.000001): Boolean = - this.x.isAlmostEquals(other.x, epsilon) && this.y.isAlmostEquals(other.y, epsilon) - -fun Point.setToTransform(mat: Matrix, p: IPoint): Point = setToTransform(mat, p.x, p.y) -fun Point.setToTransform(mat: Matrix, x: Double, y: Double): Point = setTo(mat.transformX(x, y), mat.transformY(x, y)) -fun Point.setToAdd(a: IPoint, b: IPoint): Point = setTo(a.x + b.x, a.y + b.y) -fun Point.setToSub(a: IPoint, b: IPoint): Point = setTo(a.x - b.x, a.y - b.y) -fun Point.setToMul(a: IPoint, b: IPoint): Point = setTo(a.x * b.x, a.y * b.y) -fun Point.setToMul(a: IPoint, s: Double): Point = setTo(a.x * s, a.y * s) -inline fun Point.setToMul(a: IPoint, s: Number): Point = setToMul(a, s.toDouble()) -fun Point.setToDiv(a: IPoint, b: IPoint): Point = setTo(a.x / b.x, a.y / b.y) -fun Point.setToDiv(a: IPoint, s: Double): Point = setTo(a.x / s, a.y / s) -inline fun Point.setToDiv(a: IPoint, s: Number): Point = setToDiv(a, s.toDouble()) -operator fun Point.plusAssign(that: IPoint) { setTo(this.x + that.x, this.y + that.y) } - -data class Point( +@Deprecated("Use Point instead") +data class MPoint( override var x: Double, override var y: Double //override var xf: Float, //override var yf: Float -) : MutableInterpolable, Interpolable, Comparable, IPoint, XY, XYf { +) : MutableInterpolable, Interpolable, Comparable, IPoint, IMPoint { //constructor(x: Double, y: Double) : this(x.toFloat(), y.toFloat()) constructor(x: Float, y: Float) : this(x.toDouble(), y.toDouble()) constructor(x: Int, y: Int) : this(x.toDouble(), y.toDouble()) - //override var x: Double get() = xf.toDouble() ; set(value) { xf = value.toFloat() } - //override var y: Double get() = yf.toDouble() ; set(value) { yf = value.toFloat() } - - override var xf: Float get() = x.toFloat() ; set(value) { x = value.toDouble() } - override var yf: Float get() = y.toFloat() ; set(value) { y = value.toDouble() } - override fun compareTo(other: IPoint): Int = compare(this.x, this.y, other.x, other.y) - fun compareTo(other: Point): Int = compare(this.x, this.y, other.x, other.y) + fun compareTo(other: MPoint): Int = compare(this.x, this.y, other.x, other.y) fun clear() = setToZero() fun setToZero() = setTo(0.0, 0.0) @@ -135,8 +246,142 @@ data class Point( fun setToLeft() = setTo(-1.0, 0.0) fun setToRight() = setTo(+1.0, 0.0) + fun MPoint.copyFrom(that: IPoint) = setTo(that.x, that.y) + fun MPoint.add(p: IPoint) = this.setToAdd(this, p) + fun MPoint.sub(p: IPoint) = this.setToSub(this, p) + fun MPoint.setToTransform(mat: MMatrix, p: IPoint): MPoint = setToTransform(mat, p.x, p.y) + fun MPoint.setToTransform(mat: MMatrix, x: Double, y: Double): MPoint = setTo(mat.transformX(x, y), mat.transformY(x, y)) + fun MPoint.setToAdd(a: IPoint, b: IPoint): MPoint = setTo(a.x + b.x, a.y + b.y) + fun MPoint.setToSub(a: IPoint, b: IPoint): MPoint = setTo(a.x - b.x, a.y - b.y) + fun MPoint.setToMul(a: IPoint, b: IPoint): MPoint = setTo(a.x * b.x, a.y * b.y) + fun MPoint.setToMul(a: IPoint, s: Double): MPoint = setTo(a.x * s, a.y * s) + inline fun MPoint.setToMul(a: IPoint, s: Number): MPoint = setToMul(a, s.toDouble()) + fun MPoint.setToDiv(a: IPoint, b: IPoint): MPoint = setTo(a.x / b.x, a.y / b.y) + fun MPoint.setToDiv(a: IPoint, s: Double): MPoint = setTo(a.x / s, a.y / s) + inline fun MPoint.setToDiv(a: IPoint, s: Number): MPoint = setToDiv(a, s.toDouble()) + operator fun MPoint.plusAssign(that: IPoint) { setTo(this.x + that.x, this.y + that.y) } + + + fun floor() = setTo(floor(x), floor(y)) + fun round() = setTo(round(x), round(y)) + fun ceil() = setTo(ceil(x), ceil(y)) + + fun setToRoundDecimalPlaces(places: Int) = setTo(x.roundDecimalPlaces(places), y.roundDecimalPlaces(places)) + fun setTo(x: Int, y: Int): MPoint = setTo(x.toDouble(), y.toDouble()) + + fun setTo(x: Double, y: Double): MPoint { + this.x = x + this.y = y + return this + } + + fun setTo(x: Float, y: Float): MPoint { + this.x = x.toDouble() + this.y = y.toDouble() + return this + } + + /** Updates a point from polar coordinates determined by an [angle] and a [length]. Angle 0 is pointing to the right, and the direction is counter-clock-wise */ + fun setToPolar(angle: Angle, length: Double = 1.0): MPoint = setToPolar(0.0, 0.0, angle, length) + fun setToPolar(base: Point, angle: Angle, length: Double = 1.0): MPoint = setToPolar(base.x, base.y, angle, length) + fun setToPolar(base: IPoint, angle: Angle, length: Double = 1.0): MPoint = setToPolar(base.x, base.y, angle, length) + fun setToPolar(x: Double, y: Double, angle: Angle, length: Double = 1.0): MPoint = setTo(x + angle.cosine * length, y + angle.sine * length) + + /** Rotates the vector/point -90 degrees (not normalizing it) */ + fun setToNormal(): MPoint = setTo(-this.y, this.x) + fun neg() = setTo(-this.x, -this.y) + fun mul(s: Double) = setTo(this.x * s, this.y * s) + fun mul(s: Float) = mul(s.toDouble()) + fun mul(s: Int) = mul(s.toDouble()) + + fun add(p: MPoint) = this.setToAdd(this, p) + fun sub(p: MPoint) = this.setToSub(this, p) + + fun add(x: Double, y: Double) = this.setTo(this.x + x, this.y + y) + fun sub(x: Double, y: Double) = this.setTo(this.x - x, this.y - y) + + fun copyFrom(that: IPoint) = setTo(that.x, that.y) + + fun setToTransform(mat: MMatrix, p: IPoint): MPoint = setToTransform(mat, p.x, p.y) + fun setToTransform(mat: MMatrix, x: Double, y: Double): MPoint = setTo(mat.transformX(x, y), mat.transformY(x, y)) + + fun setToAdd(a: IPoint, b: IPoint): MPoint = setTo(a.x + b.x, a.y + b.y) + fun setToSub(a: IPoint, b: IPoint): MPoint = setTo(a.x - b.x, a.y - b.y) + fun setToMul(a: IPoint, b: IPoint): MPoint = setTo(a.x * b.x, a.y * b.y) + fun setToMul(a: IPoint, s: Double): MPoint = setTo(a.x * s, a.y * s) + fun setToMul(a: IPoint, s: Float): MPoint = setToMul(a, s.toDouble()) + fun setToDiv(a: IPoint, b: IPoint): MPoint = setTo(a.x / b.x, a.y / b.y) + fun setToDiv(a: IPoint, s: Double): MPoint = setTo(a.x / s, a.y / s) + fun setToDiv(a: IPoint, s: Float): MPoint = setToDiv(a, s.toDouble()) + operator fun plusAssign(that: IPoint) { setTo(this.x + that.x, this.y + that.y) } + + override operator fun plus(that: IPoint): MPoint = MPoint(this.x + that.x, this.y + that.y) + override operator fun minus(that: IPoint): MPoint = MPoint(this.x - that.x, this.y - that.y) + override operator fun times(that: IPoint): MPoint = MPoint(this.x * that.x, this.y * that.y) + override operator fun div(that: IPoint): MPoint = MPoint(this.x / that.x, this.y / that.y) + override infix fun dot(that: IPoint): Double = this.x * that.x + this.y * that.y + + override operator fun times(scale: Double): MPoint = MPoint(this.x * scale, this.y * scale) + override operator fun times(scale: Float): MPoint = this * scale.toDouble() + override operator fun times(scale: Int): MPoint = this * scale.toDouble() + + override operator fun div(scale: Double): MPoint = MPoint(this.x / scale, this.y / scale) + override operator fun div(scale: Float): MPoint = this / scale.toDouble() + override operator fun div(scale: Int): MPoint = this / scale.toDouble() + + override fun distanceTo(x: Double, y: Double): Double = hypot(x - this.x, y - this.y) + override fun distanceTo(x: Int, y: Int): Double = distanceTo(x.toDouble(), y.toDouble()) + override fun distanceTo(x: Float, y: Float): Float = distanceTo(x.toDouble(), y.toDouble()).toFloat() + + fun distanceTo(that: MPoint): Double = distanceTo(that.x, that.y) + fun angleTo(other: MPoint): Angle = Angle.between(this.x, this.y, other.x, other.y) + override fun transformed(mat: MMatrix, out: MPoint): MPoint = out.setToTransform(mat, this) + operator fun get(index: Int) = when (index) { + 0 -> this.x; 1 -> this.y + else -> throw IndexOutOfBoundsException("IPoint doesn't have $index component") + } + override val mutable: MPoint get() = MPoint(this.x, this.y) + override val immutable: MPoint get() = MPoint(this.x, this.y) + fun copy() = MPoint(this.x, this.y) + + override val unit: IPoint get() = this / length + val squaredLength: Double get() = (x * x) + (y * y) + override val length: Double get() = hypot(this.x, this.y) + override val magnitude: Double get() = hypot(this.x, this.y) + override val normalized: MPoint + get() { + val imag = 1.0 / magnitude + return MPoint(this.x * imag, this.y * imag) + } + + fun normalize() { + val len = this.length + when { + len.isAlmostZero() -> this.setTo(0, 0) + else -> this.setTo(this.x / len, this.y / len) + } + } + + override fun interpolateWith(ratio: Double, other: MPoint): MPoint = + MPoint().setToInterpolated(ratio, this, other) + + override fun setToInterpolated(ratio: Double, l: MPoint, r: MPoint): MPoint = setToInterpolated(ratio, l.x, l.y, r.x, r.y) + fun setToInterpolated(ratio: Double, l: IPoint, r: IPoint): MPoint = setToInterpolated(ratio, l.x, l.y, r.x, r.y) + + fun setToInterpolated(ratio: Double, lx: Double, ly: Double, rx: Double, ry: Double): MPoint = + this.setTo(ratio.interpolate(lx, rx), ratio.interpolate(ly, ry)) + + override fun toString(): String = "(${this.x.niceStr}, ${this.y.niceStr})" + + fun rotate(rotation: Angle, out: MPoint = MPoint()): MPoint = + out.setToPolar(Angle.between(0.0, 0.0, this.x, this.y) + rotation, this.length) + + + @Deprecated("Use non Number version") + inline fun setTo(x: Number, y: Number): MPoint = setTo(x.toDouble(), y.toDouble()) + companion object { - val POOL: ConcurrentPool = ConcurrentPool({ it.setTo(0.0, 0.0) }) { Point() } + val POOL: ConcurrentPool = ConcurrentPool({ it.setTo(0.0, 0.0) }) { MPoint() } val Zero: IPoint = IPoint(0.0, 0.0) val One: IPoint = IPoint(1.0, 1.0) @@ -146,28 +391,32 @@ data class Point( val Right: IPoint = IPoint(+1.0, 0.0) //inline operator fun invoke(): Point = Point(0.0, 0.0) // @TODO: // e: java.lang.NullPointerException at org.jetbrains.kotlin.com.google.gwt.dev.js.JsAstMapper.mapFunction(JsAstMapper.java:562) (val pt = Array(1) { Point() }) - operator fun invoke(): Point = Point(0.0, 0.0) - operator fun invoke(v: Point): Point = Point(v.x, v.y) - operator fun invoke(v: IPoint): Point = Point(v.x, v.y) - operator fun invoke(xy: Int): Point = Point(xy.toDouble(), xy.toDouble()) - operator fun invoke(xy: Float): Point = Point(xy.toDouble(), xy.toDouble()) - operator fun invoke(xy: Double): Point = Point(xy, xy) + operator fun invoke(): MPoint = MPoint(0.0, 0.0) + operator fun invoke(v: MPoint): MPoint = MPoint(v.x, v.y) + operator fun invoke(v: IPoint): MPoint = MPoint(v.x, v.y) + operator fun invoke(xy: Int): MPoint = MPoint(xy.toDouble(), xy.toDouble()) + operator fun invoke(xy: Float): MPoint = MPoint(xy.toDouble(), xy.toDouble()) + operator fun invoke(xy: Double): MPoint = MPoint(xy, xy) /** Constructs a point from polar coordinates determined by an [angle] and a [length]. Angle 0 is pointing to the right, and the direction is counter-clock-wise */ - inline operator fun invoke(angle: Angle, length: Double = 1.0): Point = fromPolar(angle, length) + inline operator fun invoke(angle: Angle, length: Double = 1.0): MPoint = fromPolar(angle, length) - /** Constructs a point from polar coordinates determined by an [angle] and a [length]. Angle 0 is pointing to the right, and the direction is counter-clock-wise */ - fun fromPolar(x: Double, y: Double, angle: Angle, length: Double = 1.0, out: Point = Point()): Point = out.setTo(x + angle.cosine * length, y + angle.sine * length) - fun fromPolar(angle: Angle, length: Double = 1.0, out: Point = Point()): Point = fromPolar(0.0, 0.0, angle, length, out) - fun fromPolar(base: IPoint, angle: Angle, length: Double = 1.0, out: Point = Point()): Point = fromPolar(base.x, base.y, angle, length, out) - - fun direction(a: IPoint, b: IPoint, out: Point = Point()): Point = out.setTo(b.x - a.x, b.y - b.y) - fun middle(a: IPoint, b: IPoint, out: Point = Point()): Point = out.setTo((a.x + b.x) * 0.5, (a.y + b.y) * 0.5) - fun angleArc(a: IPoint, b: IPoint): Angle = Angle.fromRadians(acos((a.dot(b)) / (a.length * b.length))) @Deprecated("") fun angle(a: IPoint, b: IPoint): Angle = angleArc(a, b) + fun angleArc(a: IPoint, b: IPoint): Angle = Angle.fromRadians(acos((a.dot(b)) / (a.length * b.length))) fun angleFull(a: IPoint, b: IPoint): Angle = Angle.between(a, b) + fun middle(a: IPoint, b: IPoint): MPoint = MPoint((a.x + b.x) * 0.5, (a.y + b.y) * 0.5) + fun compare(l: IPoint, r: IPoint): Int = MPoint.compare(l.x, l.y, r.x, r.y) + + /** Constructs a point from polar coordinates determined by an [angle] and a [length]. Angle 0 is pointing to the right, and the direction is counter-clock-wise */ + fun fromPolar(x: Double, y: Double, angle: Angle, length: Double = 1.0, out: MPoint = MPoint()): MPoint = out.setTo(x + angle.cosine * length, y + angle.sine * length) + fun fromPolar(angle: Angle, length: Double = 1.0, out: MPoint = MPoint()): MPoint = fromPolar(0.0, 0.0, angle, length, out) + fun fromPolar(base: IPoint, angle: Angle, length: Double = 1.0, out: MPoint = MPoint()): MPoint = fromPolar(base.x, base.y, angle, length, out) + + fun direction(a: IPoint, b: IPoint, out: MPoint = MPoint()): MPoint = out.setTo(b.x - a.x, b.y - a.y) + fun middle(a: IPoint, b: IPoint, out: MPoint = MPoint()): MPoint = out.setTo((a.x + b.x) * 0.5, (a.y + b.y) * 0.5) + fun angle(ax: Double, ay: Double, bx: Double, by: Double): Angle = Angle.between(ax, ay, bx, by) //acos(((ax * bx) + (ay * by)) / (hypot(ax, ay) * hypot(bx, by))) @@ -176,7 +425,7 @@ data class Point( return if (ret == 0) lx.compareTo(rx) else ret } - fun compare(l: Point, r: Point): Int = compare(l.x, l.y, r.x, r.y) + fun compare(l: MPoint, r: MPoint): Int = compare(l.x, l.y, r.x, r.y) fun angle(x1: Double, y1: Double, x2: Double, y2: Double, x3: Double, y3: Double): Angle = Angle.between(x1 - x2, y1 - y2, x1 - x3, y1 - y3) @@ -186,14 +435,13 @@ data class Point( fun distanceSquared(x1: Double, y1: Double, x2: Double, y2: Double): Double = square(x1 - x2) + square(y1 - y2) fun distanceSquared(x1: Int, y1: Int, x2: Int, y2: Int): Int = square(x1 - x2) + square(y1 - y2) + fun distance(a: IPoint, b: IPoint): Double = distance(a.x, a.y, b.x, b.y) + fun distance(a: IPointInt, b: IPointInt): Double = distance(a.x, a.y, b.x, b.y) fun distance(a: Double, b: Double): Double = kotlin.math.abs(a - b) fun distance(x1: Double, y1: Double, x2: Double, y2: Double): Double = kotlin.math.hypot(x1 - x2, y1 - y2) fun distance(x1: Float, y1: Float, x2: Float, y2: Float): Double = distance(x1.toDouble(), y1.toDouble(), x2.toDouble(), y2.toDouble()) fun distance(x1: Int, y1: Int, x2: Int, y2: Int): Double = distance(x1.toDouble(), y1.toDouble(), x2.toDouble(), y2.toDouble()) - fun distance(a: IPoint, b: IPoint): Double = distance(a.x, a.y, b.x, b.y) - fun distance(a: IPointInt, b: IPointInt): Double = distance(a.x, a.y, b.x, b.y) - fun distanceSquared(a: IPoint, b: IPoint): Double = distanceSquared(a.x, a.y, b.x, b.y) fun distanceSquared(a: IPointInt, b: IPointInt): Int = distanceSquared(a.x, a.y, b.x, b.y) @@ -227,203 +475,76 @@ data class Point( //val bl = hypot(bx, by) //return acos((ax * bx + ay * by) / (al * bl)) } - - fun floor() = setTo(floor(x), floor(y)) - fun round() = setTo(round(x), round(y)) - fun ceil() = setTo(ceil(x), ceil(y)) - - fun setToRoundDecimalPlaces(places: Int) = setTo(x.roundDecimalPlaces(places), y.roundDecimalPlaces(places)) - fun setTo(x: Int, y: Int): Point = setTo(x.toDouble(), y.toDouble()) - - fun setTo(x: Double, y: Double): Point { - this.x = x - this.y = y - return this - } - - fun setTo(x: Float, y: Float): Point { - this.xf = x - this.yf = y - return this - } - - /** Updates a point from polar coordinates determined by an [angle] and a [length]. Angle 0 is pointing to the right, and the direction is counter-clock-wise */ - fun setToPolar(angle: Angle, length: Double = 1.0): Point = setToPolar(0.0, 0.0, angle, length) - fun setToPolar(base: IPoint, angle: Angle, length: Double = 1.0): Point = setToPolar(base.x, base.y, angle, length) - fun setToPolar(x: Double, y: Double, angle: Angle, length: Double = 1.0): Point = setTo(x + angle.cosine * length, y + angle.sine * length) - - /** Rotates the vector/point -90 degrees (not normalizing it) */ - fun setToNormal(): Point = setTo(-this.y, this.x) - fun neg() = setTo(-this.x, -this.y) - fun mul(s: Double) = setTo(this.x * s, this.y * s) - fun mul(s: Float) = mul(s.toDouble()) - fun mul(s: Int) = mul(s.toDouble()) - - fun add(p: Point) = this.setToAdd(this, p) - fun sub(p: Point) = this.setToSub(this, p) - - fun add(x: Double, y: Double) = this.setTo(this.x + x, this.y + y) - fun sub(x: Double, y: Double) = this.setTo(this.x - x, this.y - y) - - fun copyFrom(that: IPoint) = setTo(that.x, that.y) - - fun setToTransform(mat: Matrix, p: Point): Point = setToTransform(mat, p.x, p.y) - fun setToTransform(mat: Matrix, x: Double, y: Double): Point = setTo(mat.transformX(x, y), mat.transformY(x, y)) - - fun setToAdd(a: Point, b: Point): Point = setTo(a.x + b.x, a.y + b.y) - fun setToSub(a: Point, b: Point): Point = setTo(a.x - b.x, a.y - b.y) - fun setToMul(a: Point, b: Point): Point = setTo(a.x * b.x, a.y * b.y) - fun setToMul(a: Point, s: Double): Point = setTo(a.x * s, a.y * s) - fun setToMul(a: Point, s: Float): Point = setToMul(a, s.toDouble()) - fun setToDiv(a: Point, b: Point): Point = setTo(a.x / b.x, a.y / b.y) - fun setToDiv(a: Point, s: Double): Point = setTo(a.x / s, a.y / s) - fun setToDiv(a: Point, s: Float): Point = setToDiv(a, s.toDouble()) - operator fun plusAssign(that: Point) { setTo(this.x + that.x, this.y + that.y) } - - operator fun plus(that: IPoint): Point = Point(this.x + that.x, this.y + that.y) - operator fun minus(that: IPoint): Point = Point(this.x - that.x, this.y - that.y) - operator fun times(that: IPoint): Point = Point(this.x * that.x, this.y * that.y) - operator fun div(that: IPoint): Point = Point(this.x / that.x, this.y / that.y) - infix fun dot(that: IPoint): Double = this.x * that.x + this.y * that.y - - operator fun times(scale: Double): Point = Point(this.x * scale, this.y * scale) - operator fun times(scale: Float): Point = this * scale.toDouble() - operator fun times(scale: Int): Point = this * scale.toDouble() - - operator fun div(scale: Double): Point = Point(this.x / scale, this.y / scale) - operator fun div(scale: Float): Point = this / scale.toDouble() - operator fun div(scale: Int): Point = this / scale.toDouble() - - fun distanceTo(x: Double, y: Double): Double = hypot(x - this.x, y - this.y) - fun distanceTo(x: Int, y: Int): Double = distanceTo(x.toDouble(), y.toDouble()) - fun distanceTo(x: Float, y: Float): Float = distanceTo(x.toDouble(), y.toDouble()).toFloat() - - fun distanceTo(that: Point): Double = distanceTo(that.x, that.y) - fun angleTo(other: Point): Angle = Angle.between(this.x, this.y, other.x, other.y) - fun transformed(mat: Matrix, out: Point = Point()): Point = out.setToTransform(mat, this) - operator fun get(index: Int) = when (index) { - 0 -> this.x; 1 -> this.y - else -> throw IndexOutOfBoundsException("IPoint doesn't have $index component") - } - val mutable: Point get() = Point(this.x, this.y) - val immutable: Point get() = Point(this.x, this.y) - fun copy() = Point(this.x, this.y) - - - val unit: Point get() = this / this.length - val squaredLength: Double get() = (x * x) + (y * y) - val length: Double get() = hypot(this.x, this.y) - val magnitude: Double get() = hypot(this.x, this.y) - val normalized: Point - get() { - val imag = 1.0 / magnitude - return Point(this.x * imag, this.y * imag) - } - - fun normalize() { - val len = this.length - when { - len.isAlmostZero() -> this.setTo(0, 0) - else -> this.setTo(this.x / len, this.y / len) - } - } - - override fun interpolateWith(ratio: Double, other: Point): Point = - Point().setToInterpolated(ratio, this, other) - - override fun setToInterpolated(ratio: Double, l: Point, r: Point): Point = setToInterpolated(ratio, l.x, l.y, r.x, r.y) - fun setToInterpolated(ratio: Double, l: IPoint, r: IPoint): Point = setToInterpolated(ratio, l.x, l.y, r.x, r.y) - - fun setToInterpolated(ratio: Double, lx: Double, ly: Double, rx: Double, ry: Double): Point = - this.setTo(ratio.interpolate(lx, rx), ratio.interpolate(ly, ry)) - - override fun toString(): String = "(${this.x.niceStr}, ${this.y.niceStr})" - - fun rotate(rotation: Angle, out: Point = Point()): Point = - out.setToPolar(Angle.between(0.0, 0.0, this.x, this.y) + rotation, this.length) } - -val Point.unit: IPoint get() = this / length - -@Deprecated("Use non Number version") -inline fun Point.setTo(x: Number, y: Number): Point = setTo(x.toDouble(), y.toDouble()) - interface IPointInt { val x: Int val y: Int + val point: PointInt get() = PointInt(x, y) + companion object { - operator fun invoke(x: Int, y: Int): IPointInt = PointInt(x, y) + operator fun invoke(x: Int, y: Int): IPointInt = MPointInt(x, y) } } -inline class PointInt(val p: Point) : IPointInt, Comparable { +inline class MPointInt(val p: MPoint) : IPointInt, Comparable, MutableInterpolable { override fun compareTo(other: IPointInt): Int = compare(this.x, this.y, other.x, other.y) companion object { - operator fun invoke(): PointInt = PointInt(0, 0) - operator fun invoke(x: Int, y: Int): PointInt = PointInt(Point(x, y)) - operator fun invoke(that: IPointInt): PointInt = PointInt(Point(that.x, that.y)) + operator fun invoke(): MPointInt = MPointInt(0, 0) + operator fun invoke(x: Int, y: Int): MPointInt = MPointInt(MPoint(x, y)) + operator fun invoke(that: IPointInt): MPointInt = MPointInt(MPoint(that.x, that.y)) fun compare(lx: Int, ly: Int, rx: Int, ry: Int): Int { val ret = ly.compareTo(ry) return if (ret == 0) lx.compareTo(rx) else ret } } - override var x: Int - set(value) { p.x = value.toDouble() } - get() = p.x.toInt() - override var y: Int - set(value) { p.y = value.toDouble() } - get() = p.y.toInt() - fun setTo(x: Int, y: Int) : PointInt { + override var x: Int ; set(value) { p.x = value.toDouble() } get() = p.x.toInt() + override var y: Int ; set(value) { p.y = value.toDouble() } get() = p.y.toInt() + fun setTo(x: Int, y: Int) : MPointInt { this.x = x this.y = y - return this } fun setTo(that: IPointInt) = this.setTo(that.x, that.y) + + override fun setToInterpolated(ratio: Double, l: MPointInt, r: MPointInt): MPointInt = + setTo(ratio.interpolate(l.x, r.x), ratio.interpolate(l.y, r.y)) + override fun toString(): String = "($x, $y)" } -operator fun IPointInt.plus(that: IPointInt) = PointInt(this.x + that.x, this.y + that.y) -operator fun IPointInt.minus(that: IPointInt) = PointInt(this.x - that.x, this.y - that.y) -operator fun IPointInt.times(that: IPointInt) = PointInt(this.x * that.x, this.y * that.y) -operator fun IPointInt.div(that: IPointInt) = PointInt(this.x / that.x, this.y / that.y) -operator fun IPointInt.rem(that: IPointInt) = PointInt(this.x % that.x, this.y % that.y) +fun MPoint.asInt(): MPointInt = MPointInt(this) +fun MPointInt.asDouble(): MPoint = this.p -fun Point.asInt(): PointInt = PointInt(this) -fun PointInt.asDouble(): Point = this.p - -val Point.int get() = PointInt(this.x.toInt(), this.y.toInt()) -val IPoint.int get() = PointInt(this.x.toInt(), this.y.toInt()) +val MPoint.int get() = MPointInt(this.x.toInt(), this.y.toInt()) +val IPoint.int get() = MPointInt(this.x.toInt(), this.y.toInt()) val IPointInt.float get() = IPoint(x.toDouble(), y.toDouble()) -fun List.getPolylineLength(): Double { +private inline fun getPolylineLength(size: Int, crossinline get: (n: Int, (x: Double, y: Double) -> Unit) -> Unit): Double { var out = 0.0 - var prev: Point? = null - for (cur in this) { - if (prev != null) out += prev.distanceTo(cur) - prev = cur + var prevX = 0.0 + var prevY = 0.0 + for (n in 0 until size) { + get(n) { x, y -> + if (n > 0) { + out += MPoint.distance(prevX, prevY, x, y) + } + prevX = x + prevY = y + } } return out } -fun List.bounds(out: Rectangle = Rectangle(), bb: BoundsBuilder = BoundsBuilder()): Rectangle = bb.add(this).getBounds(out) -fun Iterable.getPolylineLength(): Double { - var out = 0.0 - var prev: IPoint? = null - for (cur in this) { - if (prev != null) out += prev.distanceTo(cur) - prev = cur - } - return out -} -fun Iterable.bounds(out: Rectangle = Rectangle(), bb: BoundsBuilder = BoundsBuilder()): Rectangle = bb.add(this).getBounds(out) +fun IPointArrayList.getPolylineLength(): Double = getPolylineLength(size) { n, func -> func(getX(n), getY(n)) } +fun List.getPolylineLength(): Double = getPolylineLength(size) { n, func -> func(this[n].x, this[n].y) } -fun min(a: Point, b: Point, out: Point = Point()): Point = out.setTo(kotlin.math.min(a.x, b.x), kotlin.math.min(a.y, b.y)) -fun max(a: Point, b: Point, out: Point = Point()): Point = out.setTo(kotlin.math.max(a.x, b.x), kotlin.math.max(a.y, b.y)) -fun Point.clamp(min: Double, max: Double, out: Point = Point()): Point = out.setTo(x.clamp(min, max), y.clamp(min, max)) +fun List.bounds(out: MRectangle = MRectangle(), bb: BoundsBuilder = BoundsBuilder()): MRectangle = bb.add(this).getBounds(out) +fun Iterable.bounds(out: MRectangle = MRectangle(), bb: BoundsBuilder = BoundsBuilder()): MRectangle = bb.add(this).getBounds(out) -typealias Vector2D = Point +fun min(a: IPoint, b: IPoint, out: MPoint = MPoint()): MPoint = out.setTo(kotlin.math.min(a.x, b.x), kotlin.math.min(a.y, b.y)) +fun max(a: IPoint, b: IPoint, out: MPoint = MPoint()): MPoint = out.setTo(kotlin.math.max(a.x, b.x), kotlin.math.max(a.y, b.y)) +fun IPoint.clamp(min: Double, max: Double, out: MPoint = MPoint()): MPoint = out.setTo(x.clamp(min, max), y.clamp(min, max)) diff --git a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/PointArrayList.kt b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/PointArrayList.kt index 327d267b36..a1b3003cce 100644 --- a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/PointArrayList.kt +++ b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/PointArrayList.kt @@ -15,8 +15,11 @@ interface IPointArrayList : IVectorArrayList, Extra { override fun get(index: Int, dim: Int): Double = if (dim == 0) getX(index) else getY(index) fun getX(index: Int): Double fun getY(index: Int): Double + fun get(index: Int, out: MPoint): IPoint = out.setTo(getX(index), getY(index)) } +operator fun IPointArrayList.get(index: Int): Point = Point(getX(index), getY(index)) + fun PointArrayList.setToRoundDecimalPlaces(places: Int): PointArrayList { fastForEachWithIndex { index, x, y -> this.setXY(index, x.roundDecimalPlaces(places), y.roundDecimalPlaces(places)) } return this @@ -38,8 +41,8 @@ val IPointArrayList.firstX: Double get() = getX(0) val IPointArrayList.firstY: Double get() = getY(0) val IPointArrayList.lastX: Double get() = getX(size - 1) val IPointArrayList.lastY: Double get() = getY(size - 1) -fun IPointArrayList.firstPoint(out: Point = Point()): Point = out.setTo(firstX, firstY) -fun IPointArrayList.lastPoint(out: Point = Point()): Point = out.setTo(lastX, lastY) +fun IPointArrayList.firstPoint(out: MPoint = MPoint()): MPoint = out.setTo(firstX, firstY) +fun IPointArrayList.lastPoint(out: MPoint = MPoint()): MPoint = out.setTo(lastX, lastY) fun IPointArrayList.orientation(): Orientation { if (size < 3) return Orientation.COLLINEAR @@ -65,17 +68,17 @@ inline fun IPointArrayList.fastForEachWithIndex(block: (index: Int, x: Double, y } } -fun IPointArrayList.getPoint(index: Int, out: Point = Point()): Point = out.setTo(getX(index), getY(index)) +fun IPointArrayList.getPoint(index: Int, out: MPoint = MPoint()): MPoint = out.setTo(getX(index), getY(index)) fun IPointArrayList.getIPoint(index: Int): IPoint = IPoint(getX(index), getY(index)) -fun IPointArrayList.toList(): List = (0 until size).map { getPoint(it) } +fun IPointArrayList.toList(): List = (0 until size).map { getPoint(it) } -fun IPointArrayList.toPoints(): List = (0 until size).map { getPoint(it) } +fun IPointArrayList.toPoints(): List = (0 until size).map { getPoint(it) } fun IPointArrayList.toIPoints(): List = (0 until size).map { getIPoint(it) } fun IPointArrayList.map(gen: (x: Double, y: Double) -> T): List = (0 until size).map { gen(getX(it), getY(it)) } -fun IPointArrayList.mapPoints(temp: Point = Point(), gen: (x: Double, y: Double, out: Point) -> IPoint): IPointArrayList { +fun IPointArrayList.mapPoints(temp: MPoint = MPoint(), gen: (x: Double, y: Double, out: MPoint) -> IPoint): IPointArrayList { val out = PointArrayList(this.size) fastForEach { x, y -> out.add(gen(x, y, temp)) } return out @@ -144,6 +147,7 @@ open class PointArrayList(capacity: Int = 7) : IPointArrayList, Extra by Extra.M fun add(x: Int, y: Int) = add(x.toDouble(), y.toDouble()) fun add(p: Point) = add(p.x, p.y) + fun add(p: MPoint) = add(p.x, p.y) fun add(p: IPoint) = add(p.x, p.y) fun add(p: IPointArrayList) = this.apply { p.fastForEach { x, y -> add(x, y) } } fun addReverse(p: IPointArrayList) = this.apply { p.fastForEachReverse { x, y -> add(x, y) } } @@ -162,9 +166,9 @@ open class PointArrayList(capacity: Int = 7) : IPointArrayList, Extra by Extra.M } fun clone(out: PointArrayList = PointArrayList()): PointArrayList = out.clear().add(this) - fun toList(): List { - val out = arrayListOf() - fastForEach { x, y -> out.add(Point(x, y)) } + fun toList(): List { + val out = arrayListOf() + fastForEach { x, y -> out.add(MPoint(x, y)) } return out } @@ -206,7 +210,7 @@ open class PointArrayList(capacity: Int = 7) : IPointArrayList, Extra by Extra.M fun setXY(index: Int, x: Float, y: Float) = setXY(index, x.toDouble(), y.toDouble()) fun setXY(index: Int, p: IPoint) = setXY(index, p.x, p.y) - fun transform(matrix: Matrix) { + fun transform(matrix: MMatrix) { for (n in 0 until size) { val x = getX(n) val y = getY(n) @@ -251,7 +255,7 @@ open class PointArrayList(capacity: Int = 7) : IPointArrayList, Extra by Extra.M } object PointSortOpts : SortOps() { - override fun compare(p: PointArrayList, l: Int, r: Int): Int = Point.compare(p.getX(l), p.getY(l), p.getX(r), p.getY(r)) + override fun compare(p: PointArrayList, l: Int, r: Int): Int = MPoint.compare(p.getX(l), p.getY(l), p.getX(r), p.getY(r)) override fun swap(subject: PointArrayList, indexL: Int, indexR: Int) = subject.swap(indexL, indexR) } } @@ -271,9 +275,9 @@ interface IPointIntArrayList { fun getY(index: Int): Int } -fun IPointIntArrayList.getPoint(index: Int, out: PointInt = PointInt()): PointInt = out.setTo(getX(index), getY(index)) +fun IPointIntArrayList.getPoint(index: Int, out: MPointInt = MPointInt()): MPointInt = out.setTo(getX(index), getY(index)) fun IPointIntArrayList.getIPoint(index: Int): IPointInt = IPointInt(getX(index), getY(index)) -fun IPointIntArrayList.toPoints(): List = (0 until size).map { getPoint(it) } +fun IPointIntArrayList.toPoints(): List = (0 until size).map { getPoint(it) } fun IPointIntArrayList.toIPoints(): List = (0 until size).map { getIPoint(it) } fun IPointIntArrayList.contains(x: Int, y: Int): Boolean { for (n in 0 until size) if (getX(n) == x && getY(n) == y) return true @@ -330,9 +334,9 @@ open class PointIntArrayList(capacity: Int = 7) : IPointIntArrayList, Extra by E } } - fun toList(): List { - val out = arrayListOf() - fastForEach { x, y -> out.add(PointInt(x, y)) } + fun toList(): List { + val out = arrayListOf() + fastForEach { x, y -> out.add(MPointInt(x, y)) } return out } @@ -379,12 +383,12 @@ open class PointIntArrayList(capacity: Int = 7) : IPointIntArrayList, Extra by E } object PointSortOpts : SortOps() { - override fun compare(p: PointIntArrayList, l: Int, r: Int): Int = PointInt.compare(p.getX(l), p.getY(l), p.getX(r), p.getY(r)) + override fun compare(p: PointIntArrayList, l: Int, r: Int): Int = MPointInt.compare(p.getX(l), p.getY(l), p.getX(r), p.getY(r)) override fun swap(subject: PointIntArrayList, indexL: Int, indexR: Int) = subject.swap(indexL, indexR) } } -inline fun Iterable.mapPoint(temp: Point = Point(), out: PointArrayList = PointArrayList(), block: Point.(value: T) -> Point): PointArrayList { +inline fun Iterable.mapPoint(temp: MPoint = MPoint(), out: PointArrayList = PointArrayList(), block: MPoint.(value: T) -> MPoint): PointArrayList { for (v in this) { out.add(block(temp, v)) } diff --git a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/PointPool.kt b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/PointPool.kt index a1db1d0330..9d1f09794a 100644 --- a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/PointPool.kt +++ b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/PointPool.kt @@ -7,9 +7,8 @@ import kotlin.jvm.JvmName import kotlin.math.min import kotlin.math.max -typealias PointScope = PointPool - @Suppress("NOTHING_TO_INLINE") +@Deprecated("Use Point instead, no pool needed") class PointPool(val capacity: Int = 16, preallocate: Boolean = false) { @PublishedApi internal var offset = 0 @@ -17,13 +16,13 @@ class PointPool(val capacity: Int = 16, preallocate: Boolean = false) { //@PublishedApi internal val points = Array(capacity) { com.soywiz.korma.geom.Point() } //@PublishedApi internal fun alloc(): Point = points[offset++] - @PublishedApi internal val points = FastArrayList() - @PublishedApi internal fun alloc(): Point { + @PublishedApi internal val points = FastArrayList() + @PublishedApi internal fun alloc(): MPoint { return if (offset < points.size) { points[offset++] } else { offset++ - com.soywiz.korma.geom.Point().also { points.add(it) } + com.soywiz.korma.geom.MPoint().also { points.add(it) } } } @@ -35,15 +34,15 @@ class PointPool(val capacity: Int = 16, preallocate: Boolean = false) { } } - fun MPoint(): Point = alloc() + fun MPoint(): MPoint = alloc() fun Point(x: Double, y: Double): IPoint = alloc().setTo(x, y) fun Point(x: Float, y: Float): IPoint = Point(x.toDouble(), y.toDouble()) fun Point(x: Int, y: Int): IPoint = Point(x.toDouble(), y.toDouble()) fun Point(): IPoint = Point(0.0, 0.0) - fun Point(angle: Angle, length: Double = 1.0): IPoint = Point.fromPolar(angle, length, alloc()) - fun Point(base: IPoint, angle: Angle, length: Double = 1.0): IPoint = Point.fromPolar(base, angle, length, alloc()) - fun Point(angle: Angle, length: Float = 1f): IPoint = Point.fromPolar(angle, length.toDouble(), alloc()) - fun Point(base: IPoint, angle: Angle, length: Float = 1f): IPoint = Point.fromPolar(base, angle, length.toDouble(), alloc()) + fun Point(angle: Angle, length: Double = 1.0): IPoint = MPoint.fromPolar(angle, length, alloc()) + fun Point(base: IPoint, angle: Angle, length: Double = 1.0): IPoint = MPoint.fromPolar(base, angle, length, alloc()) + fun Point(angle: Angle, length: Float = 1f): IPoint = MPoint.fromPolar(angle, length.toDouble(), alloc()) + fun Point(base: IPoint, angle: Angle, length: Float = 1f): IPoint = MPoint.fromPolar(base, angle, length.toDouble(), alloc()) fun abs(a: IPoint): IPoint = alloc().setTo(kotlin.math.abs(a.x), kotlin.math.abs(a.y)) fun sqrt(a: IPoint): IPoint = alloc().setTo(kotlin.math.sqrt(a.x), kotlin.math.sqrt(a.y)) @@ -78,8 +77,8 @@ class PointPool(val capacity: Int = 16, preallocate: Boolean = false) { operator fun IPoint.rem(value: Float): IPoint = this % value.toDouble() operator fun IPoint.rem(value: Int): IPoint = this % value.toDouble() - operator fun IPointArrayList.get(index: Int): Point = MPoint().setTo(this.getX(index), this.getY(index)) - fun IPointArrayList.getCyclic(index: Int): Point = this[index umod size] + operator fun IPointArrayList.get(index: Int): MPoint = MPoint().setTo(this.getX(index), this.getY(index)) + fun IPointArrayList.getCyclic(index: Int): MPoint = this[index umod size] inline operator fun invoke(callback: PointPool.() -> T): T { val oldOffset = offset diff --git a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Quaternion.kt b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Quaternion.kt index ea8fbe0c9e..1efc198e7a 100644 --- a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Quaternion.kt +++ b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Quaternion.kt @@ -9,29 +9,45 @@ import kotlin.math.cos import kotlin.math.sin import kotlin.math.sqrt -// https://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles data class Quaternion( - var x: Double = 0.0, - var y: Double = 0.0, - var z: Double = 0.0, - var w: Double = 1.0 -) { + val x: Double, + val y: Double, + val z: Double, + val w: Double, +) + +@Deprecated("Use Quaternion instead") +interface IQuaternion { + val x: Double + val y: Double + val z: Double + val w: Double +} + +// https://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles +@Deprecated("Use Quaternion instead") +data class MQuaternion( + override var x: Double = 0.0, + override var y: Double = 0.0, + override var z: Double = 0.0, + override var w: Double = 1.0 +) : IQuaternion { constructor(xyz: IVector3, w: Double) : this(xyz.x.toDouble(), xyz.y.toDouble(), xyz.z.toDouble(), w) val lengthSquared: Double get() = (x * x) + (y * y) + (z * z) + (w * w) val length: Double get() = sqrt(lengthSquared) companion object { - fun dotProduct(l: Quaternion, r: Quaternion): Double = l.x * r.x + l.y * r.y + l.z * r.z + l.w * r.w - operator fun invoke(x: Float, y: Float, z: Float, w: Float) = Quaternion(x.toDouble(), y.toDouble(), z.toDouble(), w.toDouble()) - operator fun invoke(x: Int, y: Int, z: Int, w: Int) = Quaternion(x.toDouble(), y.toDouble(), z.toDouble(), w.toDouble()) - fun toEuler(q: Quaternion, out: EulerRotation = EulerRotation()): EulerRotation = toEuler(q.x, q.y, q.z, q.w, out) - fun toEuler(x: Double, y: Double, z: Double, w: Double, euler: EulerRotation = EulerRotation()): EulerRotation = + fun dotProduct(l: MQuaternion, r: MQuaternion): Double = l.x * r.x + l.y * r.y + l.z * r.z + l.w * r.w + operator fun invoke(x: Float, y: Float, z: Float, w: Float) = MQuaternion(x.toDouble(), y.toDouble(), z.toDouble(), w.toDouble()) + operator fun invoke(x: Int, y: Int, z: Int, w: Int) = MQuaternion(x.toDouble(), y.toDouble(), z.toDouble(), w.toDouble()) + fun toEuler(q: MQuaternion, out: MEulerRotation = MEulerRotation()): MEulerRotation = toEuler(q.x, q.y, q.z, q.w, out) + fun toEuler(x: Double, y: Double, z: Double, w: Double, euler: MEulerRotation = MEulerRotation()): MEulerRotation = toEuler(x.toFloat(), y.toFloat(), z.toFloat(), w.toFloat(), euler) - fun toEuler(x: Int, y: Int, z: Int, w: Int, euler: EulerRotation = EulerRotation()): EulerRotation = + fun toEuler(x: Int, y: Int, z: Int, w: Int, euler: MEulerRotation = MEulerRotation()): MEulerRotation = toEuler(x.toFloat(), y.toFloat(), z.toFloat(), w.toFloat(), euler) - fun toEuler(x: Float, y: Float, z: Float, w: Float, out: EulerRotation = EulerRotation()): EulerRotation { + fun toEuler(x: Float, y: Float, z: Float, w: Float, out: MEulerRotation = MEulerRotation()): MEulerRotation { val sinrCosp = +2.0 * (w * x + y * z) val cosrCosp = +1.0 - 2.0 * (x * x + y * y) val roll = atan2(sinrCosp, cosrCosp) @@ -55,37 +71,37 @@ data class Quaternion( else -> Double.NaN } inline fun setToFunc(callback: (Int) -> Double) = setTo(callback(0), callback(1), callback(2), callback(3)) - fun setTo(x: Double, y: Double, z: Double, w: Double): Quaternion { + fun setTo(x: Double, y: Double, z: Double, w: Double): MQuaternion { this.x = x this.y = y this.z = z this.w = w return this } - fun setTo(x: Int, y: Int, z: Int, w: Int): Quaternion = setTo(x.toDouble(), y.toDouble(), z.toDouble(), w.toDouble()) - fun setTo(x: Float, y: Float, z: Float, w: Float): Quaternion = setTo(x.toDouble(), y.toDouble(), z.toDouble(), w.toDouble()) - fun setTo(euler: EulerRotation): Quaternion = EulerRotation.toQuaternion(euler, this) - fun setTo(other: Quaternion): Quaternion = setTo(other.x, other.y, other.z, other.w) + fun setTo(x: Int, y: Int, z: Int, w: Int): MQuaternion = setTo(x.toDouble(), y.toDouble(), z.toDouble(), w.toDouble()) + fun setTo(x: Float, y: Float, z: Float, w: Float): MQuaternion = setTo(x.toDouble(), y.toDouble(), z.toDouble(), w.toDouble()) + fun setTo(euler: MEulerRotation): MQuaternion = MEulerRotation.toQuaternion(euler, this) + fun setTo(other: MQuaternion): MQuaternion = setTo(other.x, other.y, other.z, other.w) - fun setEuler(x: Angle, y: Angle, z: Angle): Quaternion = EulerRotation.toQuaternion(x, y, z, this) - fun setEuler(euler: EulerRotation): Quaternion = EulerRotation.toQuaternion(euler, this) + fun setEuler(x: Angle, y: Angle, z: Angle): MQuaternion = MEulerRotation.toQuaternion(x, y, z, this) + fun setEuler(euler: MEulerRotation): MQuaternion = MEulerRotation.toQuaternion(euler, this) - fun copyFrom(other: Quaternion): Quaternion = this.setTo(other) + fun copyFrom(other: MQuaternion): MQuaternion = this.setTo(other) - operator fun unaryMinus(): Quaternion = Quaternion(-x, -y, -z, -w) - operator fun plus(other: Quaternion): Quaternion = Quaternion(x + other.x, y + other.y, z + other.z, w + other.w) - operator fun minus(other: Quaternion): Quaternion = Quaternion(x - other.x, y - other.y, z - other.z, w - other.w) - operator fun times(scale: Double): Quaternion = Quaternion(x * scale, y * scale, z * scale, w * scale) + operator fun unaryMinus(): MQuaternion = MQuaternion(-x, -y, -z, -w) + operator fun plus(other: MQuaternion): MQuaternion = MQuaternion(x + other.x, y + other.y, z + other.z, w + other.w) + operator fun minus(other: MQuaternion): MQuaternion = MQuaternion(x - other.x, y - other.y, z - other.z, w - other.w) + operator fun times(scale: Double): MQuaternion = MQuaternion(x * scale, y * scale, z * scale, w * scale) fun negate() = this.setTo(-x, -y, -z, -w) - inline fun setToFunc(l: Quaternion, r: Quaternion, func: (l: Double, r: Double) -> Double) = setTo( + inline fun setToFunc(l: MQuaternion, r: MQuaternion, func: (l: Double, r: Double) -> Double) = setTo( func(l.x, r.x), func(l.y, r.y), func(l.z, r.z), func(l.w, r.w) ) - fun setToSlerp(left: Quaternion, right: Quaternion, t: Double, tleft: Quaternion = Quaternion(), tright: Quaternion = Quaternion()): Quaternion { + fun setToSlerp(left: MQuaternion, right: MQuaternion, t: Double, tleft: MQuaternion = MQuaternion(), tright: MQuaternion = MQuaternion()): MQuaternion { val tleft = tleft.copyFrom(left).normalize() val tright = tright.copyFrom(right).normalize() @@ -107,14 +123,14 @@ data class Quaternion( return setToFunc(tleft, tright) { l, r -> (s0 * l) + (s1 * r) } } - fun setToNlerp(left: Quaternion, right: Quaternion, t: Double): Quaternion { + fun setToNlerp(left: MQuaternion, right: MQuaternion, t: Double): MQuaternion { val sign = if (dotProduct(left, right) < 0) -1 else +1 return setToFunc { (1f - t) * left[it] + t * right[it] * sign }.normalize() } - fun setToInterpolated(left: Quaternion, right: Quaternion, t: Double): Quaternion = setToSlerp(left, right, t) + fun setToInterpolated(left: MQuaternion, right: MQuaternion, t: Double): MQuaternion = setToSlerp(left, right, t) - fun setFromRotationMatrix(m: Matrix3D) = this.apply { + fun setFromRotationMatrix(m: MMatrix3D) = this.apply { val q = this m.apply { val t = v00 + v11 + v22 @@ -139,11 +155,11 @@ data class Quaternion( } } - fun normalize(v: Quaternion = this): Quaternion { - val length = 1.0 / Vector3D.length(v.x, v.y, v.z, v.w) + fun normalize(v: MQuaternion = this): MQuaternion { + val length = 1.0 / MVector4.length(v.x, v.y, v.z, v.w) return this.setTo(v.x / length, v.y / length, v.z / length, v.w / length) } - fun toMatrix(out: Matrix3D = Matrix3D()): Matrix3D = out.multiply( + fun toMatrix(out: MMatrix3D = MMatrix3D()): MMatrix3D = out.multiply( // Left w, z, -y, x, -z, w, x, y, @@ -156,7 +172,7 @@ data class Quaternion( x, y, z, w, ) - fun inverted(out: Quaternion = Quaternion()): Quaternion { + fun inverted(out: MQuaternion = MQuaternion()): MQuaternion { val q = this val lengthSquared = q.lengthSquared return if (lengthSquared != 0.0) { @@ -167,23 +183,23 @@ data class Quaternion( } } - val xyz get() = Vector3D(x, y, z) + val xyz get() = MVector4(x, y, z) // @TODO: Optimize - operator fun times(other: Quaternion): Quaternion { + operator fun times(other: MQuaternion): MQuaternion { val left = this val right = other - return Quaternion( - (left.xyz * right.w.toFloat()) + (right.xyz * left.w.toFloat()) + Vector3D().cross(left.xyz, right.xyz), + return MQuaternion( + (left.xyz * right.w.toFloat()) + (right.xyz * left.w.toFloat()) + MVector4().cross(left.xyz, right.xyz), left.w * right.w - left.xyz.dot(right.xyz) ) } // @TODO: Optimize - fun transform(vec: Vector3D, out: Vector3D = Vector3D()): Vector3D { - val result4 = (this * Quaternion(vec.x, vec.y, vec.z, vec.w)) * this.inverted() + fun transform(vec: MVector4, out: MVector4 = MVector4()): MVector4 { + val result4 = (this * MQuaternion(vec.x, vec.y, vec.z, vec.w)) * this.inverted() return out.setTo(result4.x, result4.y, result4.z, result4.w) } } -operator fun Double.times(scale: Quaternion): Quaternion = scale.times(this) +operator fun Double.times(scale: MQuaternion): MQuaternion = scale.times(this) diff --git a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Ray.kt b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Ray.kt index a6138b93d6..0a459f52f6 100644 --- a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Ray.kt +++ b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Ray.kt @@ -1,4 +1,4 @@ package com.soywiz.korma.geom -data class Ray(val point: Point, val direction: Vector2D) { +data class Ray(val point: MPoint, val direction: MVector2D) { } diff --git a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Ray3D.kt b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Ray3D.kt index 513abd1a89..00552ddc0a 100644 --- a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Ray3D.kt +++ b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Ray3D.kt @@ -1,11 +1,11 @@ package com.soywiz.korma.geom -data class Ray3D(val pos: Vector3D, val dir: Vector3D) { +data class Ray3D(val pos: MVector4, val dir: MVector4) { companion object { - fun fromPoints(p1: Vector3D, p2: Vector3D): Ray3D = Ray3D(pos = p1, dir = (p2 - p1).normalized()) + fun fromPoints(p1: MVector4, p2: MVector4): Ray3D = Ray3D(pos = p1, dir = (p2 - p1).normalized()) } - fun transformed(mat: Matrix3D): Ray3D = + fun transformed(mat: MMatrix3D): Ray3D = Ray3D(mat.transform(pos), mat.extractRotation().transform(dir).normalized()) override fun toString(): String = "Ray3D(pos=$pos, dir=$dir)" diff --git a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Ray3DExt.kt b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Ray3DExt.kt index 9fcf2ff3a1..6491f9a7bd 100644 --- a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Ray3DExt.kt +++ b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Ray3DExt.kt @@ -6,7 +6,7 @@ import kotlin.math.min fun Ray3D.intersectRayAABox1(box: AABB3D) : Boolean { val ray = this // r.dir is unit direction vector of ray - val dirfrac = Vector3() + val dirfrac = MVector3() dirfrac.x = 1.0f / ray.dir.x dirfrac.y = 1.0f / ray.dir.y dirfrac.z = 1.0f / ray.dir.z diff --git a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Rectangle.kt b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Rectangle.kt index a8af602106..c2abbe9a73 100644 --- a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Rectangle.kt +++ b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Rectangle.kt @@ -10,37 +10,139 @@ import com.soywiz.korma.math.roundDecimalPlaces import kotlin.math.max import kotlin.math.min +// @TODO: Value Class data class Rectangle( + val x: Double, + val y: Double, + val width: Double, + val height: Double, +) + +@Deprecated("Use Rectangle instead") +interface IRectangle { + val x: Double + val y: Double + val width: Double + val height: Double + + companion object { + inline operator fun invoke( + x: Double, + y: Double, + width: Double, + height: Double + ): IRectangle = MRectangle(x, y, width, height) + + inline operator fun invoke(x: Float, y: Float, width: Float, height: Float): IRectangle = + MRectangle(x, y, width, height) + + inline operator fun invoke(x: Int, y: Int, width: Int, height: Int): IRectangle = + MRectangle(x, y, width, height) + + // Creates a rectangle from 2 points where the (x,y) is the top left point + // with the same width and height as the point. The 2 points provided can be + // in any arbitrary order, the rectangle will be created from the projected + // rectangle of the 2 points. + // + // Here is one example + // Rect XY point1 + // │ │ + // ▼ ▼ + // ┌────────┐ + // │ │ + // │ │ + // └────────┘ + // ▲ + // │ + // point2 + // + // Here is another example + // point1 (Rect XY) + // │ + // ▼ + // ┌────────┐ + // │ │ + // │ │ + // └────────┘ + // ▲ + // │ + // point2 + operator fun invoke(point1: IPoint, point2: IPoint): MRectangle { + val left = minOf(point1.x, point2.x) + val top = minOf(point1.y, point2.y) + val right = maxOf(point1.x, point2.x) + val bottom = maxOf(point1.y, point2.y) + return MRectangle(left, top, right - left, bottom - top) + } + } +} + +val IRectangle.area: Double get() = width * height +fun IRectangle.clone(): MRectangle = MRectangle(x, y, width, height) +val IRectangle.isNotEmpty: Boolean get() = width != 0.0 || height != 0.0 +val IRectangle.mutable: MRectangle get() = MRectangle(x, y, width, height) + +val IRectangle.left get() = x +val IRectangle.top get() = y +val IRectangle.right get() = x + width +val IRectangle.bottom get() = y + height + +val IRectangle.topLeft get() = MPoint(left, top) +val IRectangle.topRight get() = MPoint(right, top) +val IRectangle.bottomLeft get() = MPoint(left, bottom) +val IRectangle.bottomRight get() = MPoint(right, bottom) + +val IRectangle.centerX: Double get() = (right + left) * 0.5 +val IRectangle.centerY: Double get() = (bottom + top) * 0.5 +val IRectangle.center: MPoint get() = MPoint(centerX, centerY) + +/** + * Circle that touches or contains all the corners ([topLeft], [topRight], [bottomLeft], [bottomRight]) of the rectangle. + */ +fun IRectangle.outerCircle(): Circle { + val centerX = centerX + val centerY = centerY + return Circle(center, MPoint.distance(centerX, centerY, right, top)) +} + +operator fun IRectangle.contains(that: IPoint) = contains(that.x, that.y) +operator fun IRectangle.contains(that: IPointInt) = contains(that.x, that.y) +fun IRectangle.contains(x: Double, y: Double) = (x >= left && x < right) && (y >= top && y < bottom) +fun IRectangle.contains(x: Float, y: Float) = contains(x.toDouble(), y.toDouble()) +fun IRectangle.contains(x: Int, y: Int) = contains(x.toDouble(), y.toDouble()) + +@Deprecated("Use Rectangle instead") +data class MRectangle( override var x: Double, override var y: Double, override var width: Double, override var height: Double -) : MutableInterpolable, Interpolable, IRectangle, Sizeable { +) : MutableInterpolable, Interpolable, IRectangle, Sizeable { companion object { - val POOL: ConcurrentPool = ConcurrentPool({ it.clear() }) { Rectangle() } + val POOL: ConcurrentPool = ConcurrentPool({ it.clear() }) { MRectangle() } - operator fun invoke(): Rectangle = Rectangle(0.0, 0.0, 0.0, 0.0) - operator fun invoke(x: Int, y: Int, width: Int, height: Int): Rectangle = - Rectangle(x.toDouble(), y.toDouble(), width.toDouble(), height.toDouble()) + operator fun invoke(): MRectangle = MRectangle(0.0, 0.0, 0.0, 0.0) + operator fun invoke(x: Int, y: Int, width: Int, height: Int): MRectangle = + MRectangle(x.toDouble(), y.toDouble(), width.toDouble(), height.toDouble()) - operator fun invoke(x: Float, y: Float, width: Float, height: Float): Rectangle = - Rectangle(x.toDouble(), y.toDouble(), width.toDouble(), height.toDouble()) + operator fun invoke(x: Float, y: Float, width: Float, height: Float): MRectangle = + MRectangle(x.toDouble(), y.toDouble(), width.toDouble(), height.toDouble()) - operator fun invoke(topLeft: IPoint, size: ISize): Rectangle = - Rectangle(topLeft.x, topLeft.y, size.width, size.height) + operator fun invoke(topLeft: IPoint, size: ISize): MRectangle = + MRectangle(topLeft.x, topLeft.y, size.width, size.height) - fun fromBounds(left: Double, top: Double, right: Double, bottom: Double): Rectangle = - Rectangle().setBounds(left, top, right, bottom) + fun fromBounds(left: Double, top: Double, right: Double, bottom: Double): MRectangle = + MRectangle().setBounds(left, top, right, bottom) - fun fromBounds(left: Int, top: Int, right: Int, bottom: Int): Rectangle = - Rectangle().setBounds(left, top, right, bottom) + fun fromBounds(left: Int, top: Int, right: Int, bottom: Int): MRectangle = + MRectangle().setBounds(left, top, right, bottom) - fun fromBounds(left: Float, top: Float, right: Float, bottom: Float): Rectangle = - Rectangle().setBounds(left, top, right, bottom) + fun fromBounds(left: Float, top: Float, right: Float, bottom: Float): MRectangle = + MRectangle().setBounds(left, top, right, bottom) - fun fromBounds(point1: IPoint, point2: IPoint): Rectangle = + fun fromBounds(point1: IPoint, point2: IPoint): MRectangle = IRectangle(point1, point2) - fun isContainedIn(a: Rectangle, b: Rectangle): Boolean = + fun isContainedIn(a: MRectangle, b: MRectangle): Boolean = a.x >= b.x && a.y >= b.y && a.x + a.width <= b.x + b.width && a.y + a.height <= b.y + b.height } @@ -89,13 +191,13 @@ data class Rectangle( height = value - y } - val position: Point get() = Point(x, y) - override val size: Size get() = Size(width, height) + val position: MPoint get() = MPoint(x, y) + override val size: MSize get() = MSize(width, height) - fun setToBounds(left: Double, top: Double, right: Double, bottom: Double): Rectangle = + fun setToBounds(left: Double, top: Double, right: Double, bottom: Double): MRectangle = setTo(left, top, right - left, bottom - top) - fun setTo(x: Double, y: Double, width: Double, height: Double): Rectangle { + fun setTo(x: Double, y: Double, width: Double, height: Double): MRectangle { this.x = x this.y = y this.width = width @@ -103,10 +205,10 @@ data class Rectangle( return this } - fun setTo(x: Int, y: Int, width: Int, height: Int): Rectangle = + fun setTo(x: Int, y: Int, width: Int, height: Int): MRectangle = setTo(x.toDouble(), y.toDouble(), width.toDouble(), height.toDouble()) - fun setTo(x: Float, y: Float, width: Float, height: Float): Rectangle = + fun setTo(x: Float, y: Float, width: Float, height: Float): MRectangle = setTo(x.toDouble(), y.toDouble(), width.toDouble(), height.toDouble()) fun copyFrom(that: IRectangle) = setTo(that.x, that.y, that.width, that.height) @@ -121,30 +223,30 @@ data class Rectangle( setBounds(left.toDouble(), top.toDouble(), right.toDouble(), bottom.toDouble()) operator fun times(scale: Double) = - Rectangle(x * scale, y * scale, width * scale, height * scale) + MRectangle(x * scale, y * scale, width * scale, height * scale) operator fun times(scale: Float) = this * scale.toDouble() operator fun times(scale: Int) = this * scale.toDouble() - operator fun div(scale: Double) = Rectangle(x / scale, y / scale, width / scale, height / scale) + operator fun div(scale: Double) = MRectangle(x / scale, y / scale, width / scale, height / scale) operator fun div(scale: Float) = this / scale.toDouble() operator fun div(scale: Int) = this / scale.toDouble() - operator fun contains(that: Rectangle) = isContainedIn(that, this) + operator fun contains(that: MRectangle) = isContainedIn(that, this) - infix fun intersects(that: Rectangle): Boolean = intersectsX(that) && intersectsY(that) + infix fun intersects(that: MRectangle): Boolean = intersectsX(that) && intersectsY(that) - infix fun intersectsX(that: Rectangle): Boolean = + infix fun intersectsX(that: MRectangle): Boolean = that.left <= this.right && that.right >= this.left - infix fun intersectsY(that: Rectangle): Boolean = + infix fun intersectsY(that: MRectangle): Boolean = that.top <= this.bottom && that.bottom >= this.top - fun setToIntersection(a: Rectangle, b: Rectangle): Rectangle? { + fun setToIntersection(a: MRectangle, b: MRectangle): MRectangle? { return if (a.intersection(b, this) != null) this else null } - fun setToUnion(a: Rectangle, b: Rectangle): Rectangle = + fun setToUnion(a: MRectangle, b: MRectangle): MRectangle = setToBounds( min(a.left, b.left), min(a.top, b.top), @@ -152,15 +254,15 @@ data class Rectangle( max(a.bottom, b.bottom) ) - infix fun intersection(that: Rectangle) = intersection(that, Rectangle()) + infix fun intersection(that: MRectangle) = intersection(that, MRectangle()) - fun intersection(that: Rectangle, target: Rectangle = Rectangle()) = + fun intersection(that: MRectangle, target: MRectangle = MRectangle()) = if (this intersects that) target.setBounds( max(this.left, that.left), max(this.top, that.top), min(this.right, that.right), min(this.bottom, that.bottom) ) else null - fun displaced(dx: Double, dy: Double) = Rectangle(this.x + dx, this.y + dy, width, height) + fun displaced(dx: Double, dy: Double) = MRectangle(this.x + dx, this.y + dy, width, height) fun displaced(dx: Float, dy: Float) = displaced(dx.toDouble(), dy.toDouble()) fun displaced(dx: Int, dy: Int) = displaced(dx.toDouble(), dy.toDouble()) @@ -169,11 +271,11 @@ data class Rectangle( fun displace(dx: Int, dy: Int) = displace(dx.toDouble(), dy.toDouble()) fun place( - item: Size, + item: MSize, anchor: Anchor, scale: ScaleMode, - out: Rectangle = Rectangle() - ): Rectangle = + out: MRectangle = MRectangle() + ): MRectangle = place(item.width, item.height, anchor, scale, out) fun place( @@ -181,8 +283,8 @@ data class Rectangle( height: Double, anchor: Anchor, scale: ScaleMode, - out: Rectangle = Rectangle() - ): Rectangle { + out: MRectangle = MRectangle() + ): MRectangle { val ow = scale.transformW(width, height, this.width, this.height) val oh = scale.transformH(width, height, this.width, this.height) val x = (this.width - ow) * anchor.sx @@ -195,7 +297,7 @@ data class Rectangle( top: Double = left, right: Double = left, bottom: Double = top - ): Rectangle = + ): MRectangle = setBounds(this.left - left, this.top - top, this.right + right, this.bottom + bottom) inline fun inflate( @@ -203,16 +305,16 @@ data class Rectangle( top: Number = left, right: Number = left, bottom: Number = top - ): Rectangle = inflate(left.toDouble(), top.toDouble(), right.toDouble(), bottom.toDouble()) + ): MRectangle = inflate(left.toDouble(), top.toDouble(), right.toDouble(), bottom.toDouble()) fun clear() = setTo(0.0, 0.0, 0.0, 0.0) - fun clone() = Rectangle(x, y, width, height) + fun clone() = MRectangle(x, y, width, height) - fun setToAnchoredRectangle(item: Rectangle, anchor: Anchor, container: Rectangle) = + fun setToAnchoredRectangle(item: MRectangle, anchor: Anchor, container: MRectangle) = setToAnchoredRectangle(item.size, anchor, container) - fun setToAnchoredRectangle(item: Size, anchor: Anchor, container: Rectangle) = setTo( + fun setToAnchoredRectangle(item: MSize, anchor: Anchor, container: MRectangle) = setTo( container.x + anchor.sx * (container.width - item.width), container.y + anchor.sy * (container.height - item.height), item.width, @@ -232,16 +334,16 @@ data class Rectangle( fun toStringCompat(): String = "Rectangle(x=${left.niceStr}, y=${top.niceStr}, w=${width.niceStr}, h=${height.niceStr})" - override fun equals(other: Any?): Boolean = other is Rectangle + override fun equals(other: Any?): Boolean = other is MRectangle && x.isAlmostEquals(other.x) && y.isAlmostEquals(other.y) && width.isAlmostEquals(other.width) && height.isAlmostEquals(other.height) - override fun interpolateWith(ratio: Double, other: Rectangle): Rectangle = - Rectangle().setToInterpolated(ratio, this, other) + override fun interpolateWith(ratio: Double, other: MRectangle): MRectangle = + MRectangle().setToInterpolated(ratio, this, other) - override fun setToInterpolated(ratio: Double, l: Rectangle, r: Rectangle): Rectangle = + override fun setToInterpolated(ratio: Double, l: MRectangle, r: MRectangle): MRectangle = this.setTo( ratio.interpolate(l.x, r.x), ratio.interpolate(l.y, r.y), @@ -249,16 +351,16 @@ data class Rectangle( ratio.interpolate(l.height, r.height) ) - fun getMiddlePoint(out: Point = Point()): Point = getAnchoredPosition(Anchor.CENTER, out) + fun getMiddlePoint(out: MPoint = MPoint()): MPoint = getAnchoredPosition(Anchor.CENTER, out) - fun getAnchoredPosition(anchor: Anchor, out: Point = Point()): Point = + fun getAnchoredPosition(anchor: Anchor, out: MPoint = MPoint()): MPoint = getAnchoredPosition(anchor.sx, anchor.sy, out) - fun getAnchoredPosition(anchorX: Double, anchorY: Double, out: Point = Point()): Point = + fun getAnchoredPosition(anchorX: Double, anchorY: Double, out: MPoint = MPoint()): MPoint = out.setTo(left + width * anchorX, top + height * anchorY) fun toInt(): RectangleInt = RectangleInt(x.toInt(), y.toInt(), width.toInt(), height.toInt()) - fun floor(): Rectangle { + fun floor(): MRectangle { setTo( kotlin.math.floor(x), kotlin.math.floor(y), @@ -268,7 +370,7 @@ data class Rectangle( return this } - fun round(): Rectangle { + fun round(): MRectangle { setTo( kotlin.math.round(x), kotlin.math.round(y), @@ -278,7 +380,7 @@ data class Rectangle( return this } - fun roundDecimalPlaces(places: Int): Rectangle { + fun roundDecimalPlaces(places: Int): MRectangle { setTo( x.roundDecimalPlaces(places), y.roundDecimalPlaces(places), @@ -288,7 +390,7 @@ data class Rectangle( return this } - fun ceil(): Rectangle { + fun ceil(): MRectangle { setTo( kotlin.math.ceil(x), kotlin.math.ceil(y), @@ -310,7 +412,7 @@ data class Rectangle( } } -fun Rectangle.expand(left: Double, top: Double, right: Double, bottom: Double): Rectangle { +fun MRectangle.expand(left: Double, top: Double, right: Double, bottom: Double): MRectangle { this.left -= left this.top -= top this.width += left + right @@ -318,17 +420,17 @@ fun Rectangle.expand(left: Double, top: Double, right: Double, bottom: Double): return this } -fun Rectangle.expand(left: Int, top: Int, right: Int, bottom: Int): Rectangle = +fun MRectangle.expand(left: Int, top: Int, right: Int, bottom: Int): MRectangle = expand(left.toDouble(), top.toDouble(), right.toDouble(), bottom.toDouble()) -fun Rectangle.expand(margin: Margin): Rectangle = +fun MRectangle.expand(margin: IMargin): MRectangle = expand(margin.left, margin.top, margin.right, margin.bottom) -fun Rectangle.expand(margin: MarginInt): Rectangle = +fun MRectangle.expand(margin: IMarginInt): MRectangle = expand(margin.left, margin.top, margin.right, margin.bottom) @Deprecated("Use non-mixed Int or Double variants for now") -inline fun Rectangle.setTo(x: Number, y: Number, width: Number, height: Number) = +inline fun MRectangle.setTo(x: Number, y: Number, width: Number, height: Number) = this.setTo(x.toDouble(), y.toDouble(), width.toDouble(), height.toDouble()) //////////// INT @@ -353,12 +455,12 @@ interface IRectangleInt { fun IRectangleInt.clone(): RectangleInt = RectangleInt(x, y, width, height) -fun IRectangleInt.expanded(border: IMarginInt): IRectangleInt { +fun IRectangleInt.expanded(border: com.soywiz.korma.geom.IMarginInt): IRectangleInt { return clone().expand(border) } /** Inline expand the rectangle */ -fun RectangleInt.expand(border: IMarginInt): RectangleInt { +fun RectangleInt.expand(border: com.soywiz.korma.geom.IMarginInt): RectangleInt { return this.setBoundsTo(left - border.left, top - border.top, right + border.right, bottom + border.bottom) } @@ -379,12 +481,12 @@ val IRectangleInt.right: Int get() = x + width val IRectangleInt.bottom: Int get() = y + height val IRectangleInt.area: Int get() = width * height -val IRectangleInt.topLeft: PointInt get() = PointInt(left, top) -val IRectangleInt.topRight: PointInt get() = PointInt(right, top) -val IRectangleInt.bottomLeft: PointInt get() = PointInt(left, bottom) -val IRectangleInt.bottomRight: PointInt get() = PointInt(right, bottom) +val IRectangleInt.topLeft: MPointInt get() = MPointInt(left, top) +val IRectangleInt.topRight: MPointInt get() = MPointInt(right, top) +val IRectangleInt.bottomLeft: MPointInt get() = MPointInt(left, bottom) +val IRectangleInt.bottomRight: MPointInt get() = MPointInt(right, bottom) -inline class RectangleInt(val rect: Rectangle) : IRectangleInt { +inline class RectangleInt(val rect: MRectangle) : IRectangleInt { override var x: Int set(value) { rect.x = value.toDouble() @@ -434,18 +536,18 @@ inline class RectangleInt(val rect: Rectangle) : IRectangleInt { get() = rect.bottom.toInt() companion object { - operator fun invoke() = RectangleInt(Rectangle()) + operator fun invoke() = RectangleInt(MRectangle()) operator fun invoke(x: Int, y: Int, width: Int, height: Int) = - RectangleInt(Rectangle(x, y, width, height)) + RectangleInt(MRectangle(x, y, width, height)) operator fun invoke(x: Float, y: Float, width: Float, height: Float) = - RectangleInt(Rectangle(x, y, width, height)) + RectangleInt(MRectangle(x, y, width, height)) operator fun invoke(x: Double, y: Double, width: Double, height: Double) = - RectangleInt(Rectangle(x, y, width, height)) + RectangleInt(MRectangle(x, y, width, height)) operator fun invoke(other: IRectangleInt) = - RectangleInt(Rectangle(other.x, other.y, other.width, other.height)) + RectangleInt(MRectangle(other.x, other.y, other.width, other.height)) fun fromBounds(left: Int, top: Int, right: Int, bottom: Int): RectangleInt = RectangleInt(left, top, right - left, bottom - top) @@ -492,7 +594,7 @@ fun RectangleInt.setSize(width: Int, height: Int): RectangleInt { return this } -fun RectangleInt.getPosition(out: PointInt = PointInt()): PointInt = out.setTo(x, y) +fun RectangleInt.getPosition(out: MPointInt = MPointInt()): MPointInt = out.setTo(x, y) fun RectangleInt.getSize(out: SizeInt = SizeInt()): SizeInt = out.setTo(width, height) val RectangleInt.position get() = getPosition() @@ -526,26 +628,26 @@ fun IRectangleInt.anchoredIn( height ) -fun IRectangleInt.getAnchorPosition(anchor: Anchor, out: PointInt = PointInt()): PointInt = +fun IRectangleInt.getAnchorPosition(anchor: Anchor, out: MPointInt = MPointInt()): MPointInt = out.setTo((x + width * anchor.sx).toInt(), (y + height * anchor.sy).toInt()) -fun Rectangle.asInt() = RectangleInt(this) +fun MRectangle.asInt() = RectangleInt(this) fun RectangleInt.asDouble() = this.rect val IRectangle.int: RectangleInt get() = RectangleInt(x, y, width, height) -val IRectangleInt.float: Rectangle get() = Rectangle(x, y, width, height) +val IRectangleInt.float: MRectangle get() = MRectangle(x, y, width, height) -fun IRectangleInt.anchor(ax: Double, ay: Double): PointInt = - PointInt((x + width * ax).toInt(), (y + height * ay).toInt()) +fun IRectangleInt.anchor(ax: Double, ay: Double): MPointInt = + MPointInt((x + width * ax).toInt(), (y + height * ay).toInt()) -inline fun IRectangleInt.anchor(ax: Number, ay: Number): PointInt = +inline fun IRectangleInt.anchor(ax: Number, ay: Number): MPointInt = anchor(ax.toDouble(), ay.toDouble()) val IRectangleInt.center get() = anchor(0.5, 0.5) /////////////////////////// -fun Iterable.bounds(target: Rectangle = Rectangle()): Rectangle { +fun Iterable.bounds(target: MRectangle = MRectangle()): MRectangle { var first = true var left = 0.0 var right = 0.0 @@ -568,23 +670,23 @@ fun Iterable.bounds(target: Rectangle = Rectangle()): Rectangle { return target.setBounds(left, top, right, bottom) } -fun Rectangle.without(padding: Margin): Rectangle = - Rectangle.fromBounds( +fun MRectangle.without(padding: IMargin): MRectangle = + MRectangle.fromBounds( left + padding.left, top + padding.top, right - padding.right, bottom - padding.bottom ) -fun Rectangle.with(margin: Margin): Rectangle = - Rectangle.fromBounds( +fun MRectangle.with(margin: IMargin): MRectangle = + MRectangle.fromBounds( left - margin.left, top - margin.top, right + margin.right, bottom + margin.bottom ) -fun Rectangle.applyTransform(m: Matrix): Rectangle { +fun MRectangle.applyTransform(m: MMatrix): MRectangle { val tl = m.transform(left, top) val tr = m.transform(right, top) val bl = m.transform(left, bottom) diff --git a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Scale.kt b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Scale.kt new file mode 100644 index 0000000000..03a3a5a9ce --- /dev/null +++ b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Scale.kt @@ -0,0 +1,5 @@ +package com.soywiz.korma.geom + +data class Scale(val scaleX: Double, val scaleY: Double) { + +} diff --git a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/ScaleMode.kt b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/ScaleMode.kt index 292fea95a5..928637aadd 100644 --- a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/ScaleMode.kt +++ b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/ScaleMode.kt @@ -10,15 +10,15 @@ class ScaleMode( fun transformW(iw: Double, ih: Double, cw: Double, ch: Double) = transform(0, iw, ih, cw, ch) fun transformH(iw: Double, ih: Double, cw: Double, ch: Double) = transform(1, iw, ih, cw, ch) - fun transform(iw: Double, ih: Double, cw: Double, ch: Double, target: Size = Size()) = target.setTo( + fun transform(iw: Double, ih: Double, cw: Double, ch: Double, target: MSize = MSize()) = target.setTo( transformW(iw, ih, cw, ch), transformH(iw, ih, cw, ch) ) - fun transformW(item: Size, container: Size) = transformW(item.width, item.height, container.width, container.height) - fun transformH(item: Size, container: Size) = transformH(item.width, item.height, container.width, container.height) + fun transformW(item: MSize, container: MSize) = transformW(item.width, item.height, container.width, container.height) + fun transformH(item: MSize, container: MSize) = transformH(item.width, item.height, container.width, container.height) - operator fun invoke(item: ISize, container: ISize, target: Size = Size()): Size = + operator fun invoke(item: ISize, container: ISize, target: MSize = MSize()): MSize = transform(item.width, item.height, container.width, container.height, target) operator fun invoke(item: ISizeInt, container: ISizeInt, target: SizeInt = SizeInt()): SizeInt = target.setTo( @@ -31,41 +31,41 @@ class ScaleMode( } companion object { - val COVER = ScaleMode("COVER") { c, iw, ih, cw, ch -> + val COVER: ScaleMode = ScaleMode("COVER") { c, iw, ih, cw, ch -> val s0 = cw / iw val s1 = ch / ih val s = max(s0, s1) if (c == 0) iw * s else ih * s } - val SHOW_ALL = ScaleMode("SHOW_ALL") { c, iw, ih, cw, ch -> + val SHOW_ALL: ScaleMode = ScaleMode("SHOW_ALL") { c, iw, ih, cw, ch -> val s0 = cw / iw val s1 = ch / ih val s = min(s0, s1) if (c == 0) iw * s else ih * s } - val FIT get() = SHOW_ALL + val FIT: ScaleMode get() = SHOW_ALL - val FILL get() = EXACT + val FILL: ScaleMode get() = EXACT - val EXACT = ScaleMode("EXACT") { c, iw, ih, cw, ch -> + val EXACT: ScaleMode = ScaleMode("EXACT") { c, iw, ih, cw, ch -> if (c == 0) cw else ch } - val NO_SCALE = ScaleMode("NO_SCALE") { c, iw, ih, cw, ch -> + val NO_SCALE: ScaleMode = ScaleMode("NO_SCALE") { c, iw, ih, cw, ch -> if (c == 0) iw else ih } } } -fun Rectangle.applyScaleMode( - container: Rectangle, mode: ScaleMode, anchor: Anchor, out: Rectangle = Rectangle() -): Rectangle = this.size.applyScaleMode(container, mode, anchor, out) +fun MRectangle.applyScaleMode( + container: MRectangle, mode: ScaleMode, anchor: Anchor, out: MRectangle = MRectangle() +): MRectangle = this.size.applyScaleMode(container, mode, anchor, out) -fun Size.applyScaleMode(container: Rectangle, mode: ScaleMode, anchor: Anchor, out: Rectangle = Rectangle(), tempSize: Size = Size()): Rectangle { +fun MSize.applyScaleMode(container: MRectangle, mode: ScaleMode, anchor: Anchor, out: MRectangle = MRectangle(), tempSize: MSize = MSize()): MRectangle { val outSize = this.applyScaleMode(container.size, mode, tempSize) - out.setToAnchoredRectangle(Rectangle(0.0, 0.0, outSize.width, outSize.height), anchor, container) + out.setToAnchoredRectangle(MRectangle(0.0, 0.0, outSize.width, outSize.height), anchor, container) return out } @@ -74,10 +74,10 @@ fun SizeInt.applyScaleMode(container: RectangleInt, mode: ScaleMode, anchor: Anc fun SizeInt.applyScaleMode(container: SizeInt, mode: ScaleMode, out: SizeInt = SizeInt(0, 0)): SizeInt = mode(this, container, out) -fun Size.applyScaleMode(container: Size, mode: ScaleMode, out: Size = Size(0, 0)): Size = +fun MSize.applyScaleMode(container: MSize, mode: ScaleMode, out: MSize = MSize(0, 0)): MSize = mode(this, container, out) fun SizeInt.fitTo(container: SizeInt, out: SizeInt = SizeInt(0, 0)): SizeInt = applyScaleMode(container, ScaleMode.SHOW_ALL, out) -fun Size.fitTo(container: Size, out: Size = Size(0, 0)): Size = +fun MSize.fitTo(container: MSize, out: MSize = MSize(0, 0)): MSize = applyScaleMode(container, ScaleMode.SHOW_ALL, out) diff --git a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Size.kt b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Size.kt index 3aaf3efb1a..9c170ca373 100644 --- a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Size.kt +++ b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Size.kt @@ -7,6 +7,15 @@ import com.soywiz.korma.interpolation.interpolate import kotlin.math.max import kotlin.math.min +data class Size(val width: Double, val height: Double) { + constructor() : this(0.0, 0.0) + constructor(width: Float, height: Float) : this(width.toDouble(), height.toDouble()) + constructor(width: Int, height: Int) : this(width.toDouble(), height.toDouble()) + + override fun toString(): String = "Size(width=${width.niceStr}, height=${height.niceStr})" +} + +@Deprecated("Use Size") interface ISize { val width: Double val height: Double @@ -17,26 +26,27 @@ interface ISize { val max: Double get() = max(width, height) companion object { - operator fun invoke(width: Double, height: Double): ISize = Size(Point(width, height)) - operator fun invoke(width: Int, height: Int): ISize = Size(Point(width, height)) - operator fun invoke(width: Float, height: Float): ISize = Size(Point(width, height)) + operator fun invoke(width: Double, height: Double): ISize = MSize(MPoint(width, height)) + operator fun invoke(width: Int, height: Int): ISize = MSize(MPoint(width, height)) + operator fun invoke(width: Float, height: Float): ISize = MSize(MPoint(width, height)) } } -fun Point.asSize(): Size = Size(this) -fun IPoint.asSize(): ISize = Size(Point(this)) +fun MPoint.asSize(): MSize = MSize(this) +fun IPoint.asSize(): ISize = MSize(MPoint(this)) -inline class Size(val p: Point) : MutableInterpolable, Interpolable, ISize, Sizeable { +@Deprecated("Use Size") +inline class MSize(val p: MPoint) : MutableInterpolable, Interpolable, ISize, Sizeable { companion object { - operator fun invoke(): Size = Size(Point(0, 0)) - operator fun invoke(width: Double, height: Double): Size = Size(Point(width, height)) - operator fun invoke(width: Int, height: Int): Size = Size(Point(width, height)) - operator fun invoke(width: Float, height: Float): Size = Size(Point(width, height)) + operator fun invoke(): MSize = MSize(MPoint(0, 0)) + operator fun invoke(width: Double, height: Double): MSize = MSize(MPoint(width, height)) + operator fun invoke(width: Int, height: Int): MSize = MSize(MPoint(width, height)) + operator fun invoke(width: Float, height: Float): MSize = MSize(MPoint(width, height)) } - fun copy() = Size(p.copy()) + fun copy() = MSize(p.copy()) - override val size: Size get() = this + override val size: MSize get() = this override var width: Double set(value) { p.x = value } @@ -45,7 +55,7 @@ inline class Size(val p: Point) : MutableInterpolable, Interpolable, set(value) { p.y = value } get() = p.y - fun setTo(width: Double, height: Double): Size { + fun setTo(width: Double, height: Double): MSize { this.width = width this.height = height return this @@ -58,11 +68,11 @@ inline class Size(val p: Point) : MutableInterpolable, Interpolable, fun setToScaled(sx: Float, sy: Float) = setToScaled(sx.toDouble(), sy.toDouble()) fun setToScaled(sx: Int, sy: Int) = setToScaled(sx.toDouble(), sy.toDouble()) - fun clone() = Size(width, height) + fun clone() = MSize(width, height) - override fun interpolateWith(ratio: Double, other: Size): Size = Size(0, 0).setToInterpolated(ratio, this, other) + override fun interpolateWith(ratio: Double, other: MSize): MSize = MSize(0, 0).setToInterpolated(ratio, this, other) - override fun setToInterpolated(ratio: Double, l: Size, r: Size): Size = this.setTo( + override fun setToInterpolated(ratio: Double, l: MSize, r: MSize): MSize = this.setTo( ratio.interpolate(l.width, r.width), ratio.interpolate(l.height, r.height) ) @@ -79,11 +89,11 @@ interface ISizeInt { } } -inline class SizeInt(val size: Size) : ISizeInt { +inline class SizeInt(val size: MSize) : ISizeInt { companion object { - operator fun invoke(): SizeInt = SizeInt(Size(0, 0)) - operator fun invoke(x: Int, y: Int): SizeInt = SizeInt(Size(x, y)) - operator fun invoke(that: ISizeInt): SizeInt = SizeInt(Size(that.width, that.height)) + operator fun invoke(): SizeInt = SizeInt(MSize(0, 0)) + operator fun invoke(x: Int, y: Int): SizeInt = SizeInt(MSize(x, y)) + operator fun invoke(that: ISizeInt): SizeInt = SizeInt(MSize(that.width, that.height)) } fun clone() = SizeInt(size.clone()) @@ -122,16 +132,16 @@ fun SizeInt.anchoredIn(container: RectangleInt, anchor: Anchor, out: RectangleIn } operator fun SizeInt.contains(v: SizeInt): Boolean = (v.width <= width) && (v.height <= height) -operator fun SizeInt.times(v: Double) = SizeInt(Size((width * v).toInt(), (height * v).toInt())) +operator fun SizeInt.times(v: Double) = SizeInt(MSize((width * v).toInt(), (height * v).toInt())) operator fun SizeInt.times(v: Int) = this * v.toDouble() operator fun SizeInt.times(v: Float) = this * v.toDouble() -fun SizeInt.getAnchorPosition(anchor: Anchor, out: PointInt = PointInt(0, 0)): PointInt = +fun SizeInt.getAnchorPosition(anchor: Anchor, out: MPointInt = MPointInt(0, 0)): MPointInt = out.setTo((width * anchor.sx).toInt(), (height * anchor.sy).toInt()) -fun Size.asInt(): SizeInt = SizeInt(this) -fun SizeInt.asDouble(): Size = this.size +fun MSize.asInt(): SizeInt = SizeInt(this) +fun SizeInt.asDouble(): MSize = this.size interface Sizeable { - val size: Size + val size: MSize } diff --git a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Vector2.kt b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Vector2.kt new file mode 100644 index 0000000000..a7b7a773aa --- /dev/null +++ b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Vector2.kt @@ -0,0 +1,5 @@ +package com.soywiz.korma.geom + +typealias PointF = Vector2 + +data class Vector2(val x: Float, val y: Float) diff --git a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Vector3.kt b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Vector3.kt index 55016f1f73..cf048b7f1e 100644 --- a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Vector3.kt +++ b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Vector3.kt @@ -5,6 +5,9 @@ import com.soywiz.korma.interpolation.interpolate import com.soywiz.korma.math.almostEquals import kotlin.math.sqrt +data class Vector3(val x: Float, val y: Float, val z: Float) + +@Deprecated("Use Vector3") interface IVector3 { val x: Float val y: Float @@ -18,13 +21,16 @@ operator fun IVector3.get(index: Int) = when (index) { else -> 0f } -interface MVector3 : IVector3 { +@Deprecated("Use Vector3") +interface IMVector3 : IVector3 { override var x: Float override var y: Float override var z: Float + + val vector: Vector3 get() = Vector3(x, y, z) } -operator fun MVector3.set(index: Int, value: Float) { +operator fun IMVector3.set(index: Int, value: Float) { when (index) { 0 -> x = value 1 -> y = value @@ -32,9 +38,11 @@ operator fun MVector3.set(index: Int, value: Float) { } } -fun vec(x: Float, y: Float, z: Float) = Vector3(x, y, z) +@Deprecated("Use Vector3") +fun vec(x: Float, y: Float, z: Float): MVector3 = MVector3(x, y, z) -class Vector3 : MVector3 { +@Deprecated("Use Vector3") +class MVector3 : IMVector3 { val data: FloatArray = FloatArray(3) override var x: Float get() = data[0]; set(value) { data[0] = value } @@ -48,9 +56,9 @@ class Vector3 : MVector3 { operator fun set(index: Int, value: Float) { data[index] = value } companion object { - operator fun invoke(x: Float, y: Float, z: Float): Vector3 = Vector3().setTo(x, y, z) - operator fun invoke(x: Double, y: Double, z: Double): Vector3 = Vector3().setTo(x, y, z) - operator fun invoke(x: Int, y: Int, z: Int): Vector3 = Vector3().setTo(x, y, z) + operator fun invoke(x: Float, y: Float, z: Float): MVector3 = MVector3().setTo(x, y, z) + operator fun invoke(x: Double, y: Double, z: Double): MVector3 = MVector3().setTo(x, y, z) + operator fun invoke(x: Int, y: Int, z: Int): MVector3 = MVector3().setTo(x, y, z) fun length(x: Double, y: Double, z: Double): Double = sqrt(lengthSq(x, y, z)) fun length(x: Float, y: Float, z: Float): Float = sqrt(lengthSq(x, y, z)) @@ -59,57 +67,57 @@ class Vector3 : MVector3 { fun lengthSq(x: Float, y: Float, z: Float): Float = x * x + y * y + z * z } - fun setTo(x: Float, y: Float, z: Float): Vector3 { + fun setTo(x: Float, y: Float, z: Float): MVector3 { this.x = x this.y = y this.z = z return this } - fun setTo(x: Double, y: Double, z: Double): Vector3 = setTo(x.toFloat(), y.toFloat(), z.toFloat()) - fun setTo(x: Int, y: Int, z: Int): Vector3 = setTo(x.toFloat(), y.toFloat(), z.toFloat()) + fun setTo(x: Double, y: Double, z: Double): MVector3 = setTo(x.toFloat(), y.toFloat(), z.toFloat()) + fun setTo(x: Int, y: Int, z: Int): MVector3 = setTo(x.toFloat(), y.toFloat(), z.toFloat()) - inline fun setToFunc(func: (index: Int) -> Float): Vector3 = setTo(func(0), func(1), func(2)) - inline fun setToFunc(l: Vector3D, r: Vector3D, func: (l: Float, r: Float) -> Float) = setTo( + inline fun setToFunc(func: (index: Int) -> Float): MVector3 = setTo(func(0), func(1), func(2)) + inline fun setToFunc(l: MVector4, r: MVector4, func: (l: Float, r: Float) -> Float) = setTo( func(l.x, r.x), func(l.y, r.y), func(l.z, r.z), ) - fun setToInterpolated(left: Vector3D, right: Vector3D, t: Double): Vector3 = setToFunc { t.interpolate(left[it], right[it]) } + fun setToInterpolated(left: MVector4, right: MVector4, t: Double): MVector3 = setToFunc { t.interpolate(left[it], right[it]) } - fun copyFrom(other: Vector3) = setTo(other.x, other.y, other.z) + fun copyFrom(other: MVector3) = setTo(other.x, other.y, other.z) fun scale(scale: Float) = this.setTo(this.x * scale, this.y * scale, this.z * scale) fun scale(scale: Int) = scale(scale.toFloat()) fun scale(scale: Double) = scale(scale.toFloat()) - fun transform(mat: Matrix3D) = mat.transform(this, this) - fun transformed(mat: Matrix3D, out: Vector3 = Vector3()) = mat.transform(this, out) + fun transform(mat: MMatrix3D) = mat.transform(this, this) + fun transformed(mat: MMatrix3D, out: MVector3 = MVector3()) = mat.transform(this, out) - fun normalize(vector: Vector3 = this): Vector3 { + fun normalize(vector: MVector3 = this): MVector3 { val norm = 1.0 / vector.length setTo(vector.x * norm, vector.y * norm, vector.z * norm) return this } - fun normalized(out: Vector3 = Vector3()): Vector3 = out.copyFrom(this).normalize() + fun normalized(out: MVector3 = MVector3()): MVector3 = out.copyFrom(this).normalize() - fun dot(v2: Vector3D): Float = this.x*v2.x + this.y*v2.y + this.z*v2.y + fun dot(v2: MVector4): Float = this.x*v2.x + this.y*v2.y + this.z*v2.y - operator fun plus(that: Vector3D) = Vector3D(this.x + that.x, this.y + that.y, this.z + that.z) - operator fun minus(that: Vector3D) = Vector3D(this.x - that.x, this.y - that.y, this.z - that.z) - operator fun times(scale: Float) = Vector3D(x * scale, y * scale, z * scale) + operator fun plus(that: MVector4) = MVector4(this.x + that.x, this.y + that.y, this.z + that.z) + operator fun minus(that: MVector4) = MVector4(this.x - that.x, this.y - that.y, this.z - that.z) + operator fun times(scale: Float) = MVector4(x * scale, y * scale, z * scale) - fun sub(l: Vector3, r: Vector3) = setTo(l.x - r.x, l.y - r.y, l.z - r.z) - fun add(l: Vector3, r: Vector3) = setTo(l.x + r.x, l.y + r.y, l.z + r.z) - fun cross(a: Vector3, b: Vector3) = setTo( + fun sub(l: MVector3, r: MVector3) = setTo(l.x - r.x, l.y - r.y, l.z - r.z) + fun add(l: MVector3, r: MVector3) = setTo(l.x + r.x, l.y + r.y, l.z + r.z) + fun cross(a: MVector3, b: MVector3) = setTo( (a.y * b.z - a.z * b.y), (a.z * b.x - a.x * b.z), (a.x * b.y - a.y * b.x), ) - fun clone() = Vector3(x, y, z) + fun clone() = MVector3(x, y, z) - override fun equals(other: Any?): Boolean = (other is Vector3) && almostEquals(this.x, other.x) && almostEquals(this.y, other.y) && almostEquals(this.z, other.z) + override fun equals(other: Any?): Boolean = (other is MVector3) && almostEquals(this.x, other.x) && almostEquals(this.y, other.y) && almostEquals(this.z, other.z) override fun hashCode(): Int = data.contentHashCode() override fun toString(): String = "(${x.niceStr}, ${y.niceStr}, ${z.niceStr})" diff --git a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Vector3D.kt b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Vector4.kt similarity index 64% rename from korma/src/commonMain/kotlin/com/soywiz/korma/geom/Vector3D.kt rename to korma/src/commonMain/kotlin/com/soywiz/korma/geom/Vector4.kt index a41bf690ab..952392133d 100644 --- a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Vector3D.kt +++ b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/Vector4.kt @@ -1,10 +1,16 @@ package com.soywiz.korma.geom + import com.soywiz.korma.internal.niceStr import com.soywiz.korma.interpolation.interpolate import com.soywiz.korma.math.almostEquals import kotlin.math.sqrt +data class Vector4(val x: Float, val y: Float, val z: Float, val w: Float) + +@Deprecated("Use Vector4") +typealias MVector3D = MVector4 + /* interface IVector3 { val x: Float @@ -28,7 +34,8 @@ interface Vector4 : Vector3, IVector4 { */ // @TODO: To inline class wrapping FloatArray? -class Vector3D : MVector3 { +@Deprecated("Use Vector4") +class MVector4 : IMVector3 { val data = floatArrayOf(0f, 0f, 0f, 1f) override var x: Float get() = data[0]; set(value) { data[0] = value } @@ -46,9 +53,9 @@ class Vector3D : MVector3 { operator fun set(index: Int, value: Float) { data[index] = value } companion object { - operator fun invoke(x: Float, y: Float, z: Float, w: Float = 1f): Vector3D = Vector3D().setTo(x, y, z, w) - operator fun invoke(x: Double, y: Double, z: Double, w: Double = 1.0): Vector3D = Vector3D().setTo(x, y, z, w) - operator fun invoke(x: Int, y: Int, z: Int, w: Int = 1): Vector3D = Vector3D().setTo(x, y, z, w) + operator fun invoke(x: Float, y: Float, z: Float, w: Float = 1f): MVector4 = MVector4().setTo(x, y, z, w) + operator fun invoke(x: Double, y: Double, z: Double, w: Double = 1.0): MVector4 = MVector4().setTo(x, y, z, w) + operator fun invoke(x: Int, y: Int, z: Int, w: Int = 1): MVector4 = MVector4().setTo(x, y, z, w) fun length(x: Double, y: Double, z: Double, w: Double): Double = sqrt(lengthSq(x, y, z, w)) fun length(x: Double, y: Double, z: Double): Double = sqrt(lengthSq(x, y, z)) @@ -61,66 +68,66 @@ class Vector3D : MVector3 { fun lengthSq(x: Float, y: Float, z: Float): Float = x * x + y * y + z * z } - fun copyFrom(other: Vector3D) = setTo(other.x, other.y, other.z, other.w) + fun copyFrom(other: MVector4) = setTo(other.x, other.y, other.z, other.w) - fun setTo(x: Float, y: Float, z: Float, w: Float): Vector3D = this.apply { this.x = x; this.y = y; this.z = z; this.w = w } - fun setTo(x: Double, y: Double, z: Double, w: Double): Vector3D = setTo(x.toFloat(), y.toFloat(), z.toFloat(), w.toFloat()) - fun setTo(x: Int, y: Int, z: Int, w: Int): Vector3D = setTo(x.toFloat(), y.toFloat(), z.toFloat(), w.toFloat()) + fun setTo(x: Float, y: Float, z: Float, w: Float): MVector4 = this.apply { this.x = x; this.y = y; this.z = z; this.w = w } + fun setTo(x: Double, y: Double, z: Double, w: Double): MVector4 = setTo(x.toFloat(), y.toFloat(), z.toFloat(), w.toFloat()) + fun setTo(x: Int, y: Int, z: Int, w: Int): MVector4 = setTo(x.toFloat(), y.toFloat(), z.toFloat(), w.toFloat()) - fun setTo(x: Float, y: Float, z: Float): Vector3D = setTo(x, y, z, 1f) - fun setTo(x: Double, y: Double, z: Double): Vector3D = setTo(x, y, z, 1.0) - fun setTo(x: Int, y: Int, z: Int): Vector3D = setTo(x, y, z, 1) + fun setTo(x: Float, y: Float, z: Float): MVector4 = setTo(x, y, z, 1f) + fun setTo(x: Double, y: Double, z: Double): MVector4 = setTo(x, y, z, 1.0) + fun setTo(x: Int, y: Int, z: Int): MVector4 = setTo(x, y, z, 1) - inline fun setToFunc(func: (index: Int) -> Float): Vector3D = setTo(func(0), func(1), func(2), func(3)) - inline fun setToFunc(l: Vector3D, r: Vector3D, func: (l: Float, r: Float) -> Float) = setTo( + inline fun setToFunc(func: (index: Int) -> Float): MVector4 = setTo(func(0), func(1), func(2), func(3)) + inline fun setToFunc(l: MVector4, r: MVector4, func: (l: Float, r: Float) -> Float) = setTo( func(l.x, r.x), func(l.y, r.y), func(l.z, r.z), func(l.w, r.w) ) - fun setToInterpolated(left: Vector3D, right: Vector3D, t: Double): Vector3D = setToFunc { t.interpolate(left[it], right[it]) } + fun setToInterpolated(left: MVector4, right: MVector4, t: Double): MVector4 = setToFunc { t.interpolate(left[it], right[it]) } fun scale(scale: Float) = this.setTo(this.x * scale, this.y * scale, this.z * scale, this.w * scale) fun scale(scale: Int) = scale(scale.toFloat()) fun scale(scale: Double) = scale(scale.toFloat()) - fun transform(mat: Matrix3D) = mat.transform(this, this) + fun transform(mat: MMatrix3D) = mat.transform(this, this) - fun normalize(vector: Vector3D = this): Vector3D = this.apply { + fun normalize(vector: MVector4 = this): MVector4 = this.apply { val norm = 1.0 / vector.length3 setTo(vector.x * norm, vector.y * norm, vector.z * norm, 1.0) } - fun normalized(out: Vector3D = Vector3D()): Vector3D = out.copyFrom(this).normalize() + fun normalized(out: MVector4 = MVector4()): MVector4 = out.copyFrom(this).normalize() - fun dot(v2: Vector3D): Float = this.x*v2.x + this.y*v2.y + this.z*v2.y + fun dot(v2: MVector4): Float = this.x*v2.x + this.y*v2.y + this.z*v2.y - operator fun plus(that: Vector3D) = Vector3D(this.x + that.x, this.y + that.y, this.z + that.z, this.w + that.w) - operator fun minus(that: Vector3D) = Vector3D(this.x - that.x, this.y - that.y, this.z - that.z, this.w - that.w) - operator fun times(scale: Float) = Vector3D(x * scale, y * scale, z * scale, w * scale) + operator fun plus(that: MVector4) = MVector4(this.x + that.x, this.y + that.y, this.z + that.z, this.w + that.w) + operator fun minus(that: MVector4) = MVector4(this.x - that.x, this.y - that.y, this.z - that.z, this.w - that.w) + operator fun times(scale: Float) = MVector4(x * scale, y * scale, z * scale, w * scale) - fun sub(l: Vector3D, r: Vector3D): Vector3D = setTo(l.x - r.x, l.y - r.y, l.z - r.z, l.w - r.w) - fun add(l: Vector3D, r: Vector3D): Vector3D = setTo(l.x + r.x, l.y + r.y, l.z + r.z, l.w + r.w) - fun cross(a: Vector3D, b: Vector3D): Vector3D = setTo( + fun sub(l: MVector4, r: MVector4): MVector4 = setTo(l.x - r.x, l.y - r.y, l.z - r.z, l.w - r.w) + fun add(l: MVector4, r: MVector4): MVector4 = setTo(l.x + r.x, l.y + r.y, l.z + r.z, l.w + r.w) + fun cross(a: MVector4, b: MVector4): MVector4 = setTo( (a.y * b.z - a.z * b.y), (a.z * b.x - a.x * b.z), (a.x * b.y - a.y * b.x), 1f ) - override fun equals(other: Any?): Boolean = (other is Vector3D) && almostEquals(this.x, other.x) && almostEquals(this.y, other.y) && almostEquals(this.z, other.z) && almostEquals(this.w, other.w) + override fun equals(other: Any?): Boolean = (other is MVector4) && almostEquals(this.x, other.x) && almostEquals(this.y, other.y) && almostEquals(this.z, other.z) && almostEquals(this.w, other.w) override fun hashCode(): Int = data.contentHashCode() override fun toString(): String = if (w == 1f) "(${x.niceStr}, ${y.niceStr}, ${z.niceStr})" else "(${x.niceStr}, ${y.niceStr}, ${z.niceStr}, ${w.niceStr})" } -inline class IntVector3(val v: Vector3D) { +inline class IntVector3(val v: MVector4) { val x: Int get() = v.x.toInt() val y: Int get() = v.y.toInt() val z: Int get() = v.z.toInt() val w: Int get() = v.w.toInt() } -fun Vector3D.asIntVector3D() = IntVector3(this) +fun MVector4.asIntVector3D() = IntVector3(this) -typealias Position3D = Vector3D -typealias Scale3D = Vector3D +typealias Position3D = MVector4 +typealias Scale3D = MVector4 diff --git a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/bezier/Arc.kt b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/bezier/Arc.kt index 0718bef5ef..b1b7d3960a 100644 --- a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/bezier/Arc.kt +++ b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/bezier/Arc.kt @@ -2,11 +2,10 @@ package com.soywiz.korma.geom.bezier import com.soywiz.korma.geom.Angle import com.soywiz.korma.geom.IPoint -import com.soywiz.korma.geom.Point +import com.soywiz.korma.geom.MPoint import com.soywiz.korma.geom.abs import com.soywiz.korma.geom.absoluteValue import com.soywiz.korma.geom.cosine -import com.soywiz.korma.geom.degrees import com.soywiz.korma.geom.div import com.soywiz.korma.geom.min import com.soywiz.korma.geom.minus @@ -17,7 +16,6 @@ import com.soywiz.korma.geom.shape.buildVectorPath import com.soywiz.korma.geom.sine import com.soywiz.korma.geom.tangent import com.soywiz.korma.geom.times -import com.soywiz.korma.geom.unit import com.soywiz.korma.geom.vector.VectorBuilder import com.soywiz.korma.geom.vector.arc import com.soywiz.korma.geom.vector.isEmpty @@ -39,7 +37,7 @@ object Arc { val c = IPoint(cx, cy) val AB = b - a val AC = c - a - val angle = Point.angleArc(AB, AC).radians * 0.5 + val angle = MPoint.angleArc(AB, AC).radians * 0.5 val x = r * sin((PI / 2.0) - angle) / sin(angle) val A = a + AB.unit * x val B = a + AC.unit * x @@ -125,11 +123,11 @@ object Arc { private fun triangleFindSideFromSideAndHypot(side: Double, hypot: Double): Double = kotlin.math.sqrt(hypot * hypot - side * side) - fun findArcCenter(p1: IPoint, p2: IPoint, radius: Double, out: Point = Point()): IPoint { + fun findArcCenter(p1: IPoint, p2: IPoint, radius: Double, out: MPoint = MPoint()): IPoint { val tangent = p2 - p1 val normal = tangent.mutable.setToNormal().normalized val mid = (p1 + p2) / 2.0 - val lineLen = triangleFindSideFromSideAndHypot(Point.distance(p1, mid), radius) + val lineLen = triangleFindSideFromSideAndHypot(MPoint.distance(p1, mid), radius) return out.copyFrom(mid + normal * lineLen) } diff --git a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/bezier/Bezier.kt b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/bezier/Bezier.kt index 4fd464bc9c..7e67670e0e 100644 --- a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/bezier/Bezier.kt +++ b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/bezier/Bezier.kt @@ -35,7 +35,7 @@ interface IBezier : Curve { fun scaleSimple(d: Double): Bezier = scaleSimple { d } fun scaleSimple(d0: Double, d1: Double): Bezier = scaleSimple { if (it < 0.5) d0 else d1 } /** Computes the point of the curve at [t] */ - fun get(t: Double, out: Point = Point()): IPoint = compute(t, out) + fun get(t: Double, out: MPoint = MPoint()): IPoint = compute(t, out) fun getLUT(steps: Int = 100, out: CurveLUT = CurveLUT(this, steps + 1)): CurveLUT fun project(point: IPoint, out: Bezier.ProjectedPoint = Bezier.ProjectedPoint()): Bezier.ProjectedPoint @@ -43,14 +43,14 @@ interface IBezier : Curve { fun reduce(): List fun overlaps(curve: Bezier): Boolean fun offset(d: Double): List - fun offset(t: Double, d: Double, out: Point = Point()): IPoint + fun offset(t: Double, d: Double, out: MPoint = MPoint()): IPoint fun scaleSimple(d: (Double) -> Double): Bezier fun selfIntersections(threshold: Double = 0.5, out: DoubleArrayList = DoubleArrayList()): DoubleArrayList - fun intersections(line: Line): DoubleArray + fun intersections(line: MLine): DoubleArray fun intersections(curve: Bezier, threshold: Double = 0.5): List> - fun compute(t: Double, out: Point = Point()): IPoint - fun derivative(t: Double, normalize: Boolean = false, out: Point = Point()): IPoint - fun normal(t: Double, normalize: Boolean = true, out: Point = Point()): IPoint + fun compute(t: Double, out: MPoint = MPoint()): IPoint + fun derivative(t: Double, normalize: Boolean = false, out: MPoint = MPoint()): IPoint + fun normal(t: Double, normalize: Boolean = true, out: MPoint = MPoint()): IPoint fun hull(t: Double, out: PointArrayList = PointArrayList()): IPointArrayList fun curvature(t: Double, kOnly: Boolean = false): Bezier.Curvature fun hullOrNull(t: Double, out: PointArrayList = PointArrayList()): IPointArrayList? @@ -59,14 +59,14 @@ interface IBezier : Curve { fun splitLeft(t: Double): SubBezier fun splitRight(t: Double): SubBezier - fun toLine(out: Line = Line()): Line + fun toLine(out: MLine = MLine()): MLine fun toLineBezier(out: Bezier = Bezier()): Bezier fun toCubic(out: Bezier = Bezier()): Bezier fun toQuad(out: Bezier = Bezier()): Bezier fun toQuadList(): List fun outline(d1: Double, d2: Double = d1, d3: Double = d1, d4: Double = d2): Curves fun translate(dx: Double, dy: Double, out: Bezier = Bezier()): Bezier - fun transform(m: Matrix, out: Bezier = Bezier()): Bezier + fun transform(m: MMatrix, out: Bezier = Bezier()): Bezier } /** @@ -162,10 +162,10 @@ class Bezier( } fun roundDecimalPlaces(places: Int): Bezier = Bezier(points.roundDecimalPlaces(places)) - override fun getBounds(target: Rectangle): Rectangle = target.copyFrom(boundingBox) - fun getBounds(target: Rectangle, m: Matrix?): IRectangle = _getBoundingBox(target, m) + override fun getBounds(target: MRectangle): MRectangle = target.copyFrom(boundingBox) + fun getBounds(target: MRectangle, m: MMatrix?): IRectangle = _getBoundingBox(target, m) - override fun calc(t: Double, target: Point): Point { + override fun calc(t: Double, target: MPoint): MPoint { this.compute(t, target) return target } @@ -182,7 +182,7 @@ class Bezier( if (alignedValid) return _aligned alignedValid = true _aligned.clear() - align(points, Line(points.firstX, points.firstY, points.lastX, points.lastY), _aligned) + align(points, MLine(points.firstX, points.firstY, points.lastX, points.lastY), _aligned) return _aligned } @@ -229,7 +229,7 @@ class Bezier( return _outerCircle!! } - private val _boundingBox: Rectangle = Rectangle() + private val _boundingBox: MRectangle = MRectangle() override val boundingBox: IRectangle get() { if (boundingBoxValid) return _boundingBox boundingBoxValid = true @@ -237,7 +237,7 @@ class Bezier( return _boundingBox } - private fun _getBoundingBox(out: Rectangle, m: Matrix? = null): IRectangle { + private fun _getBoundingBox(out: MRectangle, m: MMatrix? = null): IRectangle { var xmin = 0.0 var ymin = 0.0 var xmax = 0.0 @@ -272,7 +272,7 @@ class Bezier( return out } - private val temp = Point() + private val temp = MPoint() private var _length: Double = Double.NaN @@ -370,7 +370,7 @@ class Bezier( //dot = ( bX - aX ) * ( pY - aY ) - ( bY - aY ) * ( pX - aX ); out.p.setTo(aX + atobX * t, aY + atobY * t) out.t = t - out.dSq = Point.distanceSquared(out.p.x, out.p.y, pX, pY) + out.dSq = MPoint.distanceSquared(out.p.x, out.p.y, pX, pY) return out } @@ -394,7 +394,7 @@ class Bezier( mdistSq += 1 while (t < t2 + step) { val p: IPoint = this.compute(t, out.tempP) - val d = Point.distanceSquared(point, p) + val d = MPoint.distanceSquared(point, p) if (d < mdistSq) { mdistSq = d ft = t @@ -412,9 +412,9 @@ class Bezier( return out } - data class ProjectedPoint(val p: Point = Point(), var t: Double = 0.0, var dSq: Double = 0.0) { + data class ProjectedPoint(val p: MPoint = MPoint(), var t: Double = 0.0, var dSq: Double = 0.0) { val d: Double get() = sqrt(dSq) - internal val tempP: Point = Point() + internal val tempP: MPoint = MPoint() fun roundDecimalPlaces(places: Int): ProjectedPoint = ProjectedPoint( p.mutable.setToRoundDecimalPlaces(places), t.roundDecimalPlaces(places), @@ -544,7 +544,7 @@ class Bezier( * A coordinate is returned, representing the point on the curve at * [t]=..., offset along its normal by a distance [d] */ - override fun offset(t: Double, d: Double, out: Point): IPoint { + override fun offset(t: Double, d: Double, out: MPoint): IPoint { // @TODO: Optimize to avoid allocations val pos = calc(t) val normal = normal(t) @@ -598,7 +598,7 @@ class Bezier( val t = n - 1 val p = np.getPoint(t * order) val d = this.derivative(t.toDouble()) - val p2 = Point(p.x + d.x, p.y + d.y) + val p2 = MPoint(p.x + d.x, p.y + d.y) np.add(lli4(p, p2, o, points.getPoint(t + 1)) ?: error("Invalid curve")) } else -> { @@ -655,7 +655,7 @@ class Bezier( return results } - override fun intersections(line: Line): DoubleArray { + override fun intersections(line: MLine): DoubleArray { val minX = line.minX val minY = line.minY val maxX = line.maxX @@ -670,10 +670,10 @@ class Bezier( curveintersects(this.reduce(), curve.reduce(), threshold) /** Computes the point of the curve at [t] */ - override fun compute(t: Double, out: Point): IPoint = compute(t, this.points, out) + override fun compute(t: Double, out: MPoint): IPoint = compute(t, this.points, out) /** The derivate vector of the curve at [t] (normalized when [normalize] is set to true) */ - override fun derivative(t: Double, normalize: Boolean, out: Point): IPoint { + override fun derivative(t: Double, normalize: Boolean, out: MPoint): IPoint { compute(t, dpoints[0], out) if ((t == 0.0 || t == 1.0) && out.squaredLength.isAlmostZero()) { for (n in 0 until 10) { @@ -689,18 +689,18 @@ class Bezier( } /** The normal vector of the curve at [t] (normalized when [normalize] is set to true) */ - override fun normal(t: Double, normalize: Boolean, out: Point): IPoint { + override fun normal(t: Double, normalize: Boolean, out: MPoint): IPoint { derivative(t, normalize, out) return out.setToNormal() //return out.setTo(-out.y, out.x) } - override fun normal(t: Double, target: Point): Point { + override fun normal(t: Double, target: MPoint): MPoint { normal(t, normalize = true, target) return target } - override fun tangent(t: Double, target: Point): Point { + override fun tangent(t: Double, target: MPoint): MPoint { derivative(t, normalize = true, out = target) return target } @@ -769,7 +769,7 @@ class Bezier( val adk: Double = 0.0, ) - override fun toLine(out: Line): Line { + override fun toLine(out: MLine): MLine { val x0 = points.getX(0) val y0 = points.getY(0) val x1 = points.getX(order) @@ -868,16 +868,16 @@ class Bezier( val end = this.points.getPoint(this.points.size - 1) val fline = run { - val s = Point(start.x + n.x * d1, start.y + n.y * d1) - val e = Point(end.x + n.x * d3, end.y + n.y * d3) - val mid = Point((s.x + e.x) / 2.0, (s.y + e.y) / 2.0) + val s = MPoint(start.x + n.x * d1, start.y + n.y * d1) + val e = MPoint(end.x + n.x * d3, end.y + n.y * d3) + val mid = MPoint((s.x + e.x) / 2.0, (s.y + e.y) / 2.0) pointArrayListOf(s, mid, e) } val bline = run { - val s = Point(start.x - n.x * d2, start.y - n.y * d2) - val e = Point(end.x - n.x * d4, end.y - n.y * d4) - val mid = Point((s.x + e.x) / 2.0, (s.y + e.y) / 2.0) + val s = MPoint(start.x - n.x * d2, start.y - n.y * d2) + val e = MPoint(end.x - n.x * d4, end.y - n.y * d4) + val mid = MPoint((s.x + e.x) / 2.0, (s.y + e.y) / 2.0) pointArrayListOf(e, mid, s) }; @@ -940,7 +940,7 @@ class Bezier( override fun translate(dx: Double, dy: Double, out: Bezier): Bezier = out.setPoints(points.mapPoints { x, y, o -> o.setTo(x + dx, y + dy) }) - override fun transform(m: Matrix, out: Bezier): Bezier = + override fun transform(m: MMatrix, out: Bezier): Bezier = out.setPoints(points.mapPoints { x, y, o -> m.transform(x, y, o) }) companion object { @@ -1054,7 +1054,7 @@ class Bezier( return atan2(cross, dot) } - private fun compute(t: Double, points: IPointArrayList, out: Point = Point()): IPoint { + private fun compute(t: Double, points: IPointArrayList, out: MPoint = MPoint()): IPoint { val p = points val order = p.size - 1 if (t == 0.0) return p.getPoint(0, out) @@ -1120,7 +1120,7 @@ class Bezier( private fun align( points: IPointArrayList, - line: Line, + line: MLine, out: PointArrayList = PointArrayList() ): IPointArrayList { val p1 = line.a @@ -1142,9 +1142,9 @@ class Bezier( private fun between(v: Double, min: Double, max: Double): Boolean = ((min <= v) && (v <= max)) || v.isAlmostEquals(min) || v.isAlmostEquals(max) - private val X_AXIS = Line(0, 0, 1, 0) + private val X_AXIS = MLine(0, 0, 1, 0) - private fun roots(points: IPointArrayList, line: Line = X_AXIS): DoubleArray { + private fun roots(points: IPointArrayList, line: MLine = X_AXIS): DoubleArray { val order = points.size - 1 val aligned = align(points, line) @@ -1343,7 +1343,7 @@ class Bezier( return results.distinct() } - private fun lli8(x1: Double, y1: Double, x2: Double, y2: Double, x3: Double, y3: Double, x4: Double, y4: Double, out: Point = Point()): IPoint? { + private fun lli8(x1: Double, y1: Double, x2: Double, y2: Double, x3: Double, y3: Double, x4: Double, y4: Double, out: MPoint = MPoint()): IPoint? { val d = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4) if (d == 0.0) return null val nx = (x1 * y2 - y1 * x2) * (x3 - x4) - (x1 - x2) * (x3 * y4 - y3 * x4) @@ -1351,7 +1351,7 @@ class Bezier( return out.setTo(nx / d, ny / d) } - private fun lli4(p1: IPoint, p2: IPoint, p3: IPoint, p4: IPoint, out: Point = Point()): IPoint? = + private fun lli4(p1: IPoint, p2: IPoint, p3: IPoint, p4: IPoint, out: MPoint = MPoint()): IPoint? = lli8(p1.x, p1.y, p2.x, p2.y, p3.x, p3.y, p4.x, p4.y, out) fun cubicFromPoints(S: IPoint, B: IPoint, E: IPoint, t: Double = 0.5, d1: Double? = null): Bezier { @@ -1367,13 +1367,13 @@ class Bezier( val bx2 = d2 * lx val by2 = d2 * ly // derivation of new hull coordinates - val e1 = Point(B.x - bx1, B.y - by1) - val e2 = Point(B.x + bx2, B.y + by2) + val e1 = MPoint(B.x - bx1, B.y - by1) + val e2 = MPoint(B.x + bx2, B.y + by2) val A = abc.A - val v1 = Point(A.x + (e1.x - A.x) / (1 - t), A.y + (e1.y - A.y) / (1 - t)) - val v2 = Point(A.x + (e2.x - A.x) / t, A.y + (e2.y - A.y) / t) - val nc1 = Point(S.x + (v1.x - S.x) / t, S.y + (v1.y - S.y) / t) - val nc2 = Point( + val v1 = MPoint(A.x + (e1.x - A.x) / (1 - t), A.y + (e1.y - A.y) / (1 - t)) + val v2 = MPoint(A.x + (e2.x - A.x) / t, A.y + (e2.y - A.y) / t) + val nc1 = MPoint(S.x + (v1.x - S.x) / t, S.y + (v1.y - S.y) / t) + val nc2 = MPoint( E.x + (v2.x - E.x) / (1 - t), E.y + (v2.y - E.y) / (1 - t), ) @@ -1393,12 +1393,12 @@ class Bezier( private fun getABC(order: Int, S: IPoint, B: IPoint, E: IPoint, t: Double = 0.5): ABCResult { val u = projectionratio(t, order) val um = 1.0 - u - val C = Point( + val C = MPoint( u * S.x + um * E.x, u * S.y + um * E.y, ) val s = abcratio(t, order) - val A = Point( + val A = MPoint( B.x + (B.x - C.x) / s, B.y + (B.y - C.y) / s, ) @@ -1499,18 +1499,18 @@ class Bezier( fun cubicCalc( p0: IPoint, p1: IPoint, p2: IPoint, p3: IPoint, - t: Double, target: Point = Point() + t: Double, target: MPoint = MPoint() ): IPoint = cubicCalc(p0.x, p0.y, p1.x, p1.y, p2.x, p2.y, p3.x, p3.y, t, target) fun cubicCalc( x0: Double, y0: Double, x1: Double, y1: Double, x2: Double, y2: Double, x3: Double, y3: Double, - t: Double, target: Point = Point() - ): Point = cubicCalc(x0, y0, x1, y1, x2, y2, x3, y3, t) { x, y -> target.setTo(x, y) } + t: Double, target: MPoint = MPoint() + ): MPoint = cubicCalc(x0, y0, x1, y1, x2, y2, x3, y3, t) { x, y -> target.setTo(x, y) } fun quadCalc( p0: IPoint, p1: IPoint, p2: IPoint, - t: Double, target: Point = Point() + t: Double, target: MPoint = MPoint() ): IPoint = quadCalc(p0.x, p0.y, p1.x, p1.y, p2.x, p2.y, t, target) fun quadCalc( @@ -1518,8 +1518,8 @@ class Bezier( xc: Double, yc: Double, x1: Double, y1: Double, t: Double, - target: Point = Point() - ): Point = quadCalc(x0, y0, xc, yc, x1, y1, t) { x, y -> target.setTo(x, y) } + target: MPoint = MPoint() + ): MPoint = quadCalc(x0, y0, xc, yc, x1, y1, t) { x, y -> target.setTo(x, y) } @PublishedApi internal fun quadToCubic1(v0: Double, v1: Double) = v0 + (v1 - v0) * (2.0 / 3.0) @PublishedApi internal fun quadToCubic2(v1: Double, v2: Double) = v2 + (v1 - v2) * (2.0 / 3.0) @@ -1543,4 +1543,4 @@ class Bezier( } } -fun Line.toBezier(): Bezier = Bezier(x0, y0, x1, y1) +fun MLine.toBezier(): Bezier = Bezier(x0, y0, x1, y1) diff --git a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/bezier/Curve.kt b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/bezier/Curve.kt index 20d2b5b200..b8d112e206 100644 --- a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/bezier/Curve.kt +++ b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/bezier/Curve.kt @@ -2,11 +2,11 @@ package com.soywiz.korma.geom.bezier import com.soywiz.kds.forEachRatio01 import com.soywiz.korma.geom.IPointArrayList -import com.soywiz.korma.geom.Point +import com.soywiz.korma.geom.MPoint import com.soywiz.korma.geom.PointArrayList -import com.soywiz.korma.geom.Rectangle +import com.soywiz.korma.geom.MRectangle -fun Curve.calcOffset(t: Double, offset: Double, out: Point = Point()): Point { +fun Curve.calcOffset(t: Double, offset: Double, out: MPoint = MPoint()): MPoint { calc(t, out) val px = out.x val py = out.y @@ -21,10 +21,10 @@ fun Curve.calcOffset(t: Double, offset: Double, out: Point = Point()): Point { interface Curve { val order: Int - fun getBounds(target: Rectangle = Rectangle()): Rectangle - fun normal(t: Double, target: Point = Point()): Point - fun tangent(t: Double, target: Point = Point()): Point - fun calc(t: Double, target: Point = Point()): Point + fun getBounds(target: MRectangle = MRectangle()): MRectangle + fun normal(t: Double, target: MPoint = MPoint()): MPoint + fun tangent(t: Double, target: MPoint = MPoint()): MPoint + fun calc(t: Double, target: MPoint = MPoint()): MPoint fun ratioFromLength(length: Double): Double = TODO() val length: Double // @TODO: We should probably have a function to get ratios in the function to place the points maybe based on inflection points? @@ -37,7 +37,7 @@ interface Curve { @PublishedApi internal fun Curve._getPoints(count: Int = this.recommendedDivisions(), equidistant: Boolean = false, out: PointArrayList = PointArrayList()): IPointArrayList { - val temp = Point() + val temp = MPoint() val curveLength = length forEachRatio01(count) { ratio -> val t = if (equidistant) ratioFromLength(ratio * curveLength) else ratio diff --git a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/bezier/CurveLUT.kt b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/bezier/CurveLUT.kt index b16ee58344..d6a77eb448 100644 --- a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/bezier/CurveLUT.kt +++ b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/bezier/CurveLUT.kt @@ -23,14 +23,14 @@ data class CurveLUT(val curve: Curve, val points: PointArrayList, val ts: Double while (_estimatedLengths.size < size) { val pos = _estimatedLengths.size val prev = _estimatedLengths.last() - _estimatedLengths.add(prev + Point.distance(points.getX(pos - 1), points.getY(pos - 1), points.getX(pos), points.getY(pos))) + _estimatedLengths.add(prev + MPoint.distance(points.getX(pos - 1), points.getY(pos - 1), points.getX(pos), points.getY(pos))) } return _estimatedLengths } val estimatedLength: Double get() = estimatedLengths.last() val steps: Int get() = points.size - 1 val size: Int get() = points.size - val temp = Point() + val temp = MPoint() fun clear() { points.clear() @@ -51,7 +51,7 @@ data class CurveLUT(val curve: Curve, val points: PointArrayList, val ts: Double var mdistSq: Double = Double.POSITIVE_INFINITY var mpos: Int = 0 for (n in 0 until size) { - val d = Point.distanceSquared(this.points.getX(n), this.points.getY(n), point.x, point.y) + val d = MPoint.distanceSquared(this.points.getX(n), this.points.getY(n), point.x, point.y) if (d < mdistSq) { mdistSq = d mpos = n @@ -60,7 +60,7 @@ data class CurveLUT(val curve: Curve, val points: PointArrayList, val ts: Double return ClosestResult(mdistSq = mdistSq, mpos = mpos) } - data class Estimation(var point: Point = Point(), var ratio: Double = 0.0, var length: Double = 0.0) { + data class Estimation(var point: MPoint = MPoint(), var ratio: Double = 0.0, var length: Double = 0.0) { fun roundDecimalDigits(places: Int): Estimation = Estimation(point.copy().setToRoundDecimalPlaces(places), ratio.roundDecimalPlaces(places), length.roundDecimalPlaces(places)) override fun toString(): String = "Estimation(point=${point.niceStr}, ratio=${ratio.niceStr}, length=${length.niceStr})" } diff --git a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/bezier/Curves.kt b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/bezier/Curves.kt index 22e940828e..d02315ecb2 100644 --- a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/bezier/Curves.kt +++ b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/bezier/Curves.kt @@ -5,9 +5,9 @@ import com.soywiz.kds.iterators.fastForEach import com.soywiz.korma.annotations.KormaExperimental import com.soywiz.korma.geom.BoundsBuilder import com.soywiz.korma.geom.IPointArrayList -import com.soywiz.korma.geom.Point +import com.soywiz.korma.geom.MPoint import com.soywiz.korma.geom.PointArrayList -import com.soywiz.korma.geom.Rectangle +import com.soywiz.korma.geom.MRectangle import com.soywiz.korma.geom.fastForEach import com.soywiz.korma.geom.firstX import com.soywiz.korma.geom.firstY @@ -51,7 +51,7 @@ data class Curves(val beziers: List, val closed: Boolean) : Curve, Extra val curve: Bezier, val startLength: Double, val endLength: Double, - val bounds: Rectangle, + val bounds: MRectangle, ) { fun contains(length: Double): Boolean = length in startLength..endLength @@ -73,7 +73,7 @@ data class Curves(val beziers: List, val closed: Boolean) : Curve, Extra val CurveInfo.startRatio: Double get() = this.startLength / this@Curves.length val CurveInfo.endRatio: Double get() = this.endLength / this@Curves.length - override fun getBounds(target: Rectangle): Rectangle { + override fun getBounds(target: MRectangle): MRectangle { bb.reset() infos.fastForEach { bb.addEvenEmpty(it.bounds) } return bb.getBounds(target) @@ -103,13 +103,13 @@ data class Curves(val beziers: List, val closed: Boolean) : Curve, Extra return block(info, ratioInCurve) } - override fun calc(t: Double, target: Point): Point = + override fun calc(t: Double, target: MPoint): MPoint = findTInCurve(t) { info, ratioInCurve -> info.curve.calc(ratioInCurve, target) } - override fun normal(t: Double, target: Point): Point = + override fun normal(t: Double, target: MPoint): MPoint = findTInCurve(t) { info, ratioInCurve -> info.curve.normal(ratioInCurve, target) } - override fun tangent(t: Double, target: Point): Point = + override fun tangent(t: Double, target: MPoint): MPoint = findTInCurve(t) { info, ratioInCurve -> info.curve.tangent(ratioInCurve, target) } override fun ratioFromLength(length: Double): Double { diff --git a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/bezier/CurvesToStroke.kt b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/bezier/CurvesToStroke.kt index 717ed6440b..e9adfdc442 100644 --- a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/bezier/CurvesToStroke.kt +++ b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/bezier/CurvesToStroke.kt @@ -6,19 +6,16 @@ import com.soywiz.kds.getCyclic import com.soywiz.korma.geom.Angle import com.soywiz.korma.geom.IPoint import com.soywiz.korma.geom.IPointArrayList -import com.soywiz.korma.geom.Line -import com.soywiz.korma.geom.Point +import com.soywiz.korma.geom.MLine +import com.soywiz.korma.geom.MPoint import com.soywiz.korma.geom.PointArrayList import com.soywiz.korma.geom.VectorArrayList import com.soywiz.korma.geom.absoluteValue import com.soywiz.korma.geom.degrees import com.soywiz.korma.geom.fastForEachGeneric import com.soywiz.korma.geom.interpolate -import com.soywiz.korma.geom.length import com.soywiz.korma.geom.lineIntersectionPoint import com.soywiz.korma.geom.minus -import com.soywiz.korma.geom.mutable -import com.soywiz.korma.geom.normalized import com.soywiz.korma.geom.plus import com.soywiz.korma.geom.projectedPoint import com.soywiz.korma.geom.umod @@ -29,9 +26,7 @@ import com.soywiz.korma.geom.vector.VectorPath import com.soywiz.korma.geom.vector.toCurvesList import com.soywiz.korma.interpolation.interpolate import com.soywiz.kmem.clamp -import com.soywiz.korma.math.isNanOrInfinite import kotlin.math.absoluteValue -import kotlin.math.sign // @TODO //private fun Curves.toStrokeCurves(join: LineJoin, startCap: LineCap, endCap: LineCap): Curves { @@ -50,7 +45,7 @@ enum class StrokePointsMode { interface StrokePoints { val vector: VectorArrayList val debugPoints: IPointArrayList - val debugSegments: List + val debugSegments: List val mode: StrokePointsMode fun scale(scale: Double) { @@ -76,7 +71,7 @@ class StrokePointsBuilder( }) override val debugPoints: PointArrayList = PointArrayList() - override val debugSegments: ArrayList = arrayListOf() + override val debugSegments: ArrayList = arrayListOf() override fun toString(): String = "StrokePointsBuilder($width, $vector)" @@ -107,16 +102,16 @@ class StrokePointsBuilder( val nextTangent = next.tangent(0.0) val nextNormal = next.normal(0.0) - val currLine0 = Line.fromPointAndDirection(commonPoint + currNormal * width, currTangent) - val currLine1 = Line.fromPointAndDirection(commonPoint + currNormal * -width, currTangent) + val currLine0 = MLine.fromPointAndDirection(commonPoint + currNormal * width, currTangent) + val currLine1 = MLine.fromPointAndDirection(commonPoint + currNormal * -width, currTangent) - val nextLine0 = Line.fromPointAndDirection(commonPoint + nextNormal * width, nextTangent) - val nextLine1 = Line.fromPointAndDirection(commonPoint + nextNormal * -width, nextTangent) + val nextLine0 = MLine.fromPointAndDirection(commonPoint + nextNormal * width, nextTangent) + val nextLine1 = MLine.fromPointAndDirection(commonPoint + nextNormal * -width, nextTangent) //if (!nextLine1.dx.isFinite()) println((next as Bezier).roundDecimalPlaces(2)) - val intersection0 = Line.lineIntersectionPoint(currLine0, nextLine0) - val intersection1 = Line.lineIntersectionPoint(currLine1, nextLine1) + val intersection0 = MLine.lineIntersectionPoint(currLine0, nextLine0) + val intersection1 = MLine.lineIntersectionPoint(currLine1, nextLine1) if (intersection0 == null || intersection1 == null) { // || !intersection0.x.isFinite() || !intersection1.x.isFinite()) { //println("currTangent=$currTangent, nextTangent=$nextTangent") //val signChanged = currTangent.x.sign != nextTangent.x.sign || currTangent.y.sign != nextTangent.y.sign @@ -125,8 +120,8 @@ class StrokePointsBuilder( return } - val direction = Point.crossProduct(currTangent, nextTangent) - val miterLength = Point.distance(intersection0, intersection1) + val direction = MPoint.crossProduct(currTangent, nextTangent) + val miterLength = MPoint.distance(intersection0, intersection1) val miterLimit = miterLimitRatio * width @@ -155,8 +150,8 @@ class StrokePointsBuilder( var p3: IPoint? = when { //angle.absoluteValue > 190.degrees -> null //else -> null - direction <= 0.0 -> Line.lineIntersectionPoint(currLine1, nextLine1) - else -> Line.lineIntersectionPoint(currLine0, nextLine0) + direction <= 0.0 -> MLine.lineIntersectionPoint(currLine1, nextLine1) + else -> MLine.lineIntersectionPoint(currLine0, nextLine0) } val p4Line = if (direction < 0.0) nextLine1 else nextLine0 @@ -179,8 +174,8 @@ class StrokePointsBuilder( debugSegments.add(currLine1.scalePoints(1000.0).clone()) debugSegments.add(nextLine0.scalePoints(1000.0).clone()) debugSegments.add(currLine0.scalePoints(1000.0).clone()) - debugSegments.add(Line.fromPointAndDirection(commonPoint, currTangent).scalePoints(1000.0).clone()) - debugSegments.add(Line.fromPointAndDirection(commonPoint, nextTangent).scalePoints(1000.0).clone()) + debugSegments.add(MLine.fromPointAndDirection(commonPoint, currTangent).scalePoints(1000.0).clone()) + debugSegments.add(MLine.fromPointAndDirection(commonPoint, nextTangent).scalePoints(1000.0).clone()) debugPoints.add(p3) debugPoints.add(p4) debugPoints.add(p5) @@ -247,19 +242,19 @@ class StrokePointsBuilder( } } - fun addCurvePointsCap(p0: IPoint, p3: IPoint, ratio: Double, mid: IPoint = Point.middle(p0, p3), nsteps: Int = NSTEPS) { + fun addCurvePointsCap(p0: IPoint, p3: IPoint, ratio: Double, mid: IPoint = MPoint.middle(p0, p3), nsteps: Int = NSTEPS) { val angleStart = Angle.between(mid, p0) val angleEnd = Angle.between(mid, p3) - if (ratio == 1.0) addTwoPoints(mid, Point.fromPolar(angleEnd), width) - val addAngle = if (Point.crossProduct(p0, p3) <= 0.0) Angle.ZERO else Angle.HALF + if (ratio == 1.0) addTwoPoints(mid, MPoint.fromPolar(angleEnd), width) + val addAngle = if (MPoint.crossProduct(p0, p3) <= 0.0) Angle.ZERO else Angle.HALF forEachRatio01(nsteps, include0 = true, include1 = true) { val angle = it.interpolate(angleStart, angleEnd) - val dir = Point.fromPolar(angle + addAngle) + val dir = MPoint.fromPolar(angle + addAngle) addPoint(mid, dir, 0.0, width) addPoint(mid, dir, width, width) } - if (ratio == 0.0) addTwoPoints(mid, Point.fromPolar(angleStart), width) + if (ratio == 0.0) addTwoPoints(mid, MPoint.fromPolar(angleStart), width) } // @TODO: instead of nsteps we should have some kind of threshold regarding to how much information do we lose at 1:1 scale diff --git a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/bezier/SegmentEmitter.kt b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/bezier/SegmentEmitter.kt index 5153a02cc9..29fddcda45 100644 --- a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/bezier/SegmentEmitter.kt +++ b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/bezier/SegmentEmitter.kt @@ -1,14 +1,14 @@ package com.soywiz.korma.geom.bezier -import com.soywiz.korma.geom.Point +import com.soywiz.korma.geom.MPoint object SegmentEmitter { inline fun emit( segments: Int, - crossinline curveGen: (p: Point, t: Double) -> Point, - crossinline gen: (p0: Point, p1: Point) -> Unit, - p1: Point = Point(), - p2: Point = Point() + crossinline curveGen: (p: MPoint, t: Double) -> MPoint, + crossinline gen: (p0: MPoint, p1: MPoint) -> Unit, + p1: MPoint = MPoint(), + p2: MPoint = MPoint() ) { val dt = 1.0 / segments for (n in 0 until segments) { diff --git a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/bezier/SubCurve.kt b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/bezier/SubCurve.kt index 38041de959..c0c4dcfc47 100644 --- a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/bezier/SubCurve.kt +++ b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/bezier/SubCurve.kt @@ -2,7 +2,7 @@ package com.soywiz.korma.geom.bezier import com.soywiz.korma.geom.IPointArrayList import com.soywiz.korma.geom.IRectangle -import com.soywiz.korma.geom.Point +import com.soywiz.korma.geom.MPoint import com.soywiz.korma.geom.PointArrayList import com.soywiz.korma.geom.roundDecimalPlaces import com.soywiz.korma.internal.niceStr @@ -44,7 +44,7 @@ class SubBezier(val curve: Bezier, val t1: Double, val t2: Double, val parent: B } } - fun calc(t: Double, target: Point = Point()): Point = curve.calc(t.convertRange(t1, t2, 0.0, 1.0), target) + fun calc(t: Double, target: MPoint = MPoint()): MPoint = curve.calc(t.convertRange(t1, t2, 0.0, 1.0), target) private fun _split(t: Double, hull: IPointArrayList?, left: Boolean): SubBezier { val rt = t.convertRange(0.0, 1.0, t1, t2) diff --git a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/binpack/BinPacker.kt b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/binpack/BinPacker.kt index ce25c173e9..d72dccd3c0 100644 --- a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/binpack/BinPacker.kt +++ b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/binpack/BinPacker.kt @@ -2,8 +2,8 @@ package com.soywiz.korma.geom.binpack import com.soywiz.kds.FastArrayList import com.soywiz.kds.iterators.fastForEach -import com.soywiz.korma.geom.Rectangle -import com.soywiz.korma.geom.Size +import com.soywiz.korma.geom.MRectangle +import com.soywiz.korma.geom.MSize import com.soywiz.korma.geom.Sizeable import kotlin.collections.Iterable import kotlin.collections.List @@ -18,65 +18,65 @@ import kotlin.collections.toList class BinPacker(val width: Double, val height: Double, val algo: Algo = MaxRects(width, height)) { interface Algo { - fun add(width: Double, height: Double): Rectangle? + fun add(width: Double, height: Double): MRectangle? } - class Result(val maxWidth: Double, val maxHeight: Double, val items: List>) { + class Result(val maxWidth: Double, val maxHeight: Double, val items: List>) { private val rectanglesNotNull = items.map { it.second }.filterNotNull() val width: Double = rectanglesNotNull.map { it.right }.maxOrNull() ?: 0.0 val height: Double = rectanglesNotNull.map { it.bottom }.maxOrNull() ?: 0.0 - val rects: List get() = items.map { it.second } + val rects: List get() = items.map { it.second } val rectsStr: String get() = rects.toString() } - val allocated = FastArrayList() + val allocated = FastArrayList() - fun Algo.addBatch(items: Iterable, getSize: (T) -> Size): List> { + fun Algo.addBatch(items: Iterable, getSize: (T) -> MSize): List> { val its = items.toList() - val out = hashMapOf() + val out = hashMapOf() val sorted = its.map { it to getSize(it) }.sortedByDescending { it.second.area } for ((i, size) in sorted) out[i] = this.add(size.width, size.height) return its.map { it to out[it] } } - fun add(width: Double, height: Double): Rectangle = addOrNull(width, height) + fun add(width: Double, height: Double): MRectangle = addOrNull(width, height) ?: throw ImageDoNotFitException(width, height, this) - fun add(width: Int, height: Int): Rectangle = add(width.toDouble(), height.toDouble()) - fun add(width: Float, height: Float): Rectangle = add(width.toDouble(), height.toDouble()) + fun add(width: Int, height: Int): MRectangle = add(width.toDouble(), height.toDouble()) + fun add(width: Float, height: Float): MRectangle = add(width.toDouble(), height.toDouble()) - fun addOrNull(width: Double, height: Double): Rectangle? { + fun addOrNull(width: Double, height: Double): MRectangle? { val rect = algo.add(width, height) ?: return null allocated += rect return rect } - fun addOrNull(width: Int, height: Int): Rectangle? = addOrNull(width.toDouble(), height.toDouble()) - fun addOrNull(width: Float, height: Float): Rectangle? = addOrNull(width.toDouble(), height.toDouble()) + fun addOrNull(width: Int, height: Int): MRectangle? = addOrNull(width.toDouble(), height.toDouble()) + fun addOrNull(width: Float, height: Float): MRectangle? = addOrNull(width.toDouble(), height.toDouble()) - fun addBatch(items: Iterable, getSize: (T) -> Size): Result { + fun addBatch(items: Iterable, getSize: (T) -> MSize): Result { return Result(width, height, algo.addBatch(items, getSize)) } - fun addBatch(items: Iterable): List = algo.addBatch(items) { it }.map { it.second } + fun addBatch(items: Iterable): List = algo.addBatch(items) { it }.map { it.second } companion object { operator fun invoke(width: Double, height: Double, algo: Algo = MaxRects(width, height)) = BinPacker(width, height, algo) operator fun invoke(width: Int, height: Int, algo: Algo = MaxRects(width.toDouble(), height.toDouble())) = BinPacker(width.toDouble(), height.toDouble(), algo) operator fun invoke(width: Float, height: Float, algo: Algo = MaxRects(width.toDouble(), height.toDouble())) = BinPacker(width.toDouble(), height.toDouble(), algo) - fun pack(width: Double, height: Double, items: Iterable, getSize: (T) -> Size): Result = BinPacker(width, height).addBatch(items, getSize) - fun pack(width: Int, height: Int, items: Iterable, getSize: (T) -> Size): Result = pack(width.toDouble(), height.toDouble(), items, getSize) - fun pack(width: Float, height: Float, items: Iterable, getSize: (T) -> Size): Result = pack(width.toDouble(), height.toDouble(), items, getSize) + fun pack(width: Double, height: Double, items: Iterable, getSize: (T) -> MSize): Result = BinPacker(width, height).addBatch(items, getSize) + fun pack(width: Int, height: Int, items: Iterable, getSize: (T) -> MSize): Result = pack(width.toDouble(), height.toDouble(), items, getSize) + fun pack(width: Float, height: Float, items: Iterable, getSize: (T) -> MSize): Result = pack(width.toDouble(), height.toDouble(), items, getSize) fun packSeveral( maxWidth: Double, maxHeight: Double, items: Iterable, - getSize: (T) -> Size + getSize: (T) -> MSize ): List> { var currentBinPacker = BinPacker(maxWidth, maxHeight) - var currentPairs = FastArrayList>() + var currentPairs = FastArrayList>() val sortedItems = items.sortedByDescending { getSize(it).area } sortedItems.fastForEach { val size = getSize(it) diff --git a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/binpack/MaxRects.kt b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/binpack/MaxRects.kt index 36dabb9c3d..2f6e90dd99 100644 --- a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/binpack/MaxRects.kt +++ b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/binpack/MaxRects.kt @@ -1,18 +1,18 @@ package com.soywiz.korma.geom.binpack import com.soywiz.kds.fastArrayListOf -import com.soywiz.korma.geom.Rectangle +import com.soywiz.korma.geom.MRectangle class MaxRects( maxWidth: Double, maxHeight: Double ) : BinPacker.Algo { - var freeRectangles = fastArrayListOf(Rectangle(0.0, 0.0, maxWidth, maxHeight)) + var freeRectangles = fastArrayListOf(MRectangle(0.0, 0.0, maxWidth, maxHeight)) - override fun add(width: Double, height: Double): Rectangle? = quickInsert(width, height) + override fun add(width: Double, height: Double): MRectangle? = quickInsert(width, height) - fun quickInsert(width: Double, height: Double): Rectangle? { - if (width <= 0.0 && height <= 0.0) return Rectangle(0, 0, 0, 0) + fun quickInsert(width: Double, height: Double): MRectangle? { + if (width <= 0.0 && height <= 0.0) return MRectangle(0, 0, 0, 0) val newNode = quickFindPositionForNewNodeBestAreaFit(width, height) if (newNode.height == 0.0) return null @@ -32,10 +32,10 @@ class MaxRects( return newNode } - private fun quickFindPositionForNewNodeBestAreaFit(width: Double, height: Double): Rectangle { + private fun quickFindPositionForNewNodeBestAreaFit(width: Double, height: Double): MRectangle { var score = Double.MAX_VALUE var areaFit: Double - val bestNode = Rectangle() + val bestNode = MRectangle() for (r in freeRectangles) { // Try to place the rectangle in upright (non-flipped) orientation. @@ -54,8 +54,8 @@ class MaxRects( return bestNode } - private fun splitFreeNode(freeNode: Rectangle, usedNode: Rectangle): Boolean { - var newNode: Rectangle + private fun splitFreeNode(freeNode: MRectangle, usedNode: MRectangle): Boolean { + var newNode: MRectangle // Test with SAT if the rectangles even intersect. if (usedNode.left >= freeNode.right || usedNode.right <= freeNode.x || usedNode.top >= freeNode.bottom || usedNode.bottom <= freeNode.top) { return false @@ -102,13 +102,13 @@ class MaxRects( val tmpRect = freeRectangles[i] while (j < len) { val tmpRect2 = freeRectangles[j] - if (Rectangle.isContainedIn(tmpRect, tmpRect2)) { + if (MRectangle.isContainedIn(tmpRect, tmpRect2)) { freeRectangles.removeAt(i) --i --len break } - if (Rectangle.isContainedIn(tmpRect2, tmpRect)) { + if (MRectangle.isContainedIn(tmpRect2, tmpRect)) { freeRectangles.removeAt(j) --len --j diff --git a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/collider/HitTestable.kt b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/collider/HitTestable.kt index 613f4a3b84..bed86c27a8 100644 --- a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/collider/HitTestable.kt +++ b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/collider/HitTestable.kt @@ -1,12 +1,7 @@ package com.soywiz.korma.geom.collider import com.soywiz.kds.iterators.fastForEach -import com.soywiz.korma.geom.Angle -import com.soywiz.korma.geom.Point -import com.soywiz.korma.geom.angleTo -import com.soywiz.korma.geom.degrees -import com.soywiz.korma.geom.div -import com.soywiz.korma.geom.plus +import com.soywiz.korma.geom.* import com.soywiz.korma.geom.vector.VectorPath fun interface HitTestable { @@ -62,9 +57,9 @@ enum class HitTestDirection { val left get() = this == ANY || this == LEFT companion object { - fun fromPoint(point: Point): HitTestDirection { + fun fromPoint(point: MPoint): HitTestDirection { if (point.x == 0.0 && point.y == 0.0) return ANY - return fromAngle(Point.Zero.angleTo(point)) + return fromAngle(MPoint.Zero.angleTo(point)) } fun fromAngle(angle: Angle): HitTestDirection { val quadrant = ((angle + 45.degrees) / 90.degrees).toInt() diff --git a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/ds/BVH2D.kt b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/ds/BVH2D.kt index af1f0d02fd..52f9496f03 100644 --- a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/ds/BVH2D.kt +++ b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/ds/BVH2D.kt @@ -5,9 +5,9 @@ import com.soywiz.kds.ds.* import com.soywiz.kds.fastArrayListOf import com.soywiz.korma.geom.IRectangle import com.soywiz.korma.geom.Ray -import com.soywiz.korma.geom.Rectangle +import com.soywiz.korma.geom.MRectangle -fun BVHIntervals.toRectangle(out: Rectangle = Rectangle()) = out.setTo(a(0), a(1), b(0), b(1)) +fun BVHIntervals.toRectangle(out: MRectangle = MRectangle()) = out.setTo(a(0), a(1), b(0), b(1)) fun IRectangle.toBVH(out: BVHIntervals = BVHIntervals(2)): BVHIntervals { out.setTo(x, width, y, height) return out @@ -19,16 +19,16 @@ fun Ray.toBVH(out: BVHIntervals = BVHIntervals(2)): BVHIntervals { /** * A Bounding Volume Hierarchy implementation for 2D. - * It uses [Rectangle] to describe volumes and [Ray] for raycasting. + * It uses [MRectangle] to describe volumes and [Ray] for raycasting. */ open class BVH2D( val allowUpdateObjects: Boolean = true ) { val bvh = BVH(allowUpdateObjects = allowUpdateObjects) - fun intersectRay(ray: Ray, rect: Rectangle? = null) = bvh.intersectRay(ray.toBVH(), rect?.toBVH()) + fun intersectRay(ray: Ray, rect: MRectangle? = null) = bvh.intersectRay(ray.toBVH(), rect?.toBVH()) - fun envelope(): Rectangle = bvh.envelope().toRectangle() + fun envelope(): MRectangle = bvh.envelope().toRectangle() fun intersect( ray: Ray, @@ -46,7 +46,7 @@ open class BVH2D( fun remove(obj: T) = bvh.remove(obj) - fun getObjectBounds(obj: T, out: Rectangle = Rectangle()) = bvh.getObjectBounds(obj)?.toRectangle(out) + fun getObjectBounds(obj: T, out: MRectangle = MRectangle()) = bvh.getObjectBounds(obj)?.toRectangle(out) fun debug() { bvh.debug() diff --git a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/shape/Shape2d.kt b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/shape/Shape2d.kt index f99b35919f..a2b4518636 100644 --- a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/shape/Shape2d.kt +++ b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/shape/Shape2d.kt @@ -15,21 +15,21 @@ import kotlin.math.hypot import kotlin.math.max import kotlin.math.min -private fun Matrix?.tx(x: Double, y: Double) = this?.transformX(x, y) ?: x -private fun Matrix?.ty(x: Double, y: Double) = this?.transformY(x, y) ?: y -private fun Matrix?.dtx(x: Double, y: Double) = this?.deltaTransformX(x, y) ?: x -private fun Matrix?.dty(x: Double, y: Double) = this?.deltaTransformY(x, y) ?: y +private fun MMatrix?.tx(x: Double, y: Double) = this?.transformX(x, y) ?: x +private fun MMatrix?.ty(x: Double, y: Double) = this?.transformY(x, y) ?: y +private fun MMatrix?.dtx(x: Double, y: Double) = this?.deltaTransformX(x, y) ?: x +private fun MMatrix?.dty(x: Double, y: Double) = this?.deltaTransformY(x, y) ?: y private fun optimizedIntersect(l: Shape2d.Circle, r: Shape2d.Circle): Boolean { - return Point.distance(l.x, l.y, r.x, r.y) < (l.radius + r.radius) + return MPoint.distance(l.x, l.y, r.x, r.y) < (l.radius + r.radius) } -private fun optimizedIntersect(l: Shape2d.Circle, ml: Matrix?, r: Shape2d.Circle, mr: Matrix?): Boolean { +private fun optimizedIntersect(l: Shape2d.Circle, ml: MMatrix?, r: Shape2d.Circle, mr: MMatrix?): Boolean { if (ml == null && mr == null) return optimizedIntersect(l, r) val radiusL = ml.dtx(l.radius, l.radius) val radiusR = mr.dtx(r.radius, r.radius) //println("radiusL=$radiusL, radiusR=$radiusR") - return Point.distance( + return MPoint.distance( ml.tx(l.x, l.y), ml.ty(l.x, l.y), mr.tx(r.x, r.y), mr.ty(r.x, r.y), ) < radiusL + radiusR @@ -44,8 +44,8 @@ abstract class Shape2d { abstract val paths: List abstract val closed: Boolean abstract fun containsPoint(x: Double, y: Double): Boolean - fun containsPoint(x: Double, y: Double, mat: Matrix) = containsPoint(mat.transformX(x, y), mat.transformY(x, y)) - open fun getBounds(out: com.soywiz.korma.geom.Rectangle = com.soywiz.korma.geom.Rectangle()): com.soywiz.korma.geom.Rectangle { + fun containsPoint(x: Double, y: Double, mat: MMatrix) = containsPoint(mat.transformX(x, y), mat.transformY(x, y)) + open fun getBounds(out: com.soywiz.korma.geom.MRectangle = com.soywiz.korma.geom.MRectangle()): com.soywiz.korma.geom.MRectangle { var minx = Double.POSITIVE_INFINITY var miny = Double.POSITIVE_INFINITY var maxx = Double.NEGATIVE_INFINITY @@ -60,11 +60,11 @@ abstract class Shape2d { } return out.setBounds(minx, miny, maxx, maxy) } - open fun getCenter(): com.soywiz.korma.geom.Point { + open fun getCenter(): com.soywiz.korma.geom.MPoint { return getBounds().center } companion object { - fun intersects(l: Shape2d, ml: Matrix?, r: Shape2d, mr: Matrix?, tempMatrix: Matrix? = Matrix()): Boolean { + fun intersects(l: Shape2d, ml: MMatrix?, r: Shape2d, mr: MMatrix?, tempMatrix: MMatrix? = MMatrix()): Boolean { //println("Shape2d.intersects:"); println(" - l=$l[$ml]"); println(" - r=$r[$mr]") if (l.type == r.type) { @@ -80,7 +80,7 @@ abstract class Shape2d { return _intersectsStep0(l, ml, r, mr, tempMatrix) || _intersectsStep0(r, mr, l, ml, tempMatrix) } - private fun _intersectsStep0(l: Shape2d, ml: Matrix?, r: Shape2d, mr: Matrix?, tempMatrix: Matrix? = Matrix()): Boolean { + private fun _intersectsStep0(l: Shape2d, ml: MMatrix?, r: Shape2d, mr: MMatrix?, tempMatrix: MMatrix? = MMatrix()): Boolean { if (tempMatrix != null && (ml != null || mr != null)) { if (mr != null) tempMatrix.invert(mr) else tempMatrix.identity() if (ml != null) tempMatrix.premultiply(ml) @@ -109,7 +109,7 @@ abstract class Shape2d { } fun intersectsWith(that: Shape2d) = intersects(this, null, that, null, null) - fun intersectsWith(ml: Matrix?, that: Shape2d, mr: Matrix?) = intersects(this, ml, that, mr) + fun intersectsWith(ml: MMatrix?, that: Shape2d, mr: MMatrix?) = intersects(this, ml, that, mr) infix fun with(that: Shape2d): Shape2d { val left = this @@ -162,7 +162,7 @@ abstract class Shape2d { val vectorPath by lazy { buildVectorPath(VectorPath()) { ellipse(0.0, 0.0, ellipseRadiusX, ellipseRadiusY) - }.applyTransform(Matrix().pretranslate(ellipseX, ellipseY).prerotate(ellipseAngle)) + }.applyTransform(MMatrix().pretranslate(ellipseX, ellipseY).prerotate(ellipseAngle)) } override val paths: List = when { @@ -200,16 +200,16 @@ abstract class Shape2d { } } - data class Rectangle(val rect: com.soywiz.korma.geom.Rectangle) : Shape2d(), WithArea, IRectangle by rect { + data class Rectangle(val rect: com.soywiz.korma.geom.MRectangle) : Shape2d(), WithArea, IRectangle by rect { companion object { const val TYPE = 3 - inline operator fun invoke(x: Double, y: Double, width: Double, height: Double) = Rectangle(com.soywiz.korma.geom.Rectangle(x, y, width, height)) - inline operator fun invoke(x: Float, y: Float, width: Float, height: Float) = Rectangle(com.soywiz.korma.geom.Rectangle(x, y, width, height)) - inline operator fun invoke(x: Int, y: Int, width: Int, height: Int) = Rectangle(com.soywiz.korma.geom.Rectangle(x, y, width, height)) + inline operator fun invoke(x: Double, y: Double, width: Double, height: Double) = Rectangle(com.soywiz.korma.geom.MRectangle(x, y, width, height)) + inline operator fun invoke(x: Float, y: Float, width: Float, height: Float) = Rectangle(com.soywiz.korma.geom.MRectangle(x, y, width, height)) + inline operator fun invoke(x: Int, y: Int, width: Int, height: Int) = Rectangle(com.soywiz.korma.geom.MRectangle(x, y, width, height)) - inline fun fromBounds(left: Double, top: Double, right: Double, down: Double) = Rectangle(com.soywiz.korma.geom.Rectangle.fromBounds(left, top, right, down)) - inline fun fromBounds(left: Float, top: Float, right: Float, down: Float) = Rectangle(com.soywiz.korma.geom.Rectangle.fromBounds(left, top, right, down)) - inline fun fromBounds(left: Int, top: Int, right: Int, down: Int) = Rectangle(com.soywiz.korma.geom.Rectangle.fromBounds(left, top, right, down)) + inline fun fromBounds(left: Double, top: Double, right: Double, down: Double) = Rectangle(com.soywiz.korma.geom.MRectangle.fromBounds(left, top, right, down)) + inline fun fromBounds(left: Float, top: Float, right: Float, down: Float) = Rectangle(com.soywiz.korma.geom.MRectangle.fromBounds(left, top, right, down)) + inline fun fromBounds(left: Int, top: Int, right: Int, down: Int) = Rectangle(com.soywiz.korma.geom.MRectangle.fromBounds(left, top, right, down)) } override val type: Int = TYPE @@ -278,7 +278,7 @@ fun BoundsBuilder.add(shape: Shape2d) { for (path in shape.paths) add(path) } -val Shape2d.bounds: Rectangle get() = BoundsBuilder().apply { add(this@bounds) }.getBounds() +val Shape2d.bounds: MRectangle get() = BoundsBuilder().apply { add(this@bounds) }.getBounds() fun IRectangle.toShape() = Shape2d.Rectangle(x, y, width, height) @@ -366,14 +366,14 @@ inline fun VectorPath.emitPoints2( joint(false) }, quadTo = { x0, y0, x1, y1 -> - val sum = Point.distance(lx, ly, x0, y0) + Point.distance(x0, y0, x1, y1) + val sum = MPoint.distance(lx, ly, x0, y0) + MPoint.distance(x0, y0, x1, y1) approximateCurve(sum.toInt(), { ratio, get -> Bezier.quadCalc(lx, ly, x0, y0, x1, y1, ratio) { x, y -> get(x, y) } }, { x, y -> emit(x, y, false) }) lx = x1 ly = y1 joint(false) }, cubicTo = { x0, y0, x1, y1, x2, y2 -> - val sum = Point.distance(lx, ly, x0, y0) + Point.distance(x0, y0, x1, y1) + Point.distance(x1, y1, x2, y2) + val sum = MPoint.distance(lx, ly, x0, y0) + MPoint.distance(x0, y0, x1, y1) + MPoint.distance(x1, y1, x2, y2) approximateCurve(sum.toInt(), { ratio, get -> Bezier.cubicCalc(lx, ly, x0, y0, x1, y1, x2, y2, ratio) { x, y -> get(x, y) }}, { x, y -> emit(x, y, false) }) lx = x2 @@ -470,7 +470,7 @@ fun IPointArrayList.toRectangleOrNull(): Shape2d.Rectangle? { val right = xs.maxOrNull() ?: return null val top = ys.maxOrNull() ?: return null val bottom = ys.minOrNull() ?: return null - return Shape2d.Rectangle(Rectangle.fromBounds(top, left, right, bottom)) + return Shape2d.Rectangle(MRectangle.fromBounds(top, left, right, bottom)) } fun IPointArrayList.toShape2d(closed: Boolean = true): Shape2d { @@ -480,7 +480,7 @@ fun IPointArrayList.toShape2d(closed: Boolean = true): Shape2d { val x1 = this.getX(2) val y1 = this.getY(2) if (this.getX(1) == x1 && this.getY(1) == y0 && this.getX(3) == x0 && this.getY(3) == y1) { - return Shape2d.Rectangle(Rectangle.fromBounds(x0, y0, x1, y1)) + return Shape2d.Rectangle(MRectangle.fromBounds(x0, y0, x1, y1)) } } return if (closed) Shape2d.Polygon(this) else Shape2d.Polyline(this) @@ -501,10 +501,10 @@ fun VectorPath.toShape2dOld(closed: Boolean = true): Shape2d { } @Deprecated("", ReplaceWith("toPathPointList(m, emitClosePoint)")) -fun VectorPath.toPathList(m: Matrix? = null, emitClosePoint: Boolean = false): List = +fun VectorPath.toPathList(m: MMatrix? = null, emitClosePoint: Boolean = false): List = toPathPointList(m, emitClosePoint) -fun VectorPath.toPathPointList(m: Matrix? = null, emitClosePoint: Boolean = false): List { +fun VectorPath.toPathPointList(m: MMatrix? = null, emitClosePoint: Boolean = false): List { val paths = arrayListOf() var path = PointArrayList() var firstX = 0.0 diff --git a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/shape/ops/internal/Clipper.kt b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/shape/ops/internal/Clipper.kt index ccf9f91a7b..fb5a0dba52 100644 --- a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/shape/ops/internal/Clipper.kt +++ b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/shape/ops/internal/Clipper.kt @@ -43,8 +43,8 @@ package com.soywiz.korma.geom.shape.ops.internal import com.soywiz.kds.FastArrayList import com.soywiz.korma.geom.BoundsBuilder import com.soywiz.korma.geom.IPoint -import com.soywiz.korma.geom.Point -import com.soywiz.korma.geom.Rectangle +import com.soywiz.korma.geom.MPoint +import com.soywiz.korma.geom.MRectangle import kotlin.math.PI import kotlin.math.abs import kotlin.math.acos @@ -130,7 +130,7 @@ abstract class ClipperBase protected constructor(val isPreserveCollinear: Boolea var isFlat = true //1. Basic (first) edge initialization ... - edges[1].current = Point(pg[1]) + edges[1].current = MPoint(pg[1]) rangeTest(pg[0]) rangeTest(pg[highI]) initEdge(edges[0], edges[1], edges[highI], pg[0]) @@ -458,13 +458,13 @@ abstract class ClipperBase protected constructor(val isPreserveCollinear: Boolea while (lm != null) { var e = lm.leftBound if (e != null) { - e.current = Point(e.bot) + e.current = MPoint(e.bot) e.side = Edge.Side.LEFT e.outIdx = Edge.UNASSIGNED } e = lm.rightBound if (e != null) { - e.current = Point(e.bot) + e.current = MPoint(e.bot) e.side = Edge.Side.RIGHT e.outIdx = Edge.UNASSIGNED } @@ -477,17 +477,17 @@ abstract class ClipperBase protected constructor(val isPreserveCollinear: Boolea private fun initEdge(e: Edge, eNext: Edge, ePrev: Edge, pt: IPoint) { e.next = eNext e.prev = ePrev - e.current = Point(pt) + e.current = MPoint(pt) e.outIdx = Edge.UNASSIGNED } private fun initEdge2(e: Edge, polyType: Clipper.PolyType) { if (e.current.y >= e.next!!.current.y) { - e.bot = Point(e.current) - e.top = Point(e.next!!.current) + e.bot = MPoint(e.current) + e.top = MPoint(e.next!!.current) } else { - e.top = Point(e.current) - e.bot = Point(e.next!!.current) + e.top = MPoint(e.current) + e.bot = MPoint(e.next!!.current) } e.updateDeltaX() e.polyTyp = polyType @@ -531,7 +531,7 @@ class ClipperOffset(private val miterLimit: Double = 2.0, private val arcToleran private var miterLim: Double = 0.0 private var stepsPerRad: Double = 0.0 - private var lowest = Point(-1.0, 0.0) + private var lowest = MPoint(-1.0, 0.0) private val polyNodes: PolyNode = PolyNode() @@ -575,11 +575,11 @@ class ClipperOffset(private val miterLimit: Double = 2.0, private val arcToleran return } if (lowest.x < 0) { - lowest = Point((polyNodes.childCount - 1), k) + lowest = MPoint((polyNodes.childCount - 1), k) } else { val ip = polyNodes.getChildren()[lowest.x.toInt()].polygon[lowest.y.toInt()] if (newNode.polygon[k].y > ip.y || newNode.polygon[k].y == ip.y && newNode.polygon[k].x < ip.x) { - lowest = Point((polyNodes.childCount - 1), k) + lowest = MPoint((polyNodes.childCount - 1), k) } } } @@ -1266,7 +1266,7 @@ class DefaultClipper(initOptions: Int = 0) : ClipperBase(Clipper.PRESERVE_COLINE e = sortedEdges while (e!!.nextInSEL != null) { val eNext = e.nextInSEL - val pt = Array(1) { Point() } + val pt = Array(1) { MPoint() } if (e.current.x > eNext!!.current.x) { intersectPoint(e, eNext, pt) val newNode = IntersectNode() @@ -1439,7 +1439,7 @@ class DefaultClipper(initOptions: Int = 0) : ClipperBase(Clipper.PRESERVE_COLINE while (eNext != null && eNext !== eMaxPair) { val tmp = vector2(e.top) intersectEdges(e, eNext, tmp) - e.top = Point(tmp) + e.top = MPoint(tmp) swapPositionsInAEL(e, eNext) eNext = e.nextInAEL } @@ -2055,8 +2055,8 @@ class DefaultClipper(initOptions: Int = 0) : ClipperBase(Clipper.PRESERVE_COLINE } } - private fun intersectPoint(edge1: Edge, edge2: Edge, ipV: Array) { - ipV[0] = Point() + private fun intersectPoint(edge1: Edge, edge2: Edge, ipV: Array) { + ipV[0] = MPoint() val ip = ipV[0] val b1: Double @@ -2692,7 +2692,7 @@ class DefaultClipper(initOptions: Int = 0) : ClipperBase(Clipper.PRESERVE_COLINE e.nextInLML!!.windCnt2 = e.windCnt2 e = e.nextInLML!! eV[0] = e - e.current = Point(e.bot) + e.current = MPoint(e.bot) e.prevInAEL = aelPrev e.nextInAEL = aelNext if (!e.isHorizontal) { @@ -3231,11 +3231,11 @@ class DefaultClipper(initOptions: Int = 0) : ClipperBase(Clipper.PRESERVE_COLINE class Edge { enum class Side { LEFT, RIGHT } - var bot: Point = Point(); set(v) { field.copyFrom(v) } - var current: Point = Point(); set(v) { field.copyFrom(v) } - var top: Point = Point(); set(v) { field.copyFrom(v) } + var bot: MPoint = MPoint(); set(v) { field.copyFrom(v) } + var current: MPoint = MPoint(); set(v) { field.copyFrom(v) } + var top: MPoint = MPoint(); set(v) { field.copyFrom(v) } - val delta: Point = Point() + val delta: MPoint = MPoint() var deltaX: Double = 0.0 var polyTyp: Clipper.PolyType? = null @@ -3789,7 +3789,7 @@ class Paths private constructor(private val al: FastArrayList) : MutableLi return result } - val bounds: Rectangle + val bounds: MRectangle get() { //var i = 0 //val cnt = size diff --git a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/slice/RectSlice.kt b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/slice/RectSlice.kt index 8bc847a23f..82648ebeb2 100644 --- a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/slice/RectSlice.kt +++ b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/slice/RectSlice.kt @@ -27,7 +27,7 @@ data class RectSlice( /** An orientation describing how the slice is going to be rotated and flipped */ val orientation: SliceOrientation = SliceOrientation.ROTATE_0, /** Extra empty pixels that will be considered for this slice, for tightly packed images */ - override val padding: IMarginInt = IMarginInt.ZERO, + override val padding: com.soywiz.korma.geom.IMarginInt = IMarginInt.ZERO, /** Debug [name] describing this slice */ override val name: String? = null, ) : SliceCoordsWithBaseAndRect { //, Resourceable> { @@ -94,7 +94,7 @@ data class RectSlice( } fun virtFrame(x: Int, y: Int, width: Int, height: Int): RectSlice { - return copy(padding = MarginInt(y, width - this.width - x, height - this.height - y, x)) + return copy(padding = IMarginInt(y, width - this.width - x, height - this.height - y, x)) //val rotated = orientation.isRotatedDeg90CwOrCcw //return copy(padding = when { // !rotated -> IMarginInt(y, width - this.width - x, height - this.height - y, x) diff --git a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/slice/SliceCoords.kt b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/slice/SliceCoords.kt index 4ca2bcd9a3..f6545fc86e 100644 --- a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/slice/SliceCoords.kt +++ b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/slice/SliceCoords.kt @@ -38,7 +38,7 @@ interface SliceCoordsWithBase : SliceCoords { val base: T val width: Int val height: Int - val padding: IMarginInt + val padding: com.soywiz.korma.geom.IMarginInt val sizeString: String get() = "${width}x${height}" val frameOffsetX: Int get() = padding.left @@ -87,8 +87,8 @@ data class SliceCoordsImpl( val transformedWidth: Int = if (!flippedWidthHeight) base.width else base.height val transformedHeight: Int = if (!flippedWidthHeight) base.height else base.width - override val width: Int = (Point.distance(coords.tlX, coords.tlY, coords.trX, coords.trY) * transformedWidth).toInt() - override val height: Int = (Point.distance(coords.tlX, coords.tlY, coords.blX, coords.blY) * transformedHeight).toInt() + override val width: Int = (MPoint.distance(coords.tlX, coords.tlY, coords.trX, coords.trY) * transformedWidth).toInt() + override val height: Int = (MPoint.distance(coords.tlX, coords.tlY, coords.blX, coords.blY) * transformedHeight).toInt() override fun transformed(orientation: SliceOrientation): SliceCoordsWithBase = SliceCoordsWithBase(base, (this as SliceCoords).transformed(orientation), name, flippedWidthHeight) @@ -112,14 +112,14 @@ fun SliceCoords.transformed(orientation: SliceOrientation): RectCoords { ) } -fun SliceCoords.transformed(m: Matrix): RectCoords = RectCoords( +fun SliceCoords.transformed(m: MMatrix): RectCoords = RectCoords( m.transformXf(tlX, tlY), m.transformYf(tlX, tlY), m.transformXf(trX, trY), m.transformYf(trX, trY), m.transformXf(brX, brY), m.transformYf(brX, brY), m.transformXf(blX, blY), m.transformYf(blX, blY), ) -fun SliceCoords.transformed(m: Matrix3D): RectCoords { +fun SliceCoords.transformed(m: MMatrix3D): RectCoords { // @TODO: This allocates val v1 = m.transform(tlX, tlY, 0f, 1f) val v2 = m.transform(trX, trY, 0f, 1f) @@ -130,12 +130,12 @@ fun SliceCoords.transformed(m: Matrix3D): RectCoords { // Special versions -fun SliceCoordsWithBase.transformed(m: Matrix): SliceCoordsWithBase { +fun SliceCoordsWithBase.transformed(m: MMatrix): SliceCoordsWithBase { val coords = (this as SliceCoords).transformed(m) return SliceCoordsImpl(base, coords, name) } -fun SliceCoordsWithBase.transformed(m: Matrix3D): SliceCoordsWithBase { +fun SliceCoordsWithBase.transformed(m: MMatrix3D): SliceCoordsWithBase { val coords = (this as SliceCoords).transformed(m) return SliceCoordsImpl(base, coords, name) } diff --git a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/slice/SliceOrientation.kt b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/slice/SliceOrientation.kt index 256fe6d388..1a415696a0 100644 --- a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/slice/SliceOrientation.kt +++ b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/slice/SliceOrientation.kt @@ -78,7 +78,7 @@ inline class SliceOrientation( SliceRotation.R270 -> (w1 - x) // done } } - fun getXY(width: Int, height: Int, x: Int, y: Int, out: PointInt = PointInt()): IPointInt = + fun getXY(width: Int, height: Int, x: Int, y: Int, out: MPointInt = MPointInt()): IPointInt = out.setTo(getX(width, height, x, y), getY(width, height, x, y)) object Indices { diff --git a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/trapezoid/SegmentIntToTrapezoidIntList.kt b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/trapezoid/SegmentIntToTrapezoidIntList.kt index 720ad68e2a..c76bfabb0a 100644 --- a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/trapezoid/SegmentIntToTrapezoidIntList.kt +++ b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/trapezoid/SegmentIntToTrapezoidIntList.kt @@ -1,6 +1,5 @@ package com.soywiz.korma.geom.trapezoid -import com.soywiz.kds.* import com.soywiz.kds.iterators.* import com.soywiz.kmem.* import com.soywiz.korma.geom.* @@ -291,7 +290,7 @@ object SegmentIntToTrapezoidIntList { fun VectorPath.toSegments(scale: Int = 1): FSegmentsInt { val segments = FSegmentsInt() - val p = Point() + val p = MPoint() fun emit(x0: Double, y0: Double, x1: Double, y1: Double) { //println("EMIT") segments.add((x0 * scale).toIntRound(), (y0 * scale).toIntRound(), (x1 * scale).toIntRound(), (y1 * scale).toIntRound()) diff --git a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/triangle/Edge.kt b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/triangle/Edge.kt index 728f3fd359..52b745c51d 100644 --- a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/triangle/Edge.kt +++ b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/triangle/Edge.kt @@ -1,8 +1,7 @@ package com.soywiz.korma.geom.triangle import com.soywiz.korma.geom.IPoint -import com.soywiz.korma.geom.Point -import com.soywiz.korma.geom.compare +import com.soywiz.korma.geom.MPoint data class Edge internal constructor( val dummy: Boolean, @@ -14,7 +13,7 @@ data class Edge internal constructor( companion object { operator fun invoke(p1: IPoint, p2: IPoint): Edge { - val comp = Point.compare(p1, p2) + val comp = MPoint.compare(p1, p2) if (comp == 0) throw Error("Repeat points") val p = if (comp < 0) p1 else p2 val q = if (comp < 0) p2 else p1 diff --git a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/triangle/Triangle.kt b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/triangle/Triangle.kt index 6ca2e36fce..11c209639f 100644 --- a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/triangle/Triangle.kt +++ b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/triangle/Triangle.kt @@ -2,12 +2,12 @@ package com.soywiz.korma.geom.triangle import com.soywiz.korma.geom.IPoint import com.soywiz.korma.geom.Orientation -import com.soywiz.korma.geom.Point +import com.soywiz.korma.geom.MPoint import com.soywiz.korma.geom.PointArrayList import com.soywiz.korma.geom.getPoint import kotlin.math.abs -val Triangle.center get() = Point((p0.x + p1.x + p2.x) / 3, (p0.y + p1.y + p2.y) / 3) +val Triangle.center get() = MPoint((p0.x + p1.x + p2.x) / 3, (p0.y + p1.y + p2.y) / 3) interface Triangle { val p0: IPoint @@ -221,9 +221,9 @@ class TriangleList(val points: PointArrayList, val indices: ShortArray, val numT internal val tempTriangle: MutableTriangle = MutableTriangle() class MutableTriangle : Triangle { - override val p0 = Point() - override val p1 = Point() - override val p2 = Point() + override val p0 = MPoint() + override val p1 = MPoint() + override val p2 = MPoint() override fun toString(): String = "Triangle($p0, $p1, $p2)" } diff --git a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/vector/Edge.kt b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/vector/Edge.kt index ecfbabde8a..65e28fb21c 100644 --- a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/vector/Edge.kt +++ b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/vector/Edge.kt @@ -2,9 +2,9 @@ package com.soywiz.korma.geom.vector import com.soywiz.korma.annotations.KormaExperimental import com.soywiz.korma.geom.Angle -import com.soywiz.korma.geom.Line -import com.soywiz.korma.geom.Point -import com.soywiz.korma.geom.PointInt +import com.soywiz.korma.geom.MLine +import com.soywiz.korma.geom.MPoint +import com.soywiz.korma.geom.MPointInt import com.soywiz.korma.geom.cosine import com.soywiz.korma.geom.minus import com.soywiz.korma.geom.sine @@ -22,7 +22,7 @@ class Edge { companion object { operator fun invoke(ax: Int, ay: Int, bx: Int, by: Int, wind: Int = 0) = Edge().setTo(ax, ay, bx, by, wind) - operator fun invoke(a: PointInt, b: PointInt, wind: Int = 0) = this(a.x, a.y, b.x, b.y, wind) + operator fun invoke(a: MPointInt, b: MPointInt, wind: Int = 0) = this(a.x, a.y, b.x, b.y, wind) fun getIntersectY(a: Edge, b: Edge): Int { getIntersectXY(a, b) { x, y -> return y.toInt() } @@ -36,12 +36,12 @@ class Edge { fun areParallel(a: Edge, b: Edge) = ((a.by - a.ay) * (b.ax - b.bx)) - ((b.by - b.ay) * (a.ax - a.bx)) == 0 - fun getIntersectXY(a: Edge, b: Edge, out: Point = Point()): Point? { + fun getIntersectXY(a: Edge, b: Edge, out: MPoint = MPoint()): MPoint? { getIntersectXY(a, b) { x, y -> return out.setTo(x, y) } return null } - fun getIntersectXYInt(a: Edge, b: Edge, out: PointInt = PointInt()): PointInt? { + fun getIntersectXYInt(a: Edge, b: Edge, out: MPointInt = MPointInt()): MPointInt? { getIntersectXY(a, b) { x, y -> return out.setTo(x.toInt(), y.toInt()) } return null } @@ -64,11 +64,11 @@ class Edge { } inline fun getIntersectXY(Ax: Double, Ay: Double, Bx: Double, By: Double, Cx: Double, Cy: Double, Dx: Double, Dy: Double, out: (x: Double, y: Double) -> Unit): Boolean { - return Line.getIntersectXY(Ax, Ay, Bx, By, Cx, Cy, Dx, Dy, out) + return MLine.getIntersectXY(Ax, Ay, Bx, By, Cx, Cy, Dx, Dy, out) } - fun getIntersectXY(Ax: Double, Ay: Double, Bx: Double, By: Double, Cx: Double, Cy: Double, Dx: Double, Dy: Double, out: Point = Point()): Point? { - return Line.getIntersectXY(Ax, Ay, Bx, By, Cx, Cy, Dx, Dy, out) + fun getIntersectXY(Ax: Double, Ay: Double, Bx: Double, By: Double, Cx: Double, Cy: Double, Dx: Double, Dy: Double, out: MPoint = MPoint()): MPoint? { + return MLine.getIntersectXY(Ax, Ay, Bx, By, Cx, Cy, Dx, Dy, out) } } diff --git a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/vector/PolygonScanline.kt b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/vector/PolygonScanline.kt index 3618609692..8d274e79a6 100644 --- a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/vector/PolygonScanline.kt +++ b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/vector/PolygonScanline.kt @@ -15,11 +15,11 @@ import com.soywiz.korma.annotations.KormaExperimental import com.soywiz.korma.geom.BoundsBuilder import com.soywiz.korma.geom.IPoint import com.soywiz.korma.geom.IPointInt -import com.soywiz.korma.geom.Line +import com.soywiz.korma.geom.MLine import com.soywiz.korma.geom.LineIntersection -import com.soywiz.korma.geom.Point +import com.soywiz.korma.geom.MPoint import com.soywiz.korma.geom.PointArrayList -import com.soywiz.korma.geom.Rectangle +import com.soywiz.korma.geom.MRectangle import com.soywiz.korma.geom.fastForEach import com.soywiz.korma.geom.shape.emitPoints2 import com.soywiz.korma.segment.IntSegmentSet @@ -126,7 +126,7 @@ class PolygonScanline : RastScale() { internal val allEdges = FastArrayList() private val buckets = AllBuckets() - fun getBounds(out: Rectangle = Rectangle()) = boundsBuilder.getBounds(out) + fun getBounds(out: MRectangle = MRectangle()) = boundsBuilder.getBounds(out) private var closed = true fun reset() { @@ -309,7 +309,7 @@ class PolygonScanline : RastScale() { return ss.contains(x) } - fun getAllLines(): List = allEdges.map { Line(it.ax.d, it.ay.d, it.bx.d, it.by.d) } + fun getAllLines(): List = allEdges.map { MLine(it.ax.d, it.ay.d, it.bx.d, it.by.d) } fun getLineIntersection(x0: Int, y0: Int, x1: Int, y1: Int, out: LineIntersection = LineIntersection()): LineIntersection? { // @TODO: Optimize not iterating over all the edges, but only the ones between y0 and y1 @@ -327,7 +327,7 @@ class PolygonScanline : RastScale() { out.setFrom( edge.ax.d, edge.ay.d, edge.bx.d, edge.by.d, out.intersection.x.toInt().d, out.intersection.y.toInt().d, - Point.distance(x0.d, y0.d, x1.d, y1.d) + MPoint.distance(x0.d, y0.d, x1.d, y1.d) ) return out } @@ -339,7 +339,7 @@ class PolygonScanline : RastScale() { fun getLineIntersection(x0: Double, y0: Double, x1: Double, y1: Double, out: LineIntersection = LineIntersection()) = getLineIntersection(x0.s, y0.s, x1.s, y1.s, out) fun getLineIntersection(a: IPointInt, b: IPointInt, out: LineIntersection = LineIntersection()) = getLineIntersection(a.x, a.y, b.x, b.y, out) fun getLineIntersection(a: IPoint, b: IPoint, out: LineIntersection = LineIntersection()) = getLineIntersection(a.x.s, a.y.s, b.x.s, b.y.s, out) - fun getLineIntersection(line: Line, out: LineIntersection = LineIntersection()) = getLineIntersection(line.a, line.b, out) + fun getLineIntersection(line: MLine, out: LineIntersection = LineIntersection()) = getLineIntersection(line.a, line.b, out) private class XWithWind { val x = IntArrayList(1024) diff --git a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/vector/StrokeToFill.kt b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/vector/StrokeToFill.kt index dc020477fe..da0c7e07db 100644 --- a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/vector/StrokeToFill.kt +++ b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/vector/StrokeToFill.kt @@ -5,7 +5,7 @@ import com.soywiz.kds.IntArrayList import com.soywiz.kds.iterators.fastForEach import com.soywiz.korma.annotations.KormaExperimental import com.soywiz.korma.geom.Angle -import com.soywiz.korma.geom.Point +import com.soywiz.korma.geom.MPoint import com.soywiz.korma.geom.PointIntArrayList import com.soywiz.korma.geom.bezier.Bezier import com.soywiz.korma.geom.bezier.toDashes @@ -58,12 +58,12 @@ class StrokeToFill { internal fun PointIntArrayList.addEdgePointA(e: Edge) = add(e.ax, e.ay) internal fun PointIntArrayList.addEdgePointB(e: Edge) = add(e.bx, e.by) internal fun PointIntArrayList.addEdgePointAB(e: Edge, point: EdgePoint) = if (point == EdgePoint.A) addEdgePointA(e) else addEdgePointB(e) - internal fun PointIntArrayList.add(e: Point?) { if (e != null) add(e.x.toInt(), e.y.toInt()) } + internal fun PointIntArrayList.add(e: MPoint?) { if (e != null) add(e.x.toInt(), e.y.toInt()) } internal fun PointIntArrayList.add(x: Double, y: Double) { add(x.toInt(), y.toInt()) } - private val tempP1 = Point() - private val tempP2 = Point() - private val tempP3 = Point() + private val tempP1 = MPoint() + private val tempP2 = MPoint() + private val tempP3 = MPoint() internal fun doJoin(out: PointIntArrayList, mainPrev: Edge, mainCurr: Edge, prev: Edge, curr: Edge, join: LineJoin, miterLimit: Double, scale: Double, forcedMiter: Boolean) { val rjoin = if (forcedMiter) LineJoin.MITER else join @@ -72,7 +72,7 @@ class StrokeToFill { val intersection2 = tempP1.setTo(mainPrev.bx, mainPrev.by) val intersection = Edge.getIntersectXY(prev, curr, tempP3) if (intersection != null) { - val dist = Point.distance(intersection, intersection2) + val dist = MPoint.distance(intersection, intersection2) if (forcedMiter || dist <= miterLimit) { out.add(intersection) } else { @@ -88,7 +88,7 @@ class StrokeToFill { LineJoin.ROUND -> { val i = Edge.getIntersectXY(prev, curr, tempP3) if (i != null) { - val count = (Point.distance(prev.bx, prev.by, curr.ax, curr.ay) * scale).toInt().clamp(4, 64) + val count = (MPoint.distance(prev.bx, prev.by, curr.ax, curr.ay) * scale).toInt().clamp(4, 64) for (n in 0..count) { out.add(Bezier.quadCalc(prev.bx.toDouble(), prev.by.toDouble(), i.x, i.y, curr.ax.toDouble(), curr.ay.toDouble(), n.toDouble() / count, tempP2)) } @@ -122,7 +122,7 @@ class StrokeToFill { l.add(lx2, ly2) r.add(rx2, ry2) } else { - val count = (Point.distance(lx, ly, rx, ry) * scale).toInt().clamp(4, 64) + val count = (MPoint.distance(lx, ly, rx, ry) * scale).toInt().clamp(4, 64) l.add(lx, ly) for (n in 0 .. count) { val m = if (epoint == EdgePoint.A) n else count - n diff --git a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/vector/VectorBuilder.kt b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/vector/VectorBuilder.kt index 70d45d8e81..d01d642d3a 100644 --- a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/vector/VectorBuilder.kt +++ b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/vector/VectorBuilder.kt @@ -9,9 +9,9 @@ import com.soywiz.korma.geom.IPoint import com.soywiz.korma.geom.IPointArrayList import com.soywiz.korma.geom.IRectangle import com.soywiz.korma.geom.IRectangleInt -import com.soywiz.korma.geom.Matrix +import com.soywiz.korma.geom.MMatrix import com.soywiz.korma.geom.PointArrayList -import com.soywiz.korma.geom.Rectangle +import com.soywiz.korma.geom.MRectangle import com.soywiz.korma.geom.bezier.Arc import com.soywiz.korma.geom.bezier.Bezier import com.soywiz.korma.geom.bezier.Curves @@ -181,7 +181,7 @@ internal fun VectorBuilder._regularPolygonStar(points: Int, radiusSmall: Double * \________\ * * */ -fun VectorBuilder.parallelogram(bounds: Rectangle, angle: Angle = 30.degrees, direction: Boolean = true) { +fun VectorBuilder.parallelogram(bounds: MRectangle, angle: Angle = 30.degrees, direction: Boolean = true) { val dx = angle.sine * bounds.height val dx0 = if (direction) 0.0 else dx val dx1 = if (direction) dx else 0.0 @@ -334,7 +334,7 @@ fun VectorBuilder.rLineToV(ay: Double, relative: Boolean) = if (relative) rLineT fun VectorBuilder.rLineToV(ay: Float, relative: Boolean) = if (relative) rLineToV(ay) else lineToV(ay) fun VectorBuilder.rLineToV(ay: Int, relative: Boolean) = if (relative) rLineToV(ay) else lineToV(ay) -fun VectorBuilder.transformed(m: Matrix): VectorBuilder { +fun VectorBuilder.transformed(m: MMatrix): VectorBuilder { val im = m.inverted() val parent = this return object : VectorBuilder { @@ -360,4 +360,4 @@ fun VectorBuilder.transformed(m: Matrix): VectorBuilder { } } -fun VectorBuilder.transformed(m: Matrix, block: VectorBuilder.() -> T): T = block(this.transformed(m)) +fun VectorBuilder.transformed(m: MMatrix, block: VectorBuilder.() -> T): T = block(this.transformed(m)) diff --git a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/vector/VectorPath.kt b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/vector/VectorPath.kt index 058e924c9f..73787f2e8c 100644 --- a/korma/src/commonMain/kotlin/com/soywiz/korma/geom/vector/VectorPath.kt +++ b/korma/src/commonMain/kotlin/com/soywiz/korma/geom/vector/VectorPath.kt @@ -9,12 +9,12 @@ import com.soywiz.kmem.* import com.soywiz.korma.annotations.KormaExperimental import com.soywiz.korma.geom.BoundsBuilder import com.soywiz.korma.geom.IPoint -import com.soywiz.korma.geom.Line +import com.soywiz.korma.geom.MLine import com.soywiz.korma.geom.LineIntersection -import com.soywiz.korma.geom.Matrix -import com.soywiz.korma.geom.Point +import com.soywiz.korma.geom.MMatrix +import com.soywiz.korma.geom.MPoint import com.soywiz.korma.geom.PointArrayList -import com.soywiz.korma.geom.Rectangle +import com.soywiz.korma.geom.MRectangle import com.soywiz.korma.geom.bezier.Bezier import com.soywiz.korma.geom.bezier.Curves import com.soywiz.korma.geom.bezier.toCurves @@ -26,7 +26,7 @@ import kotlin.native.concurrent.ThreadLocal // @TODO: ThreadLocal on JVM @ThreadLocal -private val tempMatrix: Matrix = Matrix() +private val tempMatrix: MMatrix = MMatrix() interface IVectorPath : VectorBuilder { fun toSvgString(): String @@ -50,11 +50,11 @@ class VectorPath( override fun hashCode(): Int = commands.hashCode() + (data.hashCode() * 13) + (winding.ordinal * 111) companion object { - private val identityMatrix = Matrix() + private val identityMatrix = MMatrix() inline operator fun invoke(winding: Winding = Winding.DEFAULT, callback: VectorPath.() -> Unit): VectorPath = VectorPath(winding = winding).apply(callback) - fun intersects(left: VectorPath, leftTransform: Matrix, right: VectorPath, rightTransform: Matrix): Boolean = + fun intersects(left: VectorPath, leftTransform: MMatrix, right: VectorPath, rightTransform: MMatrix): Boolean = left.intersectsWith(leftTransform, right, rightTransform) fun intersects(left: VectorPath, right: VectorPath): Boolean = left.intersectsWith(right) @@ -132,7 +132,7 @@ class VectorPath( } @Deprecated("Use trapezoids instead") - fun getAllLines(): List = scanline.getAllLines() + fun getAllLines(): List = scanline.getAllLines() inline fun visitEdgesSimple( line: (x0: Double, y0: Double, x1: Double, y1: Double) -> Unit, @@ -232,7 +232,7 @@ class VectorPath( val y = data[data.size - 3] val x1 = data[data.size - 2] val y1 = data[data.size - 1] - if (Point.isCollinear(x0, y0, x, y, x1, y1)) { + if (MPoint.isCollinear(x0, y0, x, y, x1, y1)) { removeLastCommand() data[data.size - 2] = x1 data[data.size - 1] = y1 @@ -269,7 +269,7 @@ class VectorPath( return true } - fun getBounds(out: Rectangle = Rectangle(), bb: BoundsBuilder = BoundsBuilder()): Rectangle { + fun getBounds(out: MRectangle = MRectangle(), bb: BoundsBuilder = BoundsBuilder()): MRectangle { bb.reset() bb.add(this) return bb.getBounds(out) @@ -297,7 +297,7 @@ class VectorPath( // I run a semi-infinite ray horizontally (increasing x, fixed y) out from the test point, and count how many edges it crosses. // At each crossing, the ray switches between inside and outside. This is called the Jordan curve theorem. fun containsPoint(x: Double, y: Double): Boolean = trapezoids.containsPoint(x, y, this.winding) - fun containsPoint(p: Point): Boolean = containsPoint(p.x, p.y, this.winding) + fun containsPoint(p: MPoint): Boolean = containsPoint(p.x, p.y, this.winding) fun containsPoint(x: Int, y: Int): Boolean = containsPoint(x.toDouble(), y.toDouble()) fun containsPoint(x: Float, y: Float): Boolean = containsPoint(x.toDouble(), y.toDouble()) @@ -334,7 +334,7 @@ class VectorPath( fun intersectsWith(right: VectorPath): Boolean = intersectsWith(identityMatrix, right, identityMatrix) // @TODO: Use trapezoids instead - fun intersectsWith(leftMatrix: Matrix, right: VectorPath, rightMatrix: Matrix): Boolean { + fun intersectsWith(leftMatrix: MMatrix, right: VectorPath, rightMatrix: MMatrix): Boolean { val left = this val leftScanline = left.scanline val rightScanline = right.scanline @@ -360,7 +360,7 @@ class VectorPath( return false } - fun getLineIntersection(line: Line, out: LineIntersection = LineIntersection()): LineIntersection? { + fun getLineIntersection(line: MLine, out: LineIntersection = LineIntersection()): LineIntersection? { // Directs from outside the shape, to inside the shape // if (this.containsPoint(line.b) && !this.containsPoint(line.a)) { return this.scanline.getLineIntersection(line, out) @@ -420,7 +420,7 @@ class VectorPath( } } - fun write(path: VectorPath, transform: Matrix = identityMatrix) { + fun write(path: VectorPath, transform: MMatrix = identityMatrix) { this.commands += path.commands if (transform.isIdentity()) { this.data += path.data @@ -457,9 +457,9 @@ class VectorPath( override fun toString(): String = "VectorPath(${toSvgString()})" @PublishedApi - internal val tempPoint = Point() + internal val tempPoint = MPoint() - inline fun transformPoints(transform: (p: Point) -> IPoint): VectorPath { + inline fun transformPoints(transform: (p: MPoint) -> IPoint): VectorPath { val point = tempPoint for (n in 0 until data.size step 2) { point.setTo(data[n + 0], data[n + 1]) @@ -528,9 +528,9 @@ fun VectorBuilder.write(path: VectorPath) { ) } -fun VectorBuilder.moveTo(x: Double, y: Double, m: Matrix?) = if (m != null) moveTo(m.transformX(x, y), m.transformY(x, y)) else moveTo(x, y) -fun VectorBuilder.lineTo(x: Double, y: Double, m: Matrix?) = if (m != null) lineTo(m.transformX(x, y), m.transformY(x, y)) else lineTo(x, y) -fun VectorBuilder.quadTo(cx: Double, cy: Double, ax: Double, ay: Double, m: Matrix?) = +fun VectorBuilder.moveTo(x: Double, y: Double, m: MMatrix?) = if (m != null) moveTo(m.transformX(x, y), m.transformY(x, y)) else moveTo(x, y) +fun VectorBuilder.lineTo(x: Double, y: Double, m: MMatrix?) = if (m != null) lineTo(m.transformX(x, y), m.transformY(x, y)) else lineTo(x, y) +fun VectorBuilder.quadTo(cx: Double, cy: Double, ax: Double, ay: Double, m: MMatrix?) = if (m != null) { quadTo( m.transformX(cx, cy), m.transformY(cx, cy), @@ -539,7 +539,7 @@ fun VectorBuilder.quadTo(cx: Double, cy: Double, ax: Double, ay: Double, m: Matr } else { quadTo(cx, cy, ax, ay) } -fun VectorBuilder.cubicTo(cx1: Double, cy1: Double, cx2: Double, cy2: Double, ax: Double, ay: Double, m: Matrix?) = +fun VectorBuilder.cubicTo(cx1: Double, cy1: Double, cx2: Double, cy2: Double, ax: Double, ay: Double, m: MMatrix?) = if (m != null) { cubicTo( m.transformX(cx1, cy1), m.transformY(cx1, cy1), @@ -551,11 +551,11 @@ fun VectorBuilder.cubicTo(cx1: Double, cy1: Double, cx2: Double, cy2: Double, ax } -fun VectorBuilder.path(path: VectorPath, m: Matrix?) { +fun VectorBuilder.path(path: VectorPath, m: MMatrix?) { write(path, m) } -fun VectorBuilder.write(path: VectorPath, m: Matrix?) { +fun VectorBuilder.write(path: VectorPath, m: MMatrix?) { path.visitCmds( moveTo = { x, y -> moveTo(x, y, m) }, lineTo = { x, y -> lineTo(x, y, m) }, @@ -565,7 +565,7 @@ fun VectorBuilder.write(path: VectorPath, m: Matrix?) { ) } -fun BoundsBuilder.add(path: VectorPath, transform: Matrix? = null) { +fun BoundsBuilder.add(path: VectorPath, transform: MMatrix? = null) { val curvesList = path.getCurvesList() if (curvesList.isEmpty() && path.isNotEmpty()) { path.visit(object : VectorPath.Visitor { @@ -583,7 +583,7 @@ fun BoundsBuilder.add(path: VectorPath, transform: Matrix? = null) { //println("BoundsBuilder.add.path: " + bb.getBounds()) } -fun VectorPath.applyTransform(m: Matrix?): VectorPath = when { +fun VectorPath.applyTransform(m: MMatrix?): VectorPath = when { m != null -> transformPoints { m.transform(it, it) } else -> this } diff --git a/korma/src/commonMain/kotlin/com/soywiz/korma/random/RandomExt.kt b/korma/src/commonMain/kotlin/com/soywiz/korma/random/RandomExt.kt index 93fdd8c1ab..f91efa376a 100644 --- a/korma/src/commonMain/kotlin/com/soywiz/korma/random/RandomExt.kt +++ b/korma/src/commonMain/kotlin/com/soywiz/korma/random/RandomExt.kt @@ -2,7 +2,7 @@ package com.soywiz.korma.random import com.soywiz.korma.geom.Angle import com.soywiz.korma.geom.IPoint -import com.soywiz.korma.geom.Rectangle +import com.soywiz.korma.geom.MRectangle import com.soywiz.korma.geom.interpolate import com.soywiz.korma.interpolation.Interpolable import com.soywiz.korma.interpolation.MutableInterpolable @@ -34,7 +34,7 @@ operator fun Random.get(range: LongRange): Long = range.start + this.nextLong() operator fun > Random.get(l: T, r: T): T = (this.nextDoubleInclusive()).interpolate(l, r) operator fun Random.get(l: Angle, r: Angle): Angle = this.nextDoubleInclusive().interpolate(l, r) operator fun Random.get(list: List): T = list[this[list.indices]] -operator fun Random.get(rectangle: Rectangle): IPoint = IPoint(this[rectangle.left, rectangle.right], this[rectangle.top, rectangle.bottom]) +operator fun Random.get(rectangle: MRectangle): IPoint = IPoint(this[rectangle.left, rectangle.right], this[rectangle.top, rectangle.bottom]) fun > T.setToRandom(min: T, max: T, random: Random = Random) { this.setToInterpolated(random.nextDouble(), min, max) } fun Random.weighted(weights: Map): T = shuffledWeighted(weights).first() diff --git a/korma/src/commonMain/kotlin/com/soywiz/korma/triangle/poly2tri/Poly2Tri.kt b/korma/src/commonMain/kotlin/com/soywiz/korma/triangle/poly2tri/Poly2Tri.kt index 0752df4593..d9288edd7e 100644 --- a/korma/src/commonMain/kotlin/com/soywiz/korma/triangle/poly2tri/Poly2Tri.kt +++ b/korma/src/commonMain/kotlin/com/soywiz/korma/triangle/poly2tri/Poly2Tri.kt @@ -53,7 +53,6 @@ import com.soywiz.kds.genericSort import com.soywiz.kds.iterators.fastForEach import com.soywiz.kds.swap import com.soywiz.korma.geom.* -import com.soywiz.korma.geom.triangle.* import kotlin.jvm.JvmName import kotlin.math.abs @@ -115,7 +114,7 @@ object Poly2Tri { * @param {!SweepContext} tcx - SweepContext object * @param {!XY} point Point */ - fun pointEvent(tcx: SweepContext, point: Point): Node { + fun pointEvent(tcx: SweepContext, point: MPoint): Node { var node = tcx.locateNode(point)!! var new_node = newFrontTriangle(tcx, point, node) @@ -146,7 +145,7 @@ object Poly2Tri { edgeEventByPoints(tcx, edge.p, edge.q, node.triangle!!, edge.q) } - fun edgeEventByPoints(tcx: SweepContext, ep: Point, eq: Point, triangle: Triangle, point: Point) { + fun edgeEventByPoints(tcx: SweepContext, ep: MPoint, eq: MPoint, triangle: Triangle, point: MPoint) { if (isEdgeSideOfTriangle(triangle, ep, eq)) { return } @@ -184,7 +183,7 @@ object Poly2Tri { } } - fun isEdgeSideOfTriangle(triangle: Triangle, ep: Point, eq: Point): Boolean { + fun isEdgeSideOfTriangle(triangle: Triangle, ep: MPoint, eq: MPoint): Boolean { var index = triangle.edgeIndex(ep, eq) if (index != -1) { triangle.markConstrainedEdgeByIndex(index) @@ -201,7 +200,7 @@ object Poly2Tri { * Creates a new front triangle and legalize it * @param {!SweepContext} tcx - SweepContext object */ - fun newFrontTriangle(tcx: SweepContext, point: Point, node: Node): Node { + fun newFrontTriangle(tcx: SweepContext, point: MPoint, node: Node): Node { var triangle = Triangle(point, node.point, node.next!!.point) triangle.markNeighbor(node.triangle!!) @@ -384,7 +383,7 @@ object Poly2Tri { * @param pd - point opposite a * @return {boolean} true if d is inside circle, false if on circle edge */ - fun inCircle(pa: Point, pb: Point, pc: Point, pd: Point): Boolean { + fun inCircle(pa: MPoint, pb: MPoint, pc: MPoint, pd: MPoint): Boolean { var adx = pa.x - pd.x var ady = pa.y - pd.y var bdx = pb.x - pd.x @@ -432,7 +431,7 @@ object Poly2Tri { * n4 n4 * */ - fun rotateTrianglePair(t: Triangle, p: Point, ot: Triangle, op: Point) { + fun rotateTrianglePair(t: Triangle, p: MPoint, ot: Triangle, op: MPoint) { val n1 = t.neighborCCW(p) val n2 = t.neighborCW(p) val n3 = ot.neighborCCW(op) @@ -717,7 +716,7 @@ object Poly2Tri { } } - fun flipEdgeEvent(tcx: SweepContext, ep: Point, eq: Point, t: Triangle, p: Point) { + fun flipEdgeEvent(tcx: SweepContext, ep: MPoint, eq: MPoint, t: Triangle, p: MPoint) { var t = t var ot = t.neighborAcross(p) ?: error("FLIP failed due to missing triangle!") @@ -774,7 +773,7 @@ object Poly2Tri { * @param op - another point shared by both triangles * @return returns the triangle still intersecting the edge */ - fun nextFlipTriangle(tcx: SweepContext, o: Orientation, t: Triangle, ot: Triangle, p: Point, op: Point): Triangle { + fun nextFlipTriangle(tcx: SweepContext, o: Orientation, t: Triangle, ot: Triangle, p: MPoint, op: MPoint): Triangle { if (o === Orientation.CCW) { // ot is not crossing edge after flip ot.delaunay_edge[ot.edgeIndex(p, op)] = true @@ -795,7 +794,7 @@ object Poly2Tri { * the point in current triangle that is the opposite point to the next * triangle. */ - fun nextFlipPoint(ep: Point, eq: Point, ot: Triangle, op: Point): Point? { + fun nextFlipPoint(ep: MPoint, eq: MPoint, ot: Triangle, op: MPoint): MPoint? { val o2d = orient2d(eq, op, ep) return when { o2d === Orientation.CW -> ot.pointCCW(op) // Right @@ -817,7 +816,7 @@ object Poly2Tri { * @param t * @param p */ - fun flipScanEdgeEvent(tcx: SweepContext, ep: Point, eq: Point, flip_triangle: Triangle, t: Triangle, p: Point) { + fun flipScanEdgeEvent(tcx: SweepContext, ep: MPoint, eq: MPoint, flip_triangle: Triangle, t: Triangle, p: MPoint) { val ot = t.neighborAcross(p) ?: error("FLIP failed due to missing triangle") val op = ot.oppositePoint(t, p) @@ -848,7 +847,7 @@ object Poly2Tri { * @param {!XY} pc point object with {x,y} * @return {Orientation} */ - fun orient2d(pa: Point, pb: Point, pc: Point): Orientation { + fun orient2d(pa: MPoint, pb: MPoint, pc: MPoint): Orientation { val detleft = (pa.x - pc.x) * (pb.y - pc.y) val detright = (pa.y - pc.y) * (pb.x - pc.x) val v = detleft - detright @@ -869,7 +868,7 @@ object Poly2Tri { * @param {!XY} pd point object with {x,y} * @return {boolean} */ - fun inScanArea(pa: Point, pb: Point, pc: Point, pd: Point): Boolean { + fun inScanArea(pa: MPoint, pb: MPoint, pc: MPoint, pd: MPoint): Boolean { val oadb = (pa.x - pb.x) * (pd.y - pb.y) - (pd.x - pb.x) * (pa.y - pb.y) if (oadb >= -POLY2TRI_EPSILON) return false @@ -887,7 +886,7 @@ object Poly2Tri { * @param {!XY} pc point object with {x,y} * @return {boolean} true if angle is obtuse */ - fun isAngleObtuse(pa: Point, pb: Point, pc: Point): Boolean { + fun isAngleObtuse(pa: MPoint, pb: MPoint, pc: MPoint): Boolean { val ax = pb.x - pa.x val ay = pb.y - pa.y val bx = pc.x - pa.x @@ -912,7 +911,7 @@ object Poly2Tri { * @param {!XY} p - Point * @param {Triangle=} t triangle (optional) */ - class Node(var point: Point, var triangle: Triangle? = null) { + class Node(var point: MPoint, var triangle: Triangle? = null) { var next: Node? = null var prev: Node? = null var value: Double = point.x @@ -961,7 +960,7 @@ object Poly2Tri { * @param {!XY} point - Point * @return {Node} */ - fun locatePoint(point: Point): Node? { + fun locatePoint(point: MPoint): Node? { val px = point.x var node: Node? = this.findSearchNode(px) val nx = node!!.point.x @@ -1018,7 +1017,7 @@ object Poly2Tri { * @param {string=} message - error message * @param {Array.=} points - invalid points */ - class PointError(message: String, points: Iterable) : Exception(message + " " + points.toList()) + class PointError(message: String, points: Iterable) : Exception(message + " " + points.toList()) enum class Orientation(val value: Int) { CW(+1), CCW(-1), COLLINEAR(0) @@ -1037,7 +1036,7 @@ object Poly2Tri { * @param {!XY} pb point object with {x,y} * @param {!XY} pc point object with {x,y} */ - class Triangle(val a: Point, val b: Point, val c: Point) : com.soywiz.korma.geom.triangle.Triangle { + class Triangle(val a: MPoint, val b: MPoint, val c: MPoint) : com.soywiz.korma.geom.triangle.Triangle { /** * Triangle points * @private @@ -1103,7 +1102,7 @@ object Poly2Tri { * @public * @returns {Point} */ - fun getPoint(index: Int): Point = this.points_[index] + fun getPoint(index: Int): MPoint = this.points_[index] /** * Get all 3 vertices of the triangle as an array @@ -1111,7 +1110,7 @@ object Poly2Tri { * @return {Array.} */ // Method added in the JavaScript version (was not present in the c++ version) - fun getPoints(): Array = this.points_ + fun getPoints(): Array = this.points_ /** * @private @@ -1129,7 +1128,7 @@ object Poly2Tri { * false otherwise. */ // Here we are comparing point references, not values - fun containsPoint(point: Point): Boolean { + fun containsPoint(point: MPoint): Boolean { var points = this.points_ return (point === points[0] || point === points[1] || point === points[2]) } @@ -1151,7 +1150,7 @@ object Poly2Tri { * @param {Point} p2 - point object with {x,y} * @return {boolean} */ - fun containsPoints(p1: Point, p2: Point): Boolean = this.containsPoint(p1) && this.containsPoint(p2) + fun containsPoints(p1: MPoint, p2: MPoint): Boolean = this.containsPoint(p1) && this.containsPoint(p2) /** * Has this triangle been marked as an interior triangle? @@ -1176,7 +1175,7 @@ object Poly2Tri { * @param {Triangle} t Triangle object. * @throws {Error} if can't find objects */ - fun markNeighborPointers(p1: Point, p2: Point, t: Triangle) { + fun markNeighborPointers(p1: MPoint, p2: MPoint, t: Triangle) { var points = this.points_ // Here we are comparing point references, not values when { @@ -1228,7 +1227,7 @@ object Poly2Tri { * @private * @param {Point} p - point object with {x,y} */ - fun pointCW(p: Point?): Point? { + fun pointCW(p: MPoint?): MPoint? { var points = this.points_ // Here we are comparing point references, not values return when { @@ -1244,7 +1243,7 @@ object Poly2Tri { * @private * @param {Point} p - point object with {x,y} */ - fun pointCCW(p: Point): Point? { + fun pointCCW(p: MPoint): MPoint? { var points = this.points_ // Here we are comparing point references, not values return when { @@ -1261,7 +1260,7 @@ object Poly2Tri { * @param {Point} p - point object with {x,y} */ // Here we are comparing point references, not values - fun neighborCW(p: Point): Triangle? = when { + fun neighborCW(p: MPoint): Triangle? = when { p === this.points_[0] -> this.neighbors_[1] p === this.points_[1] -> this.neighbors_[2] else -> this.neighbors_[0] @@ -1273,21 +1272,21 @@ object Poly2Tri { * @param {Point} p - point object with {x,y} */ // Here we are comparing point references, not values - fun neighborCCW(p: Point): Triangle? = when { + fun neighborCCW(p: MPoint): Triangle? = when { p === this.points_[0] -> this.neighbors_[2] p === this.points_[1] -> this.neighbors_[0] else -> this.neighbors_[1] } // Here we are comparing point references, not values - fun getConstrainedEdgeCW(p: Point): Boolean = when { + fun getConstrainedEdgeCW(p: MPoint): Boolean = when { p === this.points_[0] -> this.constrained_edge[1] p === this.points_[1] -> this.constrained_edge[2] else -> this.constrained_edge[0] } // Here we are comparing point references, not values - fun getConstrainedEdgeCCW(p: Point): Boolean = when { + fun getConstrainedEdgeCCW(p: MPoint): Boolean = when { p === this.points_[0] -> this.constrained_edge[2] p === this.points_[1] -> this.constrained_edge[0] else -> this.constrained_edge[1] @@ -1295,49 +1294,49 @@ object Poly2Tri { // Additional check from Java version (see issue #88) // Here we are comparing point references, not values - fun getConstrainedEdgeAcross(p: Point): Boolean = when { + fun getConstrainedEdgeAcross(p: MPoint): Boolean = when { p === this.points_[0] -> this.constrained_edge[0] p === this.points_[1] -> this.constrained_edge[1] else -> this.constrained_edge[2] } // Here we are comparing point references, not values - fun setConstrainedEdgeCW(p: Point, ce: Boolean) = when { + fun setConstrainedEdgeCW(p: MPoint, ce: Boolean) = when { p === this.points_[0] -> this.constrained_edge[1] = ce p === this.points_[1] -> this.constrained_edge[2] = ce else -> this.constrained_edge[0] = ce } // Here we are comparing point references, not values - fun setConstrainedEdgeCCW(p: Point, ce: Boolean) = when { + fun setConstrainedEdgeCCW(p: MPoint, ce: Boolean) = when { p === this.points_[0] -> this.constrained_edge[2] = ce p === this.points_[1] -> this.constrained_edge[0] = ce else -> this.constrained_edge[1] = ce } // Here we are comparing point references, not values - fun getDelaunayEdgeCW(p: Point): Boolean = when { + fun getDelaunayEdgeCW(p: MPoint): Boolean = when { p === this.points_[0] -> this.delaunay_edge[1] p === this.points_[1] -> this.delaunay_edge[2] else -> this.delaunay_edge[0] } // Here we are comparing point references, not values - fun getDelaunayEdgeCCW(p: Point): Boolean = when { + fun getDelaunayEdgeCCW(p: MPoint): Boolean = when { p === this.points_[0] -> this.delaunay_edge[2] p === this.points_[1] -> this.delaunay_edge[0] else -> this.delaunay_edge[1] } // Here we are comparing point references, not values - fun setDelaunayEdgeCW(p: Point, e: Boolean) = when { + fun setDelaunayEdgeCW(p: MPoint, e: Boolean) = when { p === this.points_[0] -> this.delaunay_edge[1] = e p === this.points_[1] -> this.delaunay_edge[2] = e else -> this.delaunay_edge[0] = e } // Here we are comparing point references, not values - fun setDelaunayEdgeCCW(p: Point, e: Boolean) = when { + fun setDelaunayEdgeCCW(p: MPoint, e: Boolean) = when { p === this.points_[0] -> this.delaunay_edge[2] = e p === this.points_[1] -> this.delaunay_edge[0] = e else -> this.delaunay_edge[1] = e @@ -1350,7 +1349,7 @@ object Poly2Tri { * @returns {Triangle} */ // Here we are comparing point references, not values - fun neighborAcross(p: Point): Triangle? = when { + fun neighborAcross(p: MPoint): Triangle? = when { p === this.points_[0] -> this.neighbors_[0] p === this.points_[1] -> this.neighbors_[1] else -> this.neighbors_[2] @@ -1361,7 +1360,7 @@ object Poly2Tri { * @param {!Triangle} t Triangle object. * @param {Point} p - point object with {x,y} */ - fun oppositePoint(t: Triangle, p: Point): Point? = this.pointCW(t.pointCW(p)) + fun oppositePoint(t: Triangle, p: MPoint): MPoint? = this.pointCW(t.pointCW(p)) /** * Legalize triangle by rotating clockwise around oPoint @@ -1370,7 +1369,7 @@ object Poly2Tri { * @param {Point} npoint - point object with {x,y} * @throws {Error} if oPoint can not be found */ - fun legalize(opoint: Point, npoint: Point) { + fun legalize(opoint: MPoint, npoint: MPoint) { var points = this.points_ // Here we are comparing point references, not values when { @@ -1403,7 +1402,7 @@ object Poly2Tri { * @returns {number} index 0, 1 or 2 * @throws {Error} if p can not be found */ - fun index(p: Point): Int { + fun index(p: MPoint): Int { var points = this.points_ // Here we are comparing point references, not values return when { @@ -1420,7 +1419,7 @@ object Poly2Tri { * @param {Point} p2 - point object with {x,y} * @return {number} index 0, 1 or 2, or -1 if errror */ - fun edgeIndex(p1: Point, p2: Point): Int { + fun edgeIndex(p1: MPoint, p2: MPoint): Int { var points = this.points_ // Here we are comparing point references, not values if (p1 === points[0]) { @@ -1470,7 +1469,7 @@ object Poly2Tri { * @param {Point} p - point object with {x,y} * @param {Point} q - point object with {x,y} */ - fun markConstrainedEdgeByPoints(p: Point, q: Point) { + fun markConstrainedEdgeByPoints(p: MPoint, q: MPoint) { val points = this.points_ // Here we are comparing point references, not values when { @@ -1490,10 +1489,10 @@ object Poly2Tri { * @param {Point} p2 * @throw {PointError} if p1 is same as p2 */ - class Edge constructor(p1: Point, p2: Point) { + class Edge constructor(p1: MPoint, p2: MPoint) { - var p: Point = p1 - var q: Point = p2 + var p: MPoint = p1 + var q: MPoint = p2 init { if (p1.y > p2.y) { @@ -1597,14 +1596,14 @@ object Poly2Tri { val triangles_ = FastArrayList() var map_ = FastArrayList() - var points_ = FastArrayList() + var points_ = FastArrayList() val _p2t_edge_lists = FastArrayList?>() var edge_list = FastArrayList() // Bounding box of all points. Computed at the start of the triangulation, // it is stored in case it is needed by the caller. - var pbounds: Rectangle = Rectangle() + var pbounds: MRectangle = MRectangle() //var pmin_: Point? = null //var pmax_: Point? = null @@ -1620,14 +1619,14 @@ object Poly2Tri { * @private * @type {Point} */ - var head_: Point? = null + var head_: MPoint? = null /** * tail point used with advancing front * @private * @type {Point} */ - var tail_: Point? = null + var tail_: MPoint? = null /** * @private @@ -1666,7 +1665,7 @@ object Poly2Tri { * @public * @param {Array.} polyline - array of "Point like" objects with {x,y} */ - fun addHole(polyline: List) { + fun addHole(polyline: List) { var len = polyline.size val points = this.points_ val start = points.size @@ -1695,7 +1694,7 @@ object Poly2Tri { @JvmName("addHolesListIPointArrayList") fun addHoles(polyline: List) { - for (p in polyline) addHole(p.map { x, y -> Point(x, y) }) + for (p in polyline) addHole(p.map { x, y -> MPoint(x, y) }) } @@ -1719,7 +1718,7 @@ object Poly2Tri { * @param {Array.>} holes - array of array of "Point like" objects with {x,y} */ // Method added in the JavaScript version (was not present in the c++ version) - fun addHoles(holes: List>) { + fun addHoles(holes: List>) { holes.fastForEach { addHole(it) } } @@ -1736,7 +1735,7 @@ object Poly2Tri { * @public * @param {Point} point - any "Point like" object with {x,y} */ - fun addPoint(point: Point) { + fun addPoint(point: MPoint) { this.points_.add(point) } @@ -1757,8 +1756,8 @@ object Poly2Tri { * @param {Array.} points - array of "Point like" object with {x,y} */ // Method added in the JavaScript version (was not present in the c++ version) - fun addPoints(points: List) { - points.fastForEach { this.points_.add(Point(it.x, it.y)) } + fun addPoints(points: List) { + points.fastForEach { this.points_.add(MPoint(it.x, it.y)) } } @@ -1786,7 +1785,7 @@ object Poly2Tri { * @returns {{min:Point,max:Point}} object with 'min' and 'max' Point */ // Method added in the JavaScript version (was not present in the c++ version) - fun getBoundingBox(): Rectangle { + fun getBoundingBox(): MRectangle { return pbounds } @@ -1844,8 +1843,8 @@ object Poly2Tri { var dx = kAlpha * (xmax - xmin) var dy = kAlpha * (ymax - ymin) - this.head_ = Point(xmax + dx, ymin - dy) - this.tail_ = Point(xmin - dx, ymin - dy) + this.head_ = MPoint(xmax + dx, ymin - dy) + this.tail_ = MPoint(xmin - dx, ymin - dy) // Sort points along y-axis genericSort(this, 0, this.points_.size - 1, object : SortOps() { @@ -1861,7 +1860,7 @@ object Poly2Tri { } /** @private */ - fun getPoint(index: Int): Point { + fun getPoint(index: Int): MPoint { return this.points_[index] } @@ -1871,7 +1870,7 @@ object Poly2Tri { } /** @private */ - fun locateNode(point: Point): Node? { + fun locateNode(point: MPoint): Node? { return this.front_!!.locateNode(point.x) } diff --git a/korma/src/commonTest/kotlin/com/soywiz/korma/algo/AStarTest.kt b/korma/src/commonTest/kotlin/com/soywiz/korma/algo/AStarTest.kt index abd76d1422..4f374aa24c 100644 --- a/korma/src/commonTest/kotlin/com/soywiz/korma/algo/AStarTest.kt +++ b/korma/src/commonTest/kotlin/com/soywiz/korma/algo/AStarTest.kt @@ -3,7 +3,7 @@ package com.soywiz.korma.algo import com.soywiz.kds.BooleanArray2 import com.soywiz.kds.map2 import com.soywiz.korma.geom.IPointInt -import com.soywiz.korma.geom.PointInt +import com.soywiz.korma.geom.MPointInt import com.soywiz.korma.geom.toPoints import kotlin.test.Test import kotlin.test.assertEquals @@ -70,18 +70,18 @@ class AStarTest { data class Result(val map: BooleanArray2, val start: IPointInt, val end: IPointInt) fun map(str: String): Result { - var start = PointInt(0, 0) - var end = PointInt(0, 0) + var start = MPointInt(0, 0) + var end = MPointInt(0, 0) val map = BooleanArray2(str) arr@{ c, x, y -> //println("$x, $y, $c") if (c == '.') return@arr false if (c == '*' || c == '#') return@arr true if (c == 'S') { - start = PointInt(x, y) + start = MPointInt(x, y) return@arr false } if (c == 'E') { - end = PointInt(x, y) + end = MPointInt(x, y) return@arr false } return@arr false @@ -109,7 +109,7 @@ class AStarTest { val pointsMap = points.toPoints().withIndex().map { it.value to it.index }.toMap() val res = input2.map.map2 { x, y, c -> //pointsMap[PointInt(x, y)]?.let { xdigits[it] } ?: (if (c) '#' else '.') // @TODO: Kotlin-native: Regression Crashes BUG in runtime - https://github.com/JetBrains/kotlin-native/issues/1736 - (pointsMap[PointInt(x, y)]?.let { "" + xdigits[it] } ?: (if (c) "#" else ".")).first() + (pointsMap[MPointInt(x, y)]?.let { "" + xdigits[it] } ?: (if (c) "#" else ".")).first() } val output = res.asString { it } assertEquals(expected.trimIndent(), output) diff --git a/korma/src/commonTest/kotlin/com/soywiz/korma/geom/AnchorTest.kt b/korma/src/commonTest/kotlin/com/soywiz/korma/geom/AnchorTest.kt index 34ad64ecbd..43ffa82e5b 100644 --- a/korma/src/commonTest/kotlin/com/soywiz/korma/geom/AnchorTest.kt +++ b/korma/src/commonTest/kotlin/com/soywiz/korma/geom/AnchorTest.kt @@ -4,21 +4,21 @@ import com.soywiz.korma.interpolation.interpolate import kotlin.test.* class AnchorTest { - val rect = Rectangle(0, 0, 100, 100) + val rect = MRectangle(0, 0, 100, 100) @Test fun test() { - assertEquals(Point(0, 0), rect.getAnchoredPosition(Anchor.TOP_LEFT)) - assertEquals(Point(50, 0), rect.getAnchoredPosition(Anchor.TOP_CENTER)) - assertEquals(Point(100, 0), rect.getAnchoredPosition(Anchor.TOP_RIGHT)) + assertEquals(MPoint(0, 0), rect.getAnchoredPosition(Anchor.TOP_LEFT)) + assertEquals(MPoint(50, 0), rect.getAnchoredPosition(Anchor.TOP_CENTER)) + assertEquals(MPoint(100, 0), rect.getAnchoredPosition(Anchor.TOP_RIGHT)) - assertEquals(Point(0, 50), rect.getAnchoredPosition(Anchor.MIDDLE_LEFT)) - assertEquals(Point(50, 50), rect.getAnchoredPosition(Anchor.MIDDLE_CENTER)) - assertEquals(Point(100, 50), rect.getAnchoredPosition(Anchor.MIDDLE_RIGHT)) + assertEquals(MPoint(0, 50), rect.getAnchoredPosition(Anchor.MIDDLE_LEFT)) + assertEquals(MPoint(50, 50), rect.getAnchoredPosition(Anchor.MIDDLE_CENTER)) + assertEquals(MPoint(100, 50), rect.getAnchoredPosition(Anchor.MIDDLE_RIGHT)) - assertEquals(Point(0, 100), rect.getAnchoredPosition(Anchor.BOTTOM_LEFT)) - assertEquals(Point(50, 100), rect.getAnchoredPosition(Anchor.BOTTOM_CENTER)) - assertEquals(Point(100, 100), rect.getAnchoredPosition(Anchor.BOTTOM_RIGHT)) + assertEquals(MPoint(0, 100), rect.getAnchoredPosition(Anchor.BOTTOM_LEFT)) + assertEquals(MPoint(50, 100), rect.getAnchoredPosition(Anchor.BOTTOM_CENTER)) + assertEquals(MPoint(100, 100), rect.getAnchoredPosition(Anchor.BOTTOM_RIGHT)) assertEquals(Anchor.TOP_LEFT, 0.0.interpolate(Anchor.TOP_LEFT, Anchor.BOTTOM_RIGHT)) assertEquals(Anchor.MIDDLE_CENTER, 0.5.interpolate(Anchor.TOP_LEFT, Anchor.BOTTOM_RIGHT)) diff --git a/korma/src/commonTest/kotlin/com/soywiz/korma/geom/AngleTest.kt b/korma/src/commonTest/kotlin/com/soywiz/korma/geom/AngleTest.kt index d9b36846f0..2a1ec5ae56 100644 --- a/korma/src/commonTest/kotlin/com/soywiz/korma/geom/AngleTest.kt +++ b/korma/src/commonTest/kotlin/com/soywiz/korma/geom/AngleTest.kt @@ -55,10 +55,10 @@ class AngleTest { @Test fun between() { - assertEquals(0.degrees, Angle.between(Point(0, 0), Point(10, 0))) - assertEquals(90.degrees, Angle.between(Point(0, 0), Point(0, 10))) - assertEquals(180.degrees, Angle.between(Point(0, 0), Point(-10, 0))) - assertEquals(270.degrees, Angle.between(Point(0, 0), Point(0, -10))) + assertEquals(0.degrees, Angle.between(MPoint(0, 0), MPoint(10, 0))) + assertEquals(90.degrees, Angle.between(MPoint(0, 0), MPoint(0, 10))) + assertEquals(180.degrees, Angle.between(MPoint(0, 0), MPoint(-10, 0))) + assertEquals(270.degrees, Angle.between(MPoint(0, 0), MPoint(0, -10))) assertEquals(0.degrees, Angle.between(100, 100, 110, 100)) assertEquals(90.degrees, Angle.between(100, 100, 100, 110)) diff --git a/korma/src/commonTest/kotlin/com/soywiz/korma/geom/BoundsBuilderTest.kt b/korma/src/commonTest/kotlin/com/soywiz/korma/geom/BoundsBuilderTest.kt index 3df4fc8000..ba292a0276 100644 --- a/korma/src/commonTest/kotlin/com/soywiz/korma/geom/BoundsBuilderTest.kt +++ b/korma/src/commonTest/kotlin/com/soywiz/korma/geom/BoundsBuilderTest.kt @@ -8,14 +8,14 @@ class BoundsBuilderTest { @Test fun name() { val bb = BoundsBuilder() - bb.add(Rectangle(20, 10, 200, 300)) - bb.add(Rectangle(2000, 70, 400, 50)) - bb.add(Rectangle(10000, 10000, 0, 0)) + bb.add(MRectangle(20, 10, 200, 300)) + bb.add(MRectangle(2000, 70, 400, 50)) + bb.add(MRectangle(10000, 10000, 0, 0)) assertEquals("Rectangle(x=20, y=10, width=2380, height=300)", bb.getBounds().toString()) bb.reset() assertEquals("null", bb.getBoundsOrNull().toString()) assertEquals("Rectangle(x=0, y=0, width=0, height=0)", bb.getBounds().toString()) - bb.add(Rectangle.fromBounds(0, 0, 1, 1)) + bb.add(MRectangle.fromBounds(0, 0, 1, 1)) assertEquals("Rectangle(x=0, y=0, width=1, height=1)", bb.getBoundsOrNull().toString()) assertEquals("Rectangle(x=0, y=0, width=1, height=1)", bb.getBounds().toString()) } @@ -28,7 +28,7 @@ class BoundsBuilderTest { .add(-100, 110) .add(-90, 110) - assertEquals(Rectangle(-100, 100, 10, 10), bb.getBounds()) + assertEquals(MRectangle(-100, 100, 10, 10), bb.getBounds()) } fun BoundsBuilder.toPropsString(): String { diff --git a/korma/src/commonTest/kotlin/com/soywiz/korma/geom/CircleTest.kt b/korma/src/commonTest/kotlin/com/soywiz/korma/geom/CircleTest.kt index 4444dd6f6a..4d1d41ff8d 100644 --- a/korma/src/commonTest/kotlin/com/soywiz/korma/geom/CircleTest.kt +++ b/korma/src/commonTest/kotlin/com/soywiz/korma/geom/CircleTest.kt @@ -5,18 +5,18 @@ import kotlin.test.Test class CircleTest { @Test fun testProjectedPoint() { - val circle = Circle(Point(100, 100), radius = 100.0) + val circle = Circle(MPoint(100, 100), radius = 100.0) // Simple inner positions - assertEquals(Point(200, 100), circle.projectedPoint(Point(110, 100))) - assertEquals(Point(0, 100), circle.projectedPoint(Point(90, 100))) - assertEquals(Point(100, 0), circle.projectedPoint(Point(100, 90))) - assertEquals(Point(100, 200), circle.projectedPoint(Point(100, 110))) + assertEquals(MPoint(200, 100), circle.projectedPoint(MPoint(110, 100))) + assertEquals(MPoint(0, 100), circle.projectedPoint(MPoint(90, 100))) + assertEquals(MPoint(100, 0), circle.projectedPoint(MPoint(100, 90))) + assertEquals(MPoint(100, 200), circle.projectedPoint(MPoint(100, 110))) // Simple outer positions - assertEquals(Point(100, 200), circle.projectedPoint(Point(100, 500))) + assertEquals(MPoint(100, 200), circle.projectedPoint(MPoint(100, 500))) // @TODO: What to do here? - assertEquals(Point(200, 100), circle.projectedPoint(Point(100, 100))) // Arbitrary angle + assertEquals(MPoint(200, 100), circle.projectedPoint(MPoint(100, 100))) // Arbitrary angle //assertEquals(Point(100, 100), circle.projectedPoint(Point(100, 100))) // Uses center as point } } diff --git a/korma/src/commonTest/kotlin/com/soywiz/korma/geom/IntegrationShapeTest.kt b/korma/src/commonTest/kotlin/com/soywiz/korma/geom/IntegrationShapeTest.kt index 4151862ed0..9bdc382fc7 100644 --- a/korma/src/commonTest/kotlin/com/soywiz/korma/geom/IntegrationShapeTest.kt +++ b/korma/src/commonTest/kotlin/com/soywiz/korma/geom/IntegrationShapeTest.kt @@ -28,7 +28,7 @@ class IntegrationShapeTest { @Test fun triangulate() { - val shape = Rectangle(0, 0, 100, 100).toShape() + val shape = MRectangle(0, 0, 100, 100).toShape() //println(shape) //println(shape.getAllPoints()) //println(shape.getAllPoints().toPoints()) @@ -42,11 +42,11 @@ class IntegrationShapeTest { fun pathFind() { assertEquals( "[(10, 10), (90, 90)]", - Rectangle(0, 0, 100, 100).toShape().pathFind(IPoint(10, 10), IPoint(90, 90)).toString() + MRectangle(0, 0, 100, 100).toShape().pathFind(IPoint(10, 10), IPoint(90, 90)).toString() ) assertEquals( "[(10, 10), (100, 50), (120, 52)]", - (Rectangle(0, 0, 100, 100).toShape() + Rectangle(100, 50, 50, 50).toShape()).pathFind( + (MRectangle(0, 0, 100, 100).toShape() + MRectangle(100, 50, 50, 50).toShape()).pathFind( IPoint(10, 10), IPoint(120, 52) ).toString() diff --git a/korma/src/commonTest/kotlin/com/soywiz/korma/geom/LineTest.kt b/korma/src/commonTest/kotlin/com/soywiz/korma/geom/LineTest.kt index 2aac7d2362..ff2f46ce09 100644 --- a/korma/src/commonTest/kotlin/com/soywiz/korma/geom/LineTest.kt +++ b/korma/src/commonTest/kotlin/com/soywiz/korma/geom/LineTest.kt @@ -7,31 +7,31 @@ class LineTest { @Test fun testIntersecting() { - val line1 = Line(Point(284, 158), Point(246, 158)) - val line2 = Line(Point(303.89273932825165, 198.88732201874024), Point(257.05152496464524, 155.2765362319343)) + val line1 = MLine(MPoint(284, 158), MPoint(246, 158)) + val line2 = MLine(MPoint(303.89273932825165, 198.88732201874024), MPoint(257.05152496464524, 155.2765362319343)) assertEquals(true, line1.intersectsSegment(line2)) assertEquals(38.0, line1.length) assertEquals(64.0, line2.length, absoluteTolerance = tolerance) assertEquals(180.0, line1.angle.degrees, absoluteTolerance = tolerance) assertEquals(222.95459151111274, line2.angle.degrees, absoluteTolerance = tolerance) - assertEquals(Point(260.0, 158.0), line1.getSegmentIntersectionPoint(line2)?.round()) + assertEquals(MPoint(260.0, 158.0), line1.getSegmentIntersectionPoint(line2)?.round()) } @Test fun testProjectedPoint() { - assertEquals(Point(0, 50), Line(Point(0, 0), Point(0, 100)).projectedPoint(Point(50, 50))) - assertEquals(Point(50, 50), Line(Point(0, 0), Point(100, 100)).projectedPoint(Point(100, 0))) + assertEquals(MPoint(0, 50), MLine(MPoint(0, 0), MPoint(0, 100)).projectedPoint(MPoint(50, 50))) + assertEquals(MPoint(50, 50), MLine(MPoint(0, 0), MPoint(100, 100)).projectedPoint(MPoint(100, 0))) // On line - assertEquals(Point(0, 0), Line(Point(0, 0), Point(0, 100)).projectedPoint(Point(0, 0))) - assertEquals(Point(0, 50), Line(Point(0, 0), Point(0, 100)).projectedPoint(Point(0, 50))) - assertEquals(Point(0, 100), Line(Point(0, 0), Point(0, 100)).projectedPoint(Point(0, 100))) - assertEquals(Point(0, 150), Line(Point(0, 0), Point(0, 100)).projectedPoint(Point(0, 150))) + assertEquals(MPoint(0, 0), MLine(MPoint(0, 0), MPoint(0, 100)).projectedPoint(MPoint(0, 0))) + assertEquals(MPoint(0, 50), MLine(MPoint(0, 0), MPoint(0, 100)).projectedPoint(MPoint(0, 50))) + assertEquals(MPoint(0, 100), MLine(MPoint(0, 0), MPoint(0, 100)).projectedPoint(MPoint(0, 100))) + assertEquals(MPoint(0, 150), MLine(MPoint(0, 0), MPoint(0, 100)).projectedPoint(MPoint(0, 150))) } @Test fun testLineData() { - val gen = { Line(Point(0, 0), Point(100, 100)) } + val gen = { MLine(MPoint(0, 0), MPoint(100, 100)) } assertEquals(gen(), gen()) assertEquals(gen().hashCode(), gen().hashCode()) } diff --git a/korma/src/commonTest/kotlin/com/soywiz/korma/geom/Matrix3DTest.kt b/korma/src/commonTest/kotlin/com/soywiz/korma/geom/Matrix3DTest.kt index 89ea498447..003d8ecea1 100644 --- a/korma/src/commonTest/kotlin/com/soywiz/korma/geom/Matrix3DTest.kt +++ b/korma/src/commonTest/kotlin/com/soywiz/korma/geom/Matrix3DTest.kt @@ -7,7 +7,7 @@ import kotlin.test.* class Matrix3DTest { @Test fun testToString() { - val mat = Matrix3D.fromRows( + val mat = MMatrix3D.fromRows( 1f, 2f, 3f, 4f, 5f, 6f, 7f, 8f, 9f, 10f, 11f, 12f, @@ -28,20 +28,20 @@ class Matrix3DTest { @Test fun testMultiply() { - val l = Matrix3D.fromRows( + val l = MMatrix3D.fromRows( 1f, 2f, 3f, 4f, 5f, 6f, 7f, 8f, 9f, 10f, 11f, 12f, 13f, 14f, 15f, 16f ) - val r = Matrix3D.fromRows( + val r = MMatrix3D.fromRows( 17f, 18f, 19f, 20f, 21f, 22f, 23f, 24f, 25f, 26f, 27f, 28f, 29f, 30f, 31f, 32f ) assertEquals( - Matrix3D.fromRows( + MMatrix3D.fromRows( 250f, 260f, 270f, 280f, 618f, 644f, 670f, 696f, 986f, 1028f, 1070f, 1112f, @@ -54,7 +54,7 @@ class Matrix3DTest { @Test fun testMatrix4() { - val matrix = Matrix3D() + val matrix = MMatrix3D() val identityData = listOf( 1, 0, 0, 0, 0, 1, 0, 0, @@ -68,7 +68,7 @@ class Matrix3DTest { @Test fun test2() { - val mat = Matrix3D.fromRows( + val mat = MMatrix3D.fromRows( 1f, 2f, 3f, 11f, 4f, 5f, 6f, 12f, 7f, 8f, 9f, 13f, @@ -97,55 +97,55 @@ class Matrix3DTest { @Test fun test3() { run { - val mat = Matrix(2, 0, 0, 2, 20, 20) + val mat = MMatrix(2, 0, 0, 2, 20, 20) val mat4 = mat.toMatrix3D() - assertEquals(Point(40, 40), mat.transform(Point(10, 10))) - assertEquals(Vector3D(40, 40, 0), mat4.transform(Vector3D(10f, 10f, 0f))) + assertEquals(MPoint(40, 40), mat.transform(MPoint(10, 10))) + assertEquals(MVector4(40, 40, 0), mat4.transform(MVector4(10f, 10f, 0f))) } run { - val mat = Matrix(1, 2, 3, 4, 5, 6) + val mat = MMatrix(1, 2, 3, 4, 5, 6) val mat4 = mat.toMatrix3D() - assertEquals(Point(45, 66), mat.transform(Point(10, 10))) - assertEquals(Vector3D(45, 66, 0), mat4.transform(Vector3D(10f, 10f, 0f))) + assertEquals(MPoint(45, 66), mat.transform(MPoint(10, 10))) + assertEquals(MVector4(45, 66, 0), mat4.transform(MVector4(10f, 10f, 0f))) } } @Test fun ortho() { run { - val projection = Matrix3D().setToOrtho(0f, 200f, 100f, 0f, 0f, -20f) - assertEquals(Vector3D(0, 0, -1), Vector3D(100f, 50f, 0f).transform(projection)) - assertEquals(Vector3D(0, 0, +1), Vector3D(100f, 50f, 20f).transform(projection)) + val projection = MMatrix3D().setToOrtho(0f, 200f, 100f, 0f, 0f, -20f) + assertEquals(MVector4(0, 0, -1), MVector4(100f, 50f, 0f).transform(projection)) + assertEquals(MVector4(0, 0, +1), MVector4(100f, 50f, 20f).transform(projection)) } run { - val projection = Matrix3D().setToOrtho(0f, 200f, 100f, 0f, 0f, +20f) - assertEquals(Vector3D(0, 0, -1), Vector3D(100f, 50f, 0f).transform(projection)) - assertEquals(Vector3D(0, 0, +1), Vector3D(100f, 50f, -20f).transform(projection)) + val projection = MMatrix3D().setToOrtho(0f, 200f, 100f, 0f, 0f, +20f) + assertEquals(MVector4(0, 0, -1), MVector4(100f, 50f, 0f).transform(projection)) + assertEquals(MVector4(0, 0, +1), MVector4(100f, 50f, -20f).transform(projection)) } run { - val projection = Matrix3D().setToOrtho(Rectangle(0, 0, 200, 100), 0f, +20f) - assertEquals(Vector3D(0, 0, -1), Vector3D(100f, 50f, 0f).transform(projection)) - assertEquals(Vector3D(0, 0, +1), Vector3D(100f, 50f, -20f).transform(projection)) + val projection = MMatrix3D().setToOrtho(MRectangle(0, 0, 200, 100), 0f, +20f) + assertEquals(MVector4(0, 0, -1), MVector4(100f, 50f, 0f).transform(projection)) + assertEquals(MVector4(0, 0, +1), MVector4(100f, 50f, -20f).transform(projection)) } } @Test fun translation() { - assertEquals(Vector3D(11f, 22f, 33f), Vector3D(10f, 20f, 30f).transform(Matrix3D().setToTranslation(1f, 2f, 3f))) + assertEquals(MVector4(11f, 22f, 33f), MVector4(10f, 20f, 30f).transform(MMatrix3D().setToTranslation(1f, 2f, 3f))) } @Test fun scale() { - assertEquals(Vector3D(100f, 400f, 900f), Vector3D(10f, 20f, 30f).transform(Matrix3D().setToScale(10f, 20f, 30f))) + assertEquals(MVector4(100f, 400f, 900f), MVector4(10f, 20f, 30f).transform(MMatrix3D().setToScale(10f, 20f, 30f))) } @Test fun rotation() { - assertEquals(Vector3D(0, 10, 0), Vector3D(10, 0, 0).transform(Matrix3D().setToRotationZ(90.degrees))) - assertEquals(Vector3D(-10, 0, 0), Vector3D(10, 0, 0).transform(Matrix3D().setToRotationZ(180.degrees))) - assertEquals(Vector3D(0, 10, 0), Vector3D(10, 0, 0).transform(Matrix3D().setToRotation(90.degrees, Vector3D(0, 0, 1)))) + assertEquals(MVector4(0, 10, 0), MVector4(10, 0, 0).transform(MMatrix3D().setToRotationZ(90.degrees))) + assertEquals(MVector4(-10, 0, 0), MVector4(10, 0, 0).transform(MMatrix3D().setToRotationZ(180.degrees))) + assertEquals(MVector4(0, 10, 0), MVector4(10, 0, 0).transform(MMatrix3D().setToRotation(90.degrees, MVector4(0, 0, 1)))) } - val transMat = Matrix3D.fromRows( + val transMat = MMatrix3D.fromRows( 1f, 0f, 0f, 1f, 0f, 1f, 0f, 2f, 0f, 0f, 1f, 3f, @@ -155,18 +155,18 @@ class Matrix3DTest { @Test fun testSetTRS() { assertEquals( - Matrix3D(), - Matrix3D().setTRS( + MMatrix3D(), + MMatrix3D().setTRS( Position3D(0, 0, 0), - Quaternion(), + MQuaternion(), Scale3D(1, 1, 1) ) ) assertEquals( transMat, - Matrix3D().setTRS( + MMatrix3D().setTRS( Position3D(1, 2, 3), - Quaternion(), + MQuaternion(), Scale3D(1, 1, 1) ) ) @@ -175,7 +175,7 @@ class Matrix3DTest { @Test fun testGetTRS() { val pos = Position3D() - val quat = Quaternion() + val quat = MQuaternion() val scale = Scale3D() transMat.getTRS(pos, quat, scale) @@ -184,13 +184,13 @@ class Matrix3DTest { @Test fun testSetGetTRS() { - val mat = Matrix3D() + val mat = MMatrix3D() val opos = Position3D(1, 2, 3) - val oquat = Quaternion().setEuler(15.degrees, 30.degrees, 60.degrees) + val oquat = MQuaternion().setEuler(15.degrees, 30.degrees, 60.degrees) val oscale = Scale3D(1, 2, 3) val pos = Position3D().copyFrom(opos) - val quat = Quaternion().copyFrom(oquat) + val quat = MQuaternion().copyFrom(oquat) val scale = Scale3D().copyFrom(oscale) mat.setTRS(pos, quat, scale) @@ -203,26 +203,26 @@ class Matrix3DTest { @Test fun testQuat() { - assertEquals(Quaternion(0.7, 0.0, 0.0, 0.7).round(1), Quaternion().setEuler(90.degrees, 0.degrees, 0.degrees).round(1)) - assertEquals(Quaternion(0.0, 0.7, 0.0, 0.7).round(1), Quaternion().setEuler(0.degrees, 90.degrees, 0.degrees).round(1)) - assertEquals(Quaternion(0.0, 0.0, 0.7, 0.7).round(1), Quaternion().setEuler(0.degrees, 0.degrees, 90.degrees).round(1)) + assertEquals(MQuaternion(0.7, 0.0, 0.0, 0.7).round(1), MQuaternion().setEuler(90.degrees, 0.degrees, 0.degrees).round(1)) + assertEquals(MQuaternion(0.0, 0.7, 0.0, 0.7).round(1), MQuaternion().setEuler(0.degrees, 90.degrees, 0.degrees).round(1)) + assertEquals(MQuaternion(0.0, 0.0, 0.7, 0.7).round(1), MQuaternion().setEuler(0.degrees, 0.degrees, 90.degrees).round(1)) - assertEquals(EulerRotation(90.degrees, 0.degrees, 0.degrees), EulerRotation().setQuaternion(Quaternion().setEuler(90.degrees, 0.degrees, 0.degrees)), 0.1) - assertEquals(EulerRotation(0.degrees, 90.degrees, 0.degrees), EulerRotation().setQuaternion(Quaternion().setEuler(0.degrees, 90.degrees, 0.degrees)), 0.1) - assertEquals(EulerRotation(0.degrees, 0.degrees, 90.degrees), EulerRotation().setQuaternion(Quaternion().setEuler(0.degrees, 0.degrees, 90.degrees)), 0.1) + assertEquals(MEulerRotation(90.degrees, 0.degrees, 0.degrees), MEulerRotation().setQuaternion(MQuaternion().setEuler(90.degrees, 0.degrees, 0.degrees)), 0.1) + assertEquals(MEulerRotation(0.degrees, 90.degrees, 0.degrees), MEulerRotation().setQuaternion(MQuaternion().setEuler(0.degrees, 90.degrees, 0.degrees)), 0.1) + assertEquals(MEulerRotation(0.degrees, 0.degrees, 90.degrees), MEulerRotation().setQuaternion(MQuaternion().setEuler(0.degrees, 0.degrees, 90.degrees)), 0.1) } @Test fun testInvert() { - val mat = Matrix3D().setTRS(Position3D(1, 2, 3), Quaternion().setEuler(15.degrees, 30.degrees, 60.degrees), Scale3D(1, 2, 3)) - val inv = Matrix3D().invert(mat) + val mat = MMatrix3D().setTRS(Position3D(1, 2, 3), MQuaternion().setEuler(15.degrees, 30.degrees, 60.degrees), Scale3D(1, 2, 3)) + val inv = MMatrix3D().invert(mat) assertEquals( - Matrix3D().round(2).toString(), + MMatrix3D().round(2).toString(), (mat * inv).round(2).toString() ) } - fun assertEquals(a: EulerRotation, b: EulerRotation, delta: Double = 0.01) { + fun assertEquals(a: MEulerRotation, b: MEulerRotation, delta: Double = 0.01) { assertTrue("$a\n$b\na!=b // delta=$delta") { abs(a.x.degrees - b.x.degrees) <= delta && abs(a.y.degrees - b.y.degrees) <= delta && @@ -230,7 +230,7 @@ class Matrix3DTest { } } - fun assertEquals(a: Quaternion, b: Quaternion, delta: Double = 0.01) { + fun assertEquals(a: MQuaternion, b: MQuaternion, delta: Double = 0.01) { assertTrue("$a\n$b\na!=b // delta=$delta") { abs(a.x - b.x) <= delta && abs(a.y - b.y) <= delta && @@ -247,9 +247,9 @@ class Matrix3DTest { assertTrue("$a != $b // delta=$delta") { abs(a - b) <= delta } } - fun Vector3D.round(digits: Int = 0) = setTo(round(x, digits), round(y, digits), round(z, digits), round(w, digits)) - fun Quaternion.round(digits: Int = 0) = setTo(round(x, digits), round(y, digits), round(z, digits), round(w, digits)) - fun Matrix3D.round(digits: Int = 0) = setToMap { round(it, digits) } + fun MVector4.round(digits: Int = 0) = setTo(round(x, digits), round(y, digits), round(z, digits), round(w, digits)) + fun MQuaternion.round(digits: Int = 0) = setTo(round(x, digits), round(y, digits), round(z, digits), round(w, digits)) + fun MMatrix3D.round(digits: Int = 0) = setToMap { round(it, digits) } fun round(x: Float, digits: Int) = (kotlin.math.round(x * 10.0.pow(digits)) / 10.0.pow(digits)).toFloat() fun round(x: Double, digits: Int) = kotlin.math.round(x * 10.0.pow(digits)) / 10.0.pow(digits) diff --git a/korma/src/commonTest/kotlin/com/soywiz/korma/geom/MatrixTest.kt b/korma/src/commonTest/kotlin/com/soywiz/korma/geom/MatrixTest.kt index d79a40ea7f..5a791dc8e4 100644 --- a/korma/src/commonTest/kotlin/com/soywiz/korma/geom/MatrixTest.kt +++ b/korma/src/commonTest/kotlin/com/soywiz/korma/geom/MatrixTest.kt @@ -4,48 +4,48 @@ import com.soywiz.korma.interpolation.interpolate import kotlin.test.* class MatrixTest { - private val identity: Matrix = Matrix(1, 0, 0, 1, 0, 0) + private val identity: MMatrix = MMatrix(1, 0, 0, 1, 0, 0) @Test fun test() { - val matrix = Matrix() + val matrix = MMatrix() matrix.pretranslate(10, 10) matrix.prescale(2, 3) matrix.prerotate(90.degrees) - assertEquals(PointInt(10, 40).toString(), matrix.transform(Point(10, 0)).asInt().toString()) + assertEquals(MPointInt(10, 40).toString(), matrix.transform(MPoint(10, 0)).asInt().toString()) } @Test fun transform() { - val matrix = Matrix(2, 0, 0, 3, 10, 15) + val matrix = MMatrix(2, 0, 0, 3, 10, 15) assertEquals(30.0, matrix.transformX(10, 20)) assertEquals(75.0, matrix.transformY(10, 20)) - assertEquals(Point(30.0, 75.0), matrix.transform(Point(10, 20))) - assertEquals(Point(20.0, 60.0), matrix.deltaTransformPoint(Point(10, 20))) + assertEquals(MPoint(30.0, 75.0), matrix.transform(MPoint(10, 20))) + assertEquals(MPoint(20.0, 60.0), matrix.deltaTransformPoint(MPoint(10, 20))) } @Test fun type() { - assertEquals(Matrix.Type.IDENTITY, Matrix(1, 0, 0, 1, 0, 0).getType()) - assertEquals(Matrix.Type.TRANSLATE, Matrix(1, 0, 0, 1, 10, 0).getType()) - assertEquals(Matrix.Type.TRANSLATE, Matrix(1, 0, 0, 1, 0, 10).getType()) - assertEquals(Matrix.Type.SCALE, Matrix(1, 0, 0, 2, 0, 0).getType()) - assertEquals(Matrix.Type.SCALE, Matrix(2, 0, 0, 1, 0, 0).getType()) - assertEquals(Matrix.Type.SCALE_TRANSLATE, Matrix(2, 0, 0, 2, 10, 0).getType()) - assertEquals(Matrix.Type.COMPLEX, Matrix(1, 1, 0, 1, 0, 0).getType()) - - assertEquals(Matrix.Type.IDENTITY, Matrix().getType()) - assertEquals(Matrix.Type.SCALE, Matrix().apply { scale(2, 1) }.getType()) - assertEquals(Matrix.Type.SCALE, Matrix().apply { scale(1, 2) }.getType()) - assertEquals(Matrix.Type.TRANSLATE, Matrix().apply { translate(1, 0) }.getType()) - assertEquals(Matrix.Type.TRANSLATE, Matrix().apply { translate(0, 1) }.getType()) - assertEquals(Matrix.Type.SCALE_TRANSLATE, Matrix().apply { scale(2, 1).translate(0, 1) }.getType()) - assertEquals(Matrix.Type.COMPLEX, Matrix().apply { rotate(90.degrees) }.getType()) + assertEquals(MMatrix.Type.IDENTITY, MMatrix(1, 0, 0, 1, 0, 0).getType()) + assertEquals(MMatrix.Type.TRANSLATE, MMatrix(1, 0, 0, 1, 10, 0).getType()) + assertEquals(MMatrix.Type.TRANSLATE, MMatrix(1, 0, 0, 1, 0, 10).getType()) + assertEquals(MMatrix.Type.SCALE, MMatrix(1, 0, 0, 2, 0, 0).getType()) + assertEquals(MMatrix.Type.SCALE, MMatrix(2, 0, 0, 1, 0, 0).getType()) + assertEquals(MMatrix.Type.SCALE_TRANSLATE, MMatrix(2, 0, 0, 2, 10, 0).getType()) + assertEquals(MMatrix.Type.COMPLEX, MMatrix(1, 1, 0, 1, 0, 0).getType()) + + assertEquals(MMatrix.Type.IDENTITY, MMatrix().getType()) + assertEquals(MMatrix.Type.SCALE, MMatrix().apply { scale(2, 1) }.getType()) + assertEquals(MMatrix.Type.SCALE, MMatrix().apply { scale(1, 2) }.getType()) + assertEquals(MMatrix.Type.TRANSLATE, MMatrix().apply { translate(1, 0) }.getType()) + assertEquals(MMatrix.Type.TRANSLATE, MMatrix().apply { translate(0, 1) }.getType()) + assertEquals(MMatrix.Type.SCALE_TRANSLATE, MMatrix().apply { scale(2, 1).translate(0, 1) }.getType()) + assertEquals(MMatrix.Type.COMPLEX, MMatrix().apply { rotate(90.degrees) }.getType()) } @Test fun identity() { - val m = Matrix() + val m = MMatrix() assertEquals(1.0, m.a) assertEquals(0.0, m.b) assertEquals(0.0, m.c) @@ -53,28 +53,28 @@ class MatrixTest { assertEquals(0.0, m.tx) assertEquals(0.0, m.ty) m.setTo(2, 2, 2, 2, 2, 2) - assertEquals(Matrix(2, 2, 2, 2, 2, 2), m) + assertEquals(MMatrix(2, 2, 2, 2, 2, 2), m) m.identity() assertEquals(identity, m) } @Test fun invert() { - val a = Matrix(2, 1, 1, 2, 10, 10) + val a = MMatrix(2, 1, 1, 2, 10, 10) a.invert() - assertEquals(Matrix(a = 0.6666666666666666, b = -0.3333333333333333, c = -0.3333333333333333, d = 0.6666666666666666, tx = -3.333333333333333, ty = -3.333333333333333), a) + assertEquals(MMatrix(a = 0.6666666666666666, b = -0.3333333333333333, c = -0.3333333333333333, d = 0.6666666666666666, tx = -3.333333333333333, ty = -3.333333333333333), a) } @Test fun inverted() { - val a = Matrix(2, 1, 1, 2, 10, 10) + val a = MMatrix(2, 1, 1, 2, 10, 10) val b = a.inverted() assertEquals(identity, a * b) } @Test fun clone() { - val mat = Matrix(1, 2, 3, 4, 5, 6) + val mat = MMatrix(1, 2, 3, 4, 5, 6) assertNotSame(mat, mat.clone()) assertTrue(mat !== mat.clone()) assertEquals(mat, mat.clone()) @@ -82,31 +82,31 @@ class MatrixTest { @Test fun keep() { - val m = Matrix() + val m = MMatrix() m.keepMatrix { m.setTo(2, 3, 4, 5, 6, 7) - assertEquals(Matrix(2, 3, 4, 5, 6, 7), m) + assertEquals(MMatrix(2, 3, 4, 5, 6, 7), m) } assertEquals(identity, m) } @Test fun transform2() { - assertEquals(Matrix(2, 0, 0, 3, 10, 20), Matrix.Transform(10.0, 20.0, scaleX = 2.0, scaleY = 3.0).toMatrix()) + assertEquals(MMatrix(2, 0, 0, 3, 10, 20), MMatrix.Transform(10.0, 20.0, scaleX = 2.0, scaleY = 3.0).toMatrix()) // @TODO: Kotlin.JS BUG (missing arguments are NaN or undefined but it works fine on JVM) //val t1 = Matrix.Transform(10, 20, scaleX = 2, scaleY = 3, rotation = 90.degrees) //val t2 = Matrix.Transform(20, 40, scaleX = 4, scaleY = 5, rotation = 180.degrees) - val t1 = Matrix.Transform(10.0, 20.0, scaleX = 2.0, scaleY = 3.0, skewX = 0.0.degrees, skewY = 0.0.degrees, rotation = 90.degrees) - val t2 = Matrix.Transform(20.0, 40.0, scaleX = 4.0, scaleY = 5.0, skewX = 0.0.degrees, skewY = 0.0.degrees, rotation = 180.degrees) + val t1 = MMatrix.Transform(10.0, 20.0, scaleX = 2.0, scaleY = 3.0, skewX = 0.0.degrees, skewY = 0.0.degrees, rotation = 90.degrees) + val t2 = MMatrix.Transform(20.0, 40.0, scaleX = 4.0, scaleY = 5.0, skewX = 0.0.degrees, skewY = 0.0.degrees, rotation = 180.degrees) assertEquals( - Matrix.Transform(x = 15.0, y = 30.0, scaleX = 3.0, scaleY = 4.0, skewX = 0.0.degrees, skewY = 0.0.degrees, rotation = 135.degrees), + MMatrix.Transform(x = 15.0, y = 30.0, scaleX = 3.0, scaleY = 4.0, skewX = 0.0.degrees, skewY = 0.0.degrees, rotation = 135.degrees), 0.5.interpolate(t1, t2) ) - val identity = Matrix.Transform() - val mt = Matrix.Transform(1.0, 2.0, 3.0, 4.0, 5.0.radians, 6.0.radians, 7.0.radians) + val identity = MMatrix.Transform() + val mt = MMatrix.Transform(1.0, 2.0, 3.0, 4.0, 5.0.radians, 6.0.radians, 7.0.radians) mt.identity() assertEquals(identity, mt) assertNotSame(mt, mt.clone()) @@ -115,9 +115,9 @@ class MatrixTest { @Test fun transform3() { - val m = Matrix() - val t = Matrix.Transform() - val t2 = Matrix.Transform() + val m = MMatrix() + val t = MMatrix.Transform() + val t2 = MMatrix.Transform() t.rotation = -(91.degrees) t.scaleAvg = 1.3 t.toMatrix(m) diff --git a/korma/src/commonTest/kotlin/com/soywiz/korma/geom/OrientationTest.kt b/korma/src/commonTest/kotlin/com/soywiz/korma/geom/OrientationTest.kt index 55f71c5bb8..048bd8d67c 100644 --- a/korma/src/commonTest/kotlin/com/soywiz/korma/geom/OrientationTest.kt +++ b/korma/src/commonTest/kotlin/com/soywiz/korma/geom/OrientationTest.kt @@ -6,8 +6,8 @@ import kotlin.test.assertEquals class OrientationTest { @Test fun test() { - assertEquals(Orientation.CLOCK_WISE, Orientation.orient2d(Point(0, 0), Point(0, 10), Point(10, 0))) - assertEquals(Orientation.COUNTER_CLOCK_WISE, Orientation.orient2d(Point(10, 0), Point(0, 10), Point(0, 0))) - assertEquals(Orientation.COLLINEAR, Orientation.orient2d(Point(0, 0), Point(5, 0), Point(10, 0))) + assertEquals(Orientation.CLOCK_WISE, Orientation.orient2d(MPoint(0, 0), MPoint(0, 10), MPoint(10, 0))) + assertEquals(Orientation.COUNTER_CLOCK_WISE, Orientation.orient2d(MPoint(10, 0), MPoint(0, 10), MPoint(0, 0))) + assertEquals(Orientation.COLLINEAR, Orientation.orient2d(MPoint(0, 0), MPoint(5, 0), MPoint(10, 0))) } } diff --git a/korma/src/commonTest/kotlin/com/soywiz/korma/geom/PointArrayListTest.kt b/korma/src/commonTest/kotlin/com/soywiz/korma/geom/PointArrayListTest.kt index cf9e6e9ced..c5ac767c9e 100644 --- a/korma/src/commonTest/kotlin/com/soywiz/korma/geom/PointArrayListTest.kt +++ b/korma/src/commonTest/kotlin/com/soywiz/korma/geom/PointArrayListTest.kt @@ -31,22 +31,22 @@ class PointArrayListTest { fun testTransform() { val list = PointArrayList().add(1, 1).add(2, 2).add(3, 3) assertEquals("[(1, 1), (2, 2), (3, 3)]", list.toList().toString()) - assertEquals("[(10, -10), (20, -20), (30, -30)]", list.clone().also { it.transform(Matrix().scale(10, -10)) }.toList().toString()) + assertEquals("[(10, -10), (20, -20), (30, -30)]", list.clone().also { it.transform(MMatrix().scale(10, -10)) }.toList().toString()) assertEquals("[(1, 1), (2, 2), (3, 3)]", list.toList().toString()) } @Test fun testInsert() { - val list = PointArrayList(Point(1, -1), Point(2, -2), Point(3, -3)) - list.insertAt(1, Point(0, -1)) + val list = PointArrayList(MPoint(1, -1), MPoint(2, -2), MPoint(3, -3)) + list.insertAt(1, MPoint(0, -1)) assertEquals("[(1, -1), (0, -1), (2, -2), (3, -3)]", list.toList().toString()) list.removeAt(1, 2) assertEquals("[(1, -1), (3, -3)]", list.toList().toString()) list.removeAt(0, 2) assertEquals("[]", list.toList().toString()) - list.insertAt(0, Point(0, -1)) + list.insertAt(0, MPoint(0, -1)) assertEquals("[(0, -1)]", list.toList().toString()) - list.insertAt(1, PointArrayList(Point(2, -2), Point(4, -4))) + list.insertAt(1, PointArrayList(MPoint(2, -2), MPoint(4, -4))) assertEquals("[(0, -1), (2, -2), (4, -4)]", list.toList().toString()) } diff --git a/korma/src/commonTest/kotlin/com/soywiz/korma/geom/PointTest.kt b/korma/src/commonTest/kotlin/com/soywiz/korma/geom/PointTest.kt index 777aeb01ec..fadc5a4bd2 100644 --- a/korma/src/commonTest/kotlin/com/soywiz/korma/geom/PointTest.kt +++ b/korma/src/commonTest/kotlin/com/soywiz/korma/geom/PointTest.kt @@ -6,12 +6,12 @@ import kotlin.test.assertEquals class PointTest { @Test fun testPolar() { - assertEquals("(10, 0)", Point.fromPolar(0.degrees, 10.0).toString()) - assertEquals("(0, 10)", Point.fromPolar(90.degrees, 10.0).toString()) - assertEquals("(-10, 0)", Point.fromPolar(180.degrees, 10.0).toString()) - assertEquals("(0, -10)", Point.fromPolar(270.degrees, 10.0).toString()) - assertEquals("(10, 0)", Point.fromPolar(360.degrees, 10.0).toString()) + assertEquals("(10, 0)", MPoint.fromPolar(0.degrees, 10.0).toString()) + assertEquals("(0, 10)", MPoint.fromPolar(90.degrees, 10.0).toString()) + assertEquals("(-10, 0)", MPoint.fromPolar(180.degrees, 10.0).toString()) + assertEquals("(0, -10)", MPoint.fromPolar(270.degrees, 10.0).toString()) + assertEquals("(10, 0)", MPoint.fromPolar(360.degrees, 10.0).toString()) - assertEquals("(0, 5)", Point.fromPolar(0.degrees, 10.0).setToPolar(90.degrees, 5.0).toString()) + assertEquals("(0, 5)", MPoint.fromPolar(0.degrees, 10.0).setToPolar(90.degrees, 5.0).toString()) } } diff --git a/korma/src/commonTest/kotlin/com/soywiz/korma/geom/RectangleTest.kt b/korma/src/commonTest/kotlin/com/soywiz/korma/geom/RectangleTest.kt index 8945493030..2c5692f92e 100644 --- a/korma/src/commonTest/kotlin/com/soywiz/korma/geom/RectangleTest.kt +++ b/korma/src/commonTest/kotlin/com/soywiz/korma/geom/RectangleTest.kt @@ -8,9 +8,9 @@ import kotlin.test.assertTrue class RectangleTest { @Test fun name() { - val big = Rectangle.fromBounds(0, 0, 50, 50) - val small = Rectangle.fromBounds(10, 10, 20, 20) - val out = Rectangle.fromBounds(100, 10, 200, 20) + val big = MRectangle.fromBounds(0, 0, 50, 50) + val small = MRectangle.fromBounds(10, 10, 20, 20) + val out = MRectangle.fromBounds(100, 10, 200, 20) assertTrue(small in big) assertTrue(big !in small) assertTrue(small == (small intersection big)) @@ -23,24 +23,24 @@ class RectangleTest { @Test fun name2() { - val r1 = Rectangle(20, 0, 30, 10) - val r2 = Rectangle(100, 0, 100, 50) + val r1 = MRectangle(20, 0, 30, 10) + val r2 = MRectangle(100, 0, 100, 50) val ro = r1.copy() ro.setToAnchoredRectangle(ro, Anchor.MIDDLE_CENTER, r2) //Assert.assertEquals(Rectangle(0, 0, 0, 0), r1) - assertEquals(Rectangle(135, 20, 30, 10), ro) + assertEquals(MRectangle(135, 20, 30, 10), ro) } @Test fun testPlace() { val out = - Rectangle(0, 0, 100, 100).place(Size(50, 25), Anchor.MIDDLE_CENTER, ScaleMode.SHOW_ALL) - assertEquals(Rectangle(0, 25, 100, 50), out) + MRectangle(0, 0, 100, 100).place(MSize(50, 25), Anchor.MIDDLE_CENTER, ScaleMode.SHOW_ALL) + assertEquals(MRectangle(0, 25, 100, 50), out) } @Test fun corners() { - val rectangle = Rectangle(1, 20, 300, 4000) + val rectangle = MRectangle(1, 20, 300, 4000) assertEquals(IPoint(1, 20), rectangle.topLeft) assertEquals(IPoint(301, 20), rectangle.topRight) assertEquals(IPoint(1, 4020), rectangle.bottomLeft) @@ -116,55 +116,55 @@ class RectangleTest { @Test fun testMargin() { assertEquals( - Rectangle.fromBounds(10, 10, 90, 90), - Rectangle(0, 0, 100, 100).without(Margin(10.0)) + MRectangle.fromBounds(10, 10, 90, 90), + MRectangle(0, 0, 100, 100).without(IMargin(10.0)) ) assertEquals( - Rectangle.fromBounds(-10, -10, 110, 110), - Rectangle(0, 0, 100, 100).with(Margin(10.0)) + MRectangle.fromBounds(-10, -10, 110, 110), + MRectangle(0, 0, 100, 100).with(IMargin(10.0)) ) } @Test fun testInt() { - assertEquals(RectangleInt(1, 2, 3, 4), Rectangle(1.1, 2.1, 3.1, 4.1).toInt()) + assertEquals(RectangleInt(1, 2, 3, 4), MRectangle(1.1, 2.1, 3.1, 4.1).toInt()) } @Test fun testExpand() { assertEquals( - Rectangle.fromBounds(-10, -15, 120, 125), - Rectangle.fromBounds(0, 0, 100, 100).expand(10, 15, 20, 25) + MRectangle.fromBounds(-10, -15, 120, 125), + MRectangle.fromBounds(0, 0, 100, 100).expand(10, 15, 20, 25) ) assertEquals( - Rectangle.fromBounds(-10, -15, 120, 125), - Rectangle.fromBounds(0, 0, 100, 100) - .expand(Margin(left = 10.0, top = 15.0, right = 20.0, bottom = 25.0)) + MRectangle.fromBounds(-10, -15, 120, 125), + MRectangle.fromBounds(0, 0, 100, 100) + .expand(IMargin(left = 10.0, top = 15.0, right = 20.0, bottom = 25.0)) ) assertEquals( - Rectangle.fromBounds(-10, -15, 120, 125), - Rectangle.fromBounds(0, 0, 100, 100) - .expand(MarginInt(left = 10, top = 15, right = 20, bottom = 25)) + MRectangle.fromBounds(-10, -15, 120, 125), + MRectangle.fromBounds(0, 0, 100, 100) + .expand(IMarginInt(left = 10, top = 15, right = 20, bottom = 25)) ) } @Test fun constructWithPoints() { assertEquals( - IRectangle(Point(0, 0), Point(100, 100)), - Rectangle(0, 0, 100, 100) + IRectangle(MPoint(0, 0), MPoint(100, 100)), + MRectangle(0, 0, 100, 100) ) assertEquals( - IRectangle(Point(100, 100), Point(0, 0)), - Rectangle(0, 0, 100, 100) + IRectangle(MPoint(100, 100), MPoint(0, 0)), + MRectangle(0, 0, 100, 100) ) assertEquals( - IRectangle(Point(0, 100), Point(100, 0)), - Rectangle(0, 0, 100, 100) + IRectangle(MPoint(0, 100), MPoint(100, 0)), + MRectangle(0, 0, 100, 100) ) assertEquals( - IRectangle(Point(100, 0), Point(0, 100)), - Rectangle(0, 0, 100, 100) + IRectangle(MPoint(100, 0), MPoint(0, 100)), + MRectangle(0, 0, 100, 100) ) } } diff --git a/korma/src/commonTest/kotlin/com/soywiz/korma/geom/ScaleModeTest.kt b/korma/src/commonTest/kotlin/com/soywiz/korma/geom/ScaleModeTest.kt index bf2d81220d..84ca0a716c 100644 --- a/korma/src/commonTest/kotlin/com/soywiz/korma/geom/ScaleModeTest.kt +++ b/korma/src/commonTest/kotlin/com/soywiz/korma/geom/ScaleModeTest.kt @@ -15,20 +15,20 @@ class ScaleModeTest { @Test fun rectangle() { - assertEquals(Rectangle(150, 0, 300, 300), Rectangle(0, 0, 100, 100).applyScaleMode(Rectangle(0, 0, 600, 300), ScaleMode.SHOW_ALL, Anchor.MIDDLE_CENTER)) - assertEquals(Rectangle(0, 0, 300, 300), Rectangle(0, 0, 100, 100).applyScaleMode(Rectangle(0, 0, 600, 300), ScaleMode.SHOW_ALL, Anchor.TOP_LEFT)) - assertEquals(Rectangle(300, 0, 300, 300), Rectangle(0, 0, 100, 100).applyScaleMode(Rectangle(0, 0, 600, 300), ScaleMode.SHOW_ALL, Anchor.BOTTOM_RIGHT)) + assertEquals(MRectangle(150, 0, 300, 300), MRectangle(0, 0, 100, 100).applyScaleMode(MRectangle(0, 0, 600, 300), ScaleMode.SHOW_ALL, Anchor.MIDDLE_CENTER)) + assertEquals(MRectangle(0, 0, 300, 300), MRectangle(0, 0, 100, 100).applyScaleMode(MRectangle(0, 0, 600, 300), ScaleMode.SHOW_ALL, Anchor.TOP_LEFT)) + assertEquals(MRectangle(300, 0, 300, 300), MRectangle(0, 0, 100, 100).applyScaleMode(MRectangle(0, 0, 600, 300), ScaleMode.SHOW_ALL, Anchor.BOTTOM_RIGHT)) - assertEquals(Rectangle(0, 0, 600, 300), Rectangle(0, 0, 100, 100).applyScaleMode(Rectangle(0, 0, 600, 300), ScaleMode.EXACT, Anchor.MIDDLE_CENTER)) + assertEquals(MRectangle(0, 0, 600, 300), MRectangle(0, 0, 100, 100).applyScaleMode(MRectangle(0, 0, 600, 300), ScaleMode.EXACT, Anchor.MIDDLE_CENTER)) - assertEquals(Rectangle(0, 0, 100, 100), Rectangle(0, 0, 100, 100).applyScaleMode(Rectangle(0, 0, 600, 300), ScaleMode.NO_SCALE, Anchor.TOP_LEFT)) - assertEquals(Rectangle(250, 100, 100, 100), Rectangle(0, 0, 100, 100).applyScaleMode(Rectangle(0, 0, 600, 300), ScaleMode.NO_SCALE, Anchor.MIDDLE_CENTER)) - assertEquals(Rectangle(500, 200, 100, 100), Rectangle(0, 0, 100, 100).applyScaleMode(Rectangle(0, 0, 600, 300), ScaleMode.NO_SCALE, Anchor.BOTTOM_RIGHT)) + assertEquals(MRectangle(0, 0, 100, 100), MRectangle(0, 0, 100, 100).applyScaleMode(MRectangle(0, 0, 600, 300), ScaleMode.NO_SCALE, Anchor.TOP_LEFT)) + assertEquals(MRectangle(250, 100, 100, 100), MRectangle(0, 0, 100, 100).applyScaleMode(MRectangle(0, 0, 600, 300), ScaleMode.NO_SCALE, Anchor.MIDDLE_CENTER)) + assertEquals(MRectangle(500, 200, 100, 100), MRectangle(0, 0, 100, 100).applyScaleMode(MRectangle(0, 0, 600, 300), ScaleMode.NO_SCALE, Anchor.BOTTOM_RIGHT)) - assertEquals(Rectangle(0, 0, 100, 100), Size(100, 100).applyScaleMode(Rectangle(-100, -100, 200, 200), ScaleMode.NO_SCALE, Anchor.BOTTOM_RIGHT)) + assertEquals(MRectangle(0, 0, 100, 100), MSize(100, 100).applyScaleMode(MRectangle(-100, -100, 200, 200), ScaleMode.NO_SCALE, Anchor.BOTTOM_RIGHT)) - assertEquals(Rectangle(0, 0, 600, 600), Size(100, 100).applyScaleMode(Rectangle(0, 0, 600, 300), ScaleMode.COVER, Anchor.TOP_LEFT)) - assertEquals(Rectangle(0, -150, 600, 600), Size(100, 100).applyScaleMode(Rectangle(0, 0, 600, 300), ScaleMode.COVER, Anchor.MIDDLE_CENTER)) - assertEquals(Rectangle(0, -300, 600, 600), Size(100, 100).applyScaleMode(Rectangle(0, 0, 600, 300), ScaleMode.COVER, Anchor.BOTTOM_RIGHT)) + assertEquals(MRectangle(0, 0, 600, 600), MSize(100, 100).applyScaleMode(MRectangle(0, 0, 600, 300), ScaleMode.COVER, Anchor.TOP_LEFT)) + assertEquals(MRectangle(0, -150, 600, 600), MSize(100, 100).applyScaleMode(MRectangle(0, 0, 600, 300), ScaleMode.COVER, Anchor.MIDDLE_CENTER)) + assertEquals(MRectangle(0, -300, 600, 600), MSize(100, 100).applyScaleMode(MRectangle(0, 0, 600, 300), ScaleMode.COVER, Anchor.BOTTOM_RIGHT)) } } diff --git a/korma/src/commonTest/kotlin/com/soywiz/korma/geom/Vector3DTest.kt b/korma/src/commonTest/kotlin/com/soywiz/korma/geom/Vector3DTest.kt index 67d15c47c2..18588356c9 100644 --- a/korma/src/commonTest/kotlin/com/soywiz/korma/geom/Vector3DTest.kt +++ b/korma/src/commonTest/kotlin/com/soywiz/korma/geom/Vector3DTest.kt @@ -6,39 +6,39 @@ import kotlin.test.assertEquals class Vector3DTest { @Test fun testNormalize() { - val v = Vector3D(2, 0, 0) + val v = MVector4(2, 0, 0) // Normalized doesn't changes the original vector - assertEquals(Vector3D(1, 0, 0), v.normalized()) - assertEquals(Vector3D(2, 0, 0), v) + assertEquals(MVector4(1, 0, 0), v.normalized()) + assertEquals(MVector4(2, 0, 0), v) // Normalize mutates the vector - assertEquals(Vector3D(1, 0, 0), v.normalize()) - assertEquals(Vector3D(1, 0, 0), v) + assertEquals(MVector4(1, 0, 0), v.normalize()) + assertEquals(MVector4(1, 0, 0), v) } @Test fun testCrossProduct() { - val xInt = Vector3D().cross(Vector3D(1, 0, 0), Vector3D(0, 1, 0)) - assertEquals(Vector3D(0, 0, 1), xInt) - val xDouble = Vector3D().cross(Vector3D(1.0, 0.0, 0.0), Vector3D(0.0, 1.0, 0.0)) - assertEquals(Vector3D(0.0, 0.0, 1.0), xDouble) + val xInt = MVector4().cross(MVector4(1, 0, 0), MVector4(0, 1, 0)) + assertEquals(MVector4(0, 0, 1), xInt) + val xDouble = MVector4().cross(MVector4(1.0, 0.0, 0.0), MVector4(0.0, 1.0, 0.0)) + assertEquals(MVector4(0.0, 0.0, 1.0), xDouble) } @Test fun testDotProduct() { - val dot = Vector3D(0.5, 1.0, 0.0).dot(Vector3D(3.0, 1.0, 1.0)) + val dot = MVector4(0.5, 1.0, 0.0).dot(MVector4(3.0, 1.0, 1.0)) assertEquals(2.5f, dot) } @Test fun testBasicMath() { - val v = Vector3D(0,0,0) - v.add(v, Vector3D(1,0,0)) - assertEquals(Vector3D(1, 0,0, 2), v) + val v = MVector4(0,0,0) + v.add(v, MVector4(1,0,0)) + assertEquals(MVector4(1, 0,0, 2), v) v.scale(5) - assertEquals(Vector3D(5, 0 ,0,10), v) - v.sub(v, Vector3D(2, 1, 0)) - assertEquals(Vector3D(3, -1, 0, 9), v) + assertEquals(MVector4(5, 0 ,0,10), v) + v.sub(v, MVector4(2, 1, 0)) + assertEquals(MVector4(3, -1, 0, 9), v) } } diff --git a/korma/src/commonTest/kotlin/com/soywiz/korma/geom/bezier/BezierCurveCubicTest.kt b/korma/src/commonTest/kotlin/com/soywiz/korma/geom/bezier/BezierCurveCubicTest.kt index 3400c47077..7942c49fc2 100644 --- a/korma/src/commonTest/kotlin/com/soywiz/korma/geom/bezier/BezierCurveCubicTest.kt +++ b/korma/src/commonTest/kotlin/com/soywiz/korma/geom/bezier/BezierCurveCubicTest.kt @@ -1,8 +1,8 @@ package com.soywiz.korma.geom.bezier -import com.soywiz.korma.geom.Point +import com.soywiz.korma.geom.MPoint import com.soywiz.korma.geom.PointArrayList -import com.soywiz.korma.geom.Rectangle +import com.soywiz.korma.geom.MRectangle import kotlin.test.Test import kotlin.test.assertEquals @@ -30,16 +30,16 @@ class BezierCurveCubicTest { b.dpoints ) - assertEquals(Point(0, 3), b.derivative(0.0)) - assertEquals(Point(1.5, 0.0), b.derivative(0.5)) - assertEquals(Point(0, -3), b.derivative(1.0)) + assertEquals(MPoint(0, 3), b.derivative(0.0)) + assertEquals(MPoint(1.5, 0.0), b.derivative(0.5)) + assertEquals(MPoint(0, -3), b.derivative(1.0)) } @Test fun testHasTheExpectedNormals() { - assertEquals(Point(-1, 0), b.normal(0.0)) - assertEquals(Point(-0.0, 1.0), b.normal(0.5)) - assertEquals(Point(1.0, 0.0), b.normal(1.0)) + assertEquals(MPoint(-1, 0), b.normal(0.0)) + assertEquals(MPoint(-0.0, 1.0), b.normal(0.5)) + assertEquals(MPoint(1.0, 0.0), b.normal(1.0)) } @Test @@ -50,7 +50,7 @@ class BezierCurveCubicTest { @Test fun testHasTheCorrectAxisAlignedBoundingBox() { assertEquals( - Rectangle.fromBounds(0.0, 0.0, 1.0, 0.75), + MRectangle.fromBounds(0.0, 0.0, 1.0, 0.75), b.boundingBox ) } @@ -63,8 +63,8 @@ class BezierCurveCubicTest { @Test fun testFromPointSet() { - val M = Point(200 / 3.0, 100 / 3.0) - val pts = listOf(Point(0, 0), M, Point(100, 100)) + val M = MPoint(200 / 3.0, 100 / 3.0) + val pts = listOf(MPoint(0, 0), M, MPoint(100, 100)) run { val b: Bezier = Bezier.cubicFromPoints(pts[0], pts[1], pts[2]) assertEquals( diff --git a/korma/src/commonTest/kotlin/com/soywiz/korma/geom/bezier/BezierCurveLinearTest.kt b/korma/src/commonTest/kotlin/com/soywiz/korma/geom/bezier/BezierCurveLinearTest.kt index 8286559c8d..47e79762b3 100644 --- a/korma/src/commonTest/kotlin/com/soywiz/korma/geom/bezier/BezierCurveLinearTest.kt +++ b/korma/src/commonTest/kotlin/com/soywiz/korma/geom/bezier/BezierCurveLinearTest.kt @@ -1,6 +1,6 @@ package com.soywiz.korma.geom.bezier -import com.soywiz.korma.geom.Point +import com.soywiz.korma.geom.MPoint import kotlin.test.Test import kotlin.test.assertEquals @@ -14,6 +14,6 @@ class BezierCurveLinearTest { @Test fun testMidpointIsIndeedTheMidpoint() { - assertEquals(Point(50, 50), b.compute(0.5)) + assertEquals(MPoint(50, 50), b.compute(0.5)) } } diff --git a/korma/src/commonTest/kotlin/com/soywiz/korma/geom/bezier/BezierCurveQuadraticTest.kt b/korma/src/commonTest/kotlin/com/soywiz/korma/geom/bezier/BezierCurveQuadraticTest.kt index d145f538c5..b19ac040df 100644 --- a/korma/src/commonTest/kotlin/com/soywiz/korma/geom/bezier/BezierCurveQuadraticTest.kt +++ b/korma/src/commonTest/kotlin/com/soywiz/korma/geom/bezier/BezierCurveQuadraticTest.kt @@ -1,8 +1,8 @@ package com.soywiz.korma.geom.bezier -import com.soywiz.korma.geom.Point +import com.soywiz.korma.geom.MPoint import com.soywiz.korma.geom.PointArrayList -import com.soywiz.korma.geom.Rectangle +import com.soywiz.korma.geom.MRectangle import kotlin.test.Test import kotlin.test.assertEquals @@ -27,16 +27,16 @@ class BezierCurveQuadraticTest { ), b.dpoints ) - assertEquals(Point(1, 2), b.derivative(0.0)) - assertEquals(Point(1, 0), b.derivative(0.5)) - assertEquals(Point(1, -2), b.derivative(1.0)) + assertEquals(MPoint(1, 2), b.derivative(0.0)) + assertEquals(MPoint(1, 0), b.derivative(0.5)) + assertEquals(MPoint(1, -2), b.derivative(1.0)) } @Test fun testHasTheExpectedNormals() { - assertEquals(Point(-0.8944271909999159, 0.4472135954999579), b.normal(0.0)) - assertEquals(Point(-0.0, 1.0), b.normal(0.5)) - assertEquals(Point(0.8944271909999159, 0.4472135954999579), b.normal(1.0)) + assertEquals(MPoint(-0.8944271909999159, 0.4472135954999579), b.normal(0.0)) + assertEquals(MPoint(-0.0, 1.0), b.normal(0.5)) + assertEquals(MPoint(0.8944271909999159, 0.4472135954999579), b.normal(1.0)) } @Test @@ -48,15 +48,15 @@ class BezierCurveQuadraticTest { @Test fun testHasTheCorrectAxisAlignedBoundingBox() { assertEquals( - Rectangle.fromBounds(0.0, 0.0, 1.0, 0.5), + MRectangle.fromBounds(0.0, 0.0, 1.0, 0.5), b.boundingBox ) } @Test fun testFromPointSet() { - val M = Point(75, 25) - val pts = listOf(Point(0, 0), M, Point(100, 100)) + val M = MPoint(75, 25) + val pts = listOf(MPoint(0, 0), M, MPoint(100, 100)) run { val b = Bezier.quadraticFromPoints(pts[0], pts[1], pts[2]) diff --git a/korma/src/commonTest/kotlin/com/soywiz/korma/geom/bezier/BezierCurveTest.kt b/korma/src/commonTest/kotlin/com/soywiz/korma/geom/bezier/BezierCurveTest.kt index be92f48686..f0ac5fb8ec 100644 --- a/korma/src/commonTest/kotlin/com/soywiz/korma/geom/bezier/BezierCurveTest.kt +++ b/korma/src/commonTest/kotlin/com/soywiz/korma/geom/bezier/BezierCurveTest.kt @@ -1,9 +1,9 @@ package com.soywiz.korma.geom.bezier import com.soywiz.kds.* -import com.soywiz.korma.geom.Line -import com.soywiz.korma.geom.Point -import com.soywiz.korma.geom.Rectangle +import com.soywiz.korma.geom.MLine +import com.soywiz.korma.geom.MPoint +import com.soywiz.korma.geom.MRectangle import com.soywiz.korma.geom.clone import com.soywiz.korma.geom.mutable import com.soywiz.korma.geom.pointArrayListOf @@ -14,31 +14,31 @@ import kotlin.test.assertEquals class BezierCurveTest { @Test fun testBezierSimple() { - val curve = Bezier(Point(0, 0), Point(-50, -200), Point(150, 150), Point(110, 120)) + val curve = Bezier(MPoint(0, 0), MPoint(-50, -200), MPoint(150, 150), MPoint(110, 120)) assertEquals( - Bezier.ProjectedPoint(p=Point(-6.66, -31.89), t=0.06, dSq=181.61), - curve.project(Point(-20, -30)).roundDecimalPlaces(2) + Bezier.ProjectedPoint(p=MPoint(-6.66, -31.89), t=0.06, dSq=181.61), + curve.project(MPoint(-20, -30)).roundDecimalPlaces(2) ) } @Test fun testBezier() { //val curve = Bezier(PointArrayList(Point(0, 0), Point(100, 100), Point(150, 150), Point(250, 300))) - val curve = Bezier(Point(0, 0), Point(-50, -200), Point(150, 150), Point(110, 120)) + val curve = Bezier(MPoint(0, 0), MPoint(-50, -200), MPoint(150, 150), MPoint(110, 120)) //val curve = Bezier(PointArrayList(Point(0, 0), Point(100, 100), Point(250, 300))) assertEquals("[(0, 0), (-50, -200), (150, 150), (110, 120)]", curve.points.toString()) assertEquals("[[(-150, -600), (600, 1050), (-120, -90)], [(1500, 3300), (-1440, -2280)], [(-2940, -5580)]]", curve.dpoints.toString()) - assertEquals(Point(-150, -600), curve.derivative(0.0)) - assertEquals(Point(232.5, 352.5), curve.derivative(0.5)) - assertEquals(Point(-120, -90), curve.derivative(1.0)) + assertEquals(MPoint(-150, -600), curve.derivative(0.0)) + assertEquals(MPoint(232.5, 352.5), curve.derivative(0.5)) + assertEquals(MPoint(-120, -90), curve.derivative(1.0)) - assertEquals(Point(0.97, -0.24), curve.normal(0.0).mutable.setToRoundDecimalPlaces(2)) - assertEquals(Point(-0.83, 0.55), curve.normal(0.5).mutable.setToRoundDecimalPlaces(2)) - assertEquals(Point(0.6, -0.8), curve.normal(1.0)) + assertEquals(MPoint(0.97, -0.24), curve.normal(0.0).mutable.setToRoundDecimalPlaces(2)) + assertEquals(MPoint(-0.83, 0.55), curve.normal(0.5).mutable.setToRoundDecimalPlaces(2)) + assertEquals(MPoint(0.6, -0.8), curve.normal(1.0)) - assertEquals(Point(0, 0), curve.compute(0.0)) - assertEquals(Point(51.25, -3.75), curve.compute(0.5)) - assertEquals(Point(110, 120), curve.compute(1.0)) + assertEquals(MPoint(0, 0), curve.compute(0.0)) + assertEquals(MPoint(51.25, -3.75), curve.compute(0.5)) + assertEquals(MPoint(110, 120), curve.compute(1.0)) assertEquals(292.8273626504729, curve.length, 0.00001) assertEquals( @@ -52,16 +52,16 @@ class BezierCurveTest { assertEquals(101, curve.getLUT().size) assertEquals( - Rectangle(x=-8.08, y=-62.06, width=123.41, height=183.90), + MRectangle(x=-8.08, y=-62.06, width=123.41, height=183.90), curve.boundingBox.mutable.roundDecimalPlaces(2) ) assertEquals( - pointArrayListOf(Point(0, 0), Point(-50, -200), Point(150, 150), Point(110, 120), Point(-25, -100), Point(50, -25), Point(130, 135), Point(12.5, -62.5), Point(90, 55), Point(51.25, -3.75)), + pointArrayListOf(MPoint(0, 0), MPoint(-50, -200), MPoint(150, 150), MPoint(110, 120), MPoint(-25, -100), MPoint(50, -25), MPoint(130, 135), MPoint(12.5, -62.5), MPoint(90, 55), MPoint(51.25, -3.75)), curve.hull(0.5) ) assertEquals( - Bezier.ProjectedPoint(p=Point(-6.66, -31.89), t=0.06, dSq=181.61), - curve.project(Point(-20, -30)).roundDecimalPlaces(2) + Bezier.ProjectedPoint(p=MPoint(-6.66, -31.89), t=0.06, dSq=181.61), + curve.project(MPoint(-20, -30)).roundDecimalPlaces(2) ) assertEquals( "CurveSplit(base=Bezier([(0, 0), (-50, -200), (150, 150), (110, 120)]), left=SubBezier[0..0.5](Bezier([(0, 0), (-25, -100), (12.5, -62.5), (51.25, -3.75)])), right=SubBezier[0.5..1](Bezier([(51.25, -3.75), (90, 55), (130, 135), (110, 120)])), t=0.5, hull=[(0, 0), (-50, -200), (150, 150), (110, 120), (-25, -100), (50, -25), (130, 135), (12.5, -62.5), (90, 55), (51.25, -3.75)])", @@ -80,17 +80,17 @@ class BezierCurveTest { @Test fun testBezierBoundingBox() { assertEquals( - Rectangle(x=-4.044654662829129, y=-62.06241698807055, width=2.6127315550921892, height=0.6955056507112474).clone().roundDecimalPlaces(2), + MRectangle(x=-4.044654662829129, y=-62.06241698807055, width=2.6127315550921892, height=0.6955056507112474).clone().roundDecimalPlaces(2), Bezier( - Point(-4.044654662829129, -61.366911337359305), - Point(-3.2722813703417932, -61.83588230138613), - Point(-2.398578099496581, -62.06241698807055), - Point(-1.4319231077369396, -62.06241698807055), + MPoint(-4.044654662829129, -61.366911337359305), + MPoint(-3.2722813703417932, -61.83588230138613), + MPoint(-2.398578099496581, -62.06241698807055), + MPoint(-1.4319231077369396, -62.06241698807055), ).boundingBox.clone().roundDecimalPlaces(2) ) assertEquals( - Rectangle(65.0, 25.0, 37.2, 116.6), + MRectangle(65.0, 25.0, 37.2, 116.6), Bezier(100,25 , 10,180 , 170,165 , 65,70).boundingBox.clone().roundDecimalPlaces(1) ) } @@ -103,7 +103,7 @@ class BezierCurveTest { ) assertEquals( listOf(), - Bezier(Point(0, 0), Point(-50, -200), Point(150, 150), Point(110, 120)).selfIntersections().toList() + Bezier(MPoint(0, 0), MPoint(-50, -200), MPoint(150, 150), MPoint(110, 120)).selfIntersections().toList() ) } @@ -152,11 +152,11 @@ class BezierCurveTest { @Test fun testBoundingBox() { assertEquals( - Rectangle(0.0, -37.5, 50.0, 37.5), + MRectangle(0.0, -37.5, 50.0, 37.5), Bezier(0,0, 0,-50, 50,-50, 50,0).boundingBox ) assertEquals( - Rectangle(0.0, -37.5, 50.0, 37.5), + MRectangle(0.0, -37.5, 50.0, 37.5), Bezier(0.0,0.0, 0.0,-50.0, 50.0,-50.0, 50.0,0.0).boundingBox ) } @@ -189,28 +189,28 @@ class BezierCurveTest { assertEquals( listOf( Bezier( - Point(0.0, 0.0), - Point(0.0, -18.25000000000001), - Point(6.661250000000008, -29.838750000000015), - Point(15.121037500000018, -34.766250000000014), + MPoint(0.0, 0.0), + MPoint(0.0, -18.25000000000001), + MPoint(6.661250000000008, -29.838750000000015), + MPoint(15.121037500000018, -34.766250000000014), ), Bezier( - Point(15.121037500000018, -34.766250000000014), - Point(18.250000000000014, -36.588750000000005), - Point(21.625000000000007, -37.5), - Point(25.0, -37.5), + MPoint(15.121037500000018, -34.766250000000014), + MPoint(18.250000000000014, -36.588750000000005), + MPoint(21.625000000000007, -37.5), + MPoint(25.0, -37.5), ), Bezier( - Point(25.0, -37.5 ), - Point(32.125, -37.5 ), - Point(39.25, -33.43875 ), - Point(44.0600875, -25.31624999999999) + MPoint(25.0, -37.5 ), + MPoint(32.125, -37.5 ), + MPoint(39.25, -33.43875 ), + MPoint(44.0600875, -25.31624999999999) ), Bezier( - Point(44.0600875, -25.31624999999999), - Point(47.68875, -19.188749999999988), - Point(50.0, -10.749999999999993), - Point(50, 0) + MPoint(44.0600875, -25.31624999999999), + MPoint(47.68875, -19.188749999999988), + MPoint(50.0, -10.749999999999993), + MPoint(50, 0) ) ), curves.map { it.curve } @@ -241,7 +241,7 @@ class BezierCurveTest { @Test fun testLineCurveIntersection() { val b = Bezier(76, 250, 77, 150, 220, 50); - val line = Line(13, 140, 213, 140) + val line = MLine(13, 140, 213, 140) val intersections = b.intersections(line) assertEquals(listOf(0.55), intersections.toList()) } @@ -250,8 +250,8 @@ class BezierCurveTest { fun testProjectsOntoTheCorrectOnCurvePoint() { val b = Bezier(0, 0, 100, 0, 100, 100) assertEquals( - Bezier.ProjectedPoint(p = Point(75, 25), t = 0.5, dSq = 50.0), - b.project(Point(80, 20)) + Bezier.ProjectedPoint(p = MPoint(75, 25), t = 0.5, dSq = 50.0), + b.project(MPoint(80, 20)) ) } diff --git a/korma/src/commonTest/kotlin/com/soywiz/korma/geom/bezier/BezierTest.kt b/korma/src/commonTest/kotlin/com/soywiz/korma/geom/bezier/BezierTest.kt index 4e60e6639d..5f90c53e52 100644 --- a/korma/src/commonTest/kotlin/com/soywiz/korma/geom/bezier/BezierTest.kt +++ b/korma/src/commonTest/kotlin/com/soywiz/korma/geom/bezier/BezierTest.kt @@ -1,7 +1,7 @@ package com.soywiz.korma.geom.bezier -import com.soywiz.korma.geom.Point -import com.soywiz.korma.geom.Rectangle +import com.soywiz.korma.geom.MPoint +import com.soywiz.korma.geom.MRectangle import com.soywiz.korma.geom.map import com.soywiz.korma.geom.shape.buildVectorPath import com.soywiz.korma.geom.vector.getCurves @@ -15,10 +15,10 @@ import kotlin.test.assertEquals class BezierTest { @Test fun testLength() { - assertEquals(100.0, Bezier(Point(0, 0), Point(50, 0), Point(100, 0)).length) - val bezier = Bezier(Point(0, 0), Point(50, 0), Point(100, 0)) + assertEquals(100.0, Bezier(MPoint(0, 0), MPoint(50, 0), MPoint(100, 0)).length) + val bezier = Bezier(MPoint(0, 0), MPoint(50, 0), MPoint(100, 0)) assertEquals(100.0, bezier.length) - bezier.setPoints(Point(0, 0), Point(100, 0), Point(100, 100)) + bezier.setPoints(MPoint(0, 0), MPoint(100, 0), MPoint(100, 100)) assertEquals(162.32, bezier.length.roundDecimalPlaces(2)) } @@ -31,7 +31,7 @@ class BezierTest { } val curves = path.getCurves() assertEquals(590.0, curves.length, 0.4) - assertEquals(Rectangle(200, 100, 200, 180), curves.getBounds()) + assertEquals(MRectangle(200, 100, 200, 180), curves.getBounds()) assertEquals( """ (200, 200) @@ -67,14 +67,14 @@ class BezierTest { } val curves = path.getCurvesList() assertEquals(2, curves.size) - assertEquals(Rectangle(0, 0, 100, 100), curves[0].getBounds()) - assertEquals(Rectangle(300, 0, 100, 100), curves[1].getBounds()) - assertEquals(Rectangle(0, 0, 400, 100), curves.toCurves().getBounds()) + assertEquals(MRectangle(0, 0, 100, 100), curves[0].getBounds()) + assertEquals(MRectangle(300, 0, 100, 100), curves[1].getBounds()) + assertEquals(MRectangle(0, 0, 400, 100), curves.toCurves().getBounds()) } @Test fun testTangent() { - val bezier = Bezier(Point(74.58, 36.96), Point(74.58, 36.96), Point(77.04, 27.36), Point(71.76, 32.64)) - assertEquals(Point(0.2482, -0.9687), bezier.tangent(0.0).setToRoundDecimalPlaces(4)) + val bezier = Bezier(MPoint(74.58, 36.96), MPoint(74.58, 36.96), MPoint(77.04, 27.36), MPoint(71.76, 32.64)) + assertEquals(MPoint(0.2482, -0.9687), bezier.tangent(0.0).setToRoundDecimalPlaces(4)) } } diff --git a/korma/src/commonTest/kotlin/com/soywiz/korma/geom/binpack/BinPackerTest.kt b/korma/src/commonTest/kotlin/com/soywiz/korma/geom/binpack/BinPackerTest.kt index 0b0497d0b4..c5ff70d3a7 100644 --- a/korma/src/commonTest/kotlin/com/soywiz/korma/geom/binpack/BinPackerTest.kt +++ b/korma/src/commonTest/kotlin/com/soywiz/korma/geom/binpack/BinPackerTest.kt @@ -1,6 +1,6 @@ package com.soywiz.korma.geom.binpack -import com.soywiz.korma.geom.Size +import com.soywiz.korma.geom.MSize import kotlin.test.Test import kotlin.test.assertEquals @@ -8,7 +8,7 @@ class BinPackerTest { @Test fun name() { val packer = BinPacker(100, 100) - val result = packer.addBatch(listOf(Size(20, 10), Size(10, 30), Size(100, 20), Size(20, 80))) + val result = packer.addBatch(listOf(MSize(20, 10), MSize(10, 30), MSize(100, 20), MSize(20, 80))) assertEquals( "[Rectangle(x=20, y=50, width=20, height=10), Rectangle(x=20, y=20, width=10, height=30), Rectangle(x=0, y=0, width=100, height=20), Rectangle(x=0, y=20, width=20, height=80)]", result.toString() @@ -20,7 +20,7 @@ class BinPackerTest { val packs = BinPacker.packSeveral( 10, 10, - listOf(Size(10, 10), Size(5, 5), Size(5, 5), Size(5, 5), Size(5, 5), Size(10, 5), Size(5, 10), Size(5, 5)) + listOf(MSize(10, 10), MSize(5, 5), MSize(5, 5), MSize(5, 5), MSize(5, 5), MSize(10, 5), MSize(5, 10), MSize(5, 5)) ) assertEquals(4, packs.size) @@ -48,7 +48,7 @@ class BinPackerTest { @Test fun packZero() { - val packs = BinPacker.packSeveral(10, 10, listOf(Size(0, 0))) + val packs = BinPacker.packSeveral(10, 10, listOf(MSize(0, 0))) assertEquals(1, packs.size) assertEquals("[Rectangle(x=0, y=0, width=0, height=0)]", packs[0].rectsStr) } diff --git a/korma/src/commonTest/kotlin/com/soywiz/korma/geom/ds/Array2ExtTest.kt b/korma/src/commonTest/kotlin/com/soywiz/korma/geom/ds/Array2ExtTest.kt index 14d28b6560..825b412287 100644 --- a/korma/src/commonTest/kotlin/com/soywiz/korma/geom/ds/Array2ExtTest.kt +++ b/korma/src/commonTest/kotlin/com/soywiz/korma/geom/ds/Array2ExtTest.kt @@ -1,7 +1,7 @@ package com.soywiz.korma.geom.ds import com.soywiz.kds.Array2 -import com.soywiz.korma.geom.PointInt +import com.soywiz.korma.geom.MPointInt import kotlin.test.Test import kotlin.test.assertEquals @@ -10,7 +10,7 @@ class Array2ExtTest { @Test fun test() { - array[PointInt(5, 5)] = 10 + array[MPointInt(5, 5)] = 10 assertEquals(10, array[5, 5]) } } diff --git a/korma/src/commonTest/kotlin/com/soywiz/korma/geom/ds/BVHTest.kt b/korma/src/commonTest/kotlin/com/soywiz/korma/geom/ds/BVHTest.kt index 9e4a76191e..b996c2b0f2 100644 --- a/korma/src/commonTest/kotlin/com/soywiz/korma/geom/ds/BVHTest.kt +++ b/korma/src/commonTest/kotlin/com/soywiz/korma/geom/ds/BVHTest.kt @@ -9,12 +9,12 @@ class BVHTest { val tree = BVH2D() //for (n in 0 until 1_000_000) tree.insert(Rectangle(n * 5, 5, 10, 10), "$n") //for (n in 0 until 10_000_000) tree.insert(Rectangle(n * 5, 5, 10, 10), "$n") - tree.insertOrUpdate(Rectangle(20, 15, 20, 20), "1") - tree.insertOrUpdate(Rectangle(50, 50, 20, 20), "2") + tree.insertOrUpdate(MRectangle(20, 15, 20, 20), "1") + tree.insertOrUpdate(MRectangle(50, 50, 20, 20), "2") //tree.remove(Rectangle(20, 15, 20, 20), "1") - val intersection = tree.intersect(Ray(Point(25, 100), Vector2D(0, -1))) - val rectSearch = tree.search(Rectangle(0.0, 0.0, 60.0, 60.0)) + val intersection = tree.intersect(Ray(MPoint(25, 100), MVector2D(0, -1))) + val rectSearch = tree.search(MRectangle(0.0, 0.0, 60.0, 60.0)) //assertEquals(1, intersection.size) //assertEquals(2, rectSearch.size) diff --git a/korma/src/commonTest/kotlin/com/soywiz/korma/geom/shape/Shape2dTest.kt b/korma/src/commonTest/kotlin/com/soywiz/korma/geom/shape/Shape2dTest.kt index aa9d345f7b..adb325c396 100644 --- a/korma/src/commonTest/kotlin/com/soywiz/korma/geom/shape/Shape2dTest.kt +++ b/korma/src/commonTest/kotlin/com/soywiz/korma/geom/shape/Shape2dTest.kt @@ -1,6 +1,6 @@ package com.soywiz.korma.geom.shape -import com.soywiz.korma.geom.Point +import com.soywiz.korma.geom.MPoint import com.soywiz.korma.geom.PointArrayList import com.soywiz.korma.geom.map import com.soywiz.korma.geom.shape.ops.extend @@ -48,10 +48,10 @@ class Shape2dTest { @Test fun test_ToRectangleOrNull() { - val a = Point(1.0, 1.0) - val b = Point(1.0, 2.0) - val c = Point(2.0, 2.0) - val d = Point(2.0, 1.0) + val a = MPoint(1.0, 1.0) + val b = MPoint(1.0, 2.0) + val c = MPoint(2.0, 2.0) + val d = MPoint(2.0, 1.0) assertNotNull(PointArrayList(a, b, c, d).toRectangleOrNull()) assertNotNull(PointArrayList(d, a, b, c).toRectangleOrNull()) @@ -73,14 +73,14 @@ class Shape2dTest { assertNull(PointArrayList(a, a, a, a).toRectangleOrNull()) - assertNull(PointArrayList(Point(0.0, 1.0), Point(1.0, 2.0), Point(2.0, 2.0), Point(2.0, 1.0)).toRectangleOrNull()) - assertNull(PointArrayList(Point(1.0, 1.0), Point(0.0, 2.0), Point(2.0, 2.0), Point(2.0, 1.0)).toRectangleOrNull()) - assertNull(PointArrayList(Point(1.0, 1.0), Point(1.0, 2.0), Point(0.0, 2.0), Point(2.0, 1.0)).toRectangleOrNull()) - assertNull(PointArrayList(Point(1.0, 1.0), Point(1.0, 2.0), Point(2.0, 2.0), Point(0.0, 1.0)).toRectangleOrNull()) - assertNull(PointArrayList(Point(1.0, 0.0), Point(1.0, 2.0), Point(2.0, 2.0), Point(2.0, 1.0)).toRectangleOrNull()) - assertNull(PointArrayList(Point(1.0, 1.0), Point(1.0, 0.0), Point(2.0, 2.0), Point(2.0, 1.0)).toRectangleOrNull()) - assertNull(PointArrayList(Point(1.0, 1.0), Point(1.0, 2.0), Point(2.0, 0.0), Point(2.0, 1.0)).toRectangleOrNull()) - assertNull(PointArrayList(Point(1.0, 1.0), Point(1.0, 2.0), Point(2.0, 2.0), Point(2.0, 0.0)).toRectangleOrNull()) + assertNull(PointArrayList(MPoint(0.0, 1.0), MPoint(1.0, 2.0), MPoint(2.0, 2.0), MPoint(2.0, 1.0)).toRectangleOrNull()) + assertNull(PointArrayList(MPoint(1.0, 1.0), MPoint(0.0, 2.0), MPoint(2.0, 2.0), MPoint(2.0, 1.0)).toRectangleOrNull()) + assertNull(PointArrayList(MPoint(1.0, 1.0), MPoint(1.0, 2.0), MPoint(0.0, 2.0), MPoint(2.0, 1.0)).toRectangleOrNull()) + assertNull(PointArrayList(MPoint(1.0, 1.0), MPoint(1.0, 2.0), MPoint(2.0, 2.0), MPoint(0.0, 1.0)).toRectangleOrNull()) + assertNull(PointArrayList(MPoint(1.0, 0.0), MPoint(1.0, 2.0), MPoint(2.0, 2.0), MPoint(2.0, 1.0)).toRectangleOrNull()) + assertNull(PointArrayList(MPoint(1.0, 1.0), MPoint(1.0, 0.0), MPoint(2.0, 2.0), MPoint(2.0, 1.0)).toRectangleOrNull()) + assertNull(PointArrayList(MPoint(1.0, 1.0), MPoint(1.0, 2.0), MPoint(2.0, 0.0), MPoint(2.0, 1.0)).toRectangleOrNull()) + assertNull(PointArrayList(MPoint(1.0, 1.0), MPoint(1.0, 2.0), MPoint(2.0, 2.0), MPoint(2.0, 0.0)).toRectangleOrNull()) } @Test diff --git a/korma/src/commonTest/kotlin/com/soywiz/korma/geom/slice/SliceOrientationTest.kt b/korma/src/commonTest/kotlin/com/soywiz/korma/geom/slice/SliceOrientationTest.kt index 72e2e0766a..c16353cc42 100644 --- a/korma/src/commonTest/kotlin/com/soywiz/korma/geom/slice/SliceOrientationTest.kt +++ b/korma/src/commonTest/kotlin/com/soywiz/korma/geom/slice/SliceOrientationTest.kt @@ -63,17 +63,17 @@ class SliceOrientationTest { @Test fun testXY() { - assertEquals(PointInt(2, 1), SliceOrientation().getXY(10, 13, 2, 1)) - assertEquals(PointInt(7, 1), SliceOrientation(flipX = true).getXY(10, 13, 2, 1)) - assertEquals(PointInt(2, 11), SliceOrientation().flippedY().getXY(10, 13, 2, 1)) + assertEquals(MPointInt(2, 1), SliceOrientation().getXY(10, 13, 2, 1)) + assertEquals(MPointInt(7, 1), SliceOrientation(flipX = true).getXY(10, 13, 2, 1)) + assertEquals(MPointInt(2, 11), SliceOrientation().flippedY().getXY(10, 13, 2, 1)) - assertEquals(PointInt(0, 0), SliceOrientation(rotation = SliceRotation.R0).getXY(10, 13, 0, 0)) - assertEquals(PointInt(12, 0), SliceOrientation(rotation = SliceRotation.R90).getXY(10, 13, 0, 0)) - assertEquals(PointInt(9, 12), SliceOrientation(rotation = SliceRotation.R180).getXY(10, 13, 0, 0)) - assertEquals(PointInt(0, 9), SliceOrientation(rotation = SliceRotation.R270).getXY(10, 13, 0, 0)) + assertEquals(MPointInt(0, 0), SliceOrientation(rotation = SliceRotation.R0).getXY(10, 13, 0, 0)) + assertEquals(MPointInt(12, 0), SliceOrientation(rotation = SliceRotation.R90).getXY(10, 13, 0, 0)) + assertEquals(MPointInt(9, 12), SliceOrientation(rotation = SliceRotation.R180).getXY(10, 13, 0, 0)) + assertEquals(MPointInt(0, 9), SliceOrientation(rotation = SliceRotation.R270).getXY(10, 13, 0, 0)) - assertEquals(PointInt(11, 2), SliceOrientation(rotation = SliceRotation.R90).getXY(10, 13, 2, 1)) - assertEquals(PointInt(7, 11), SliceOrientation(rotation = SliceRotation.R180).getXY(10, 13, 2, 1)) - assertEquals(PointInt(1, 7), SliceOrientation(rotation = SliceRotation.R270).getXY(10, 13, 2, 1)) + assertEquals(MPointInt(11, 2), SliceOrientation(rotation = SliceRotation.R90).getXY(10, 13, 2, 1)) + assertEquals(MPointInt(7, 11), SliceOrientation(rotation = SliceRotation.R180).getXY(10, 13, 2, 1)) + assertEquals(MPointInt(1, 7), SliceOrientation(rotation = SliceRotation.R270).getXY(10, 13, 2, 1)) } } diff --git a/korma/src/commonTest/kotlin/com/soywiz/korma/geom/triangle/EdgeTest.kt b/korma/src/commonTest/kotlin/com/soywiz/korma/geom/triangle/EdgeTest.kt index c927365b68..f1c3f41c05 100644 --- a/korma/src/commonTest/kotlin/com/soywiz/korma/geom/triangle/EdgeTest.kt +++ b/korma/src/commonTest/kotlin/com/soywiz/korma/geom/triangle/EdgeTest.kt @@ -1,29 +1,29 @@ package com.soywiz.korma.geom.triangle -import com.soywiz.korma.geom.Point +import com.soywiz.korma.geom.MPoint import kotlin.test.Test import kotlin.test.assertEquals class EdgeTest { @Test fun string() { - assertEquals("Edge((1, 2), (3, 4))", Edge(Point(1, 2), Point(3, 4)).toString()) + assertEquals("Edge((1, 2), (3, 4))", Edge(MPoint(1, 2), MPoint(3, 4)).toString()) } @Test fun equality() { - val e1 = Edge(Point(1, 1), Point(2, 2)) - val e2 = Edge(Point(1, 1), Point(2, 2)) - val e3 = Edge(Point(2, 2), Point(1, 1)) + val e1 = Edge(MPoint(1, 1), MPoint(2, 2)) + val e2 = Edge(MPoint(1, 1), MPoint(2, 2)) + val e3 = Edge(MPoint(2, 2), MPoint(1, 1)) assertEquals(e1, e2) assertEquals(e1, e3) } @Test fun unique() { - val e1 = Edge(Point(1, 1), Point(2, 2)) - val e2 = Edge(Point(2, 2), Point(3, 3)) - val e3 = Edge(Point(3, 3), Point(1, 1)) - assertEquals(listOf(Point(1, 1), Point(2, 2), Point(3, 3)), Edge.getUniquePointsFromEdges(listOf(e1, e2, e3))) + val e1 = Edge(MPoint(1, 1), MPoint(2, 2)) + val e2 = Edge(MPoint(2, 2), MPoint(3, 3)) + val e3 = Edge(MPoint(3, 3), MPoint(1, 1)) + assertEquals(listOf(MPoint(1, 1), MPoint(2, 2), MPoint(3, 3)), Edge.getUniquePointsFromEdges(listOf(e1, e2, e3))) } } diff --git a/korma/src/commonTest/kotlin/com/soywiz/korma/geom/triangle/TriangleTest.kt b/korma/src/commonTest/kotlin/com/soywiz/korma/geom/triangle/TriangleTest.kt index 50054f9d5e..11fa1e0a69 100644 --- a/korma/src/commonTest/kotlin/com/soywiz/korma/geom/triangle/TriangleTest.kt +++ b/korma/src/commonTest/kotlin/com/soywiz/korma/geom/triangle/TriangleTest.kt @@ -1,70 +1,70 @@ package com.soywiz.korma.geom.triangle -import com.soywiz.korma.geom.Point +import com.soywiz.korma.geom.MPoint import com.soywiz.korma.geom.assertEquals import kotlin.test.Test import kotlin.test.assertEquals class TriangleTest { - val t1 = Triangle(Point(0, 0), Point(10, 0), Point(0, 10)) - val t2 = Triangle(Point(0, 10), Point(10, 0), Point(10, 10)) + val t1 = Triangle(MPoint(0, 0), MPoint(10, 0), MPoint(0, 10)) + val t2 = Triangle(MPoint(0, 10), MPoint(10, 0), MPoint(10, 10)) @Test fun test() { assertEquals(50.0, t1.area) - assertEquals(0, t1.index(Point(0, 0))) - assertEquals(1, t1.index(Point(10, 0))) - assertEquals(2, t1.index(Point(0, 10))) + assertEquals(0, t1.index(MPoint(0, 0))) + assertEquals(1, t1.index(MPoint(10, 0))) + assertEquals(2, t1.index(MPoint(0, 10))) - assertEquals(2, t1.edgeIndex(Point(0, 0), Point(10, 0))) - assertEquals(0, t1.edgeIndex(Point(10, 0), Point(0, 10))) - assertEquals(1, t1.edgeIndex(Point(0, 10), Point(0, 0))) + assertEquals(2, t1.edgeIndex(MPoint(0, 0), MPoint(10, 0))) + assertEquals(0, t1.edgeIndex(MPoint(10, 0), MPoint(0, 10))) + assertEquals(1, t1.edgeIndex(MPoint(0, 10), MPoint(0, 0))) - assertEquals(true, t1.containsPoint(Point(0, 0))) - assertEquals(true, t1.containsPoint(Point(10, 0))) - assertEquals(true, t1.containsPoint(Point(0, 10))) - assertEquals(false, t1.containsPoint(Point(10, 10))) + assertEquals(true, t1.containsPoint(MPoint(0, 0))) + assertEquals(true, t1.containsPoint(MPoint(10, 0))) + assertEquals(true, t1.containsPoint(MPoint(0, 10))) + assertEquals(false, t1.containsPoint(MPoint(10, 10))) - assertEquals(Point(0, 0), t1.point(0)) - assertEquals(Point(10, 0), t1.point(1)) - assertEquals(Point(0, 10), t1.point(2)) + assertEquals(MPoint(0, 0), t1.point(0)) + assertEquals(MPoint(10, 0), t1.point(1)) + assertEquals(MPoint(0, 10), t1.point(2)) - assertEquals(Point(0, 0), t1.p0) - assertEquals(Point(10, 0), t1.p1) - assertEquals(Point(0, 10), t1.p2) + assertEquals(MPoint(0, 0), t1.p0) + assertEquals(MPoint(10, 0), t1.p1) + assertEquals(MPoint(0, 10), t1.p2) assertEquals("[(0, 0), (10, 0), (0, 10), (10, 10)]", Triangle.getUniquePointsFromTriangles(listOf(t1, t2)).toString()) - assertEquals(true, t1.containsEdge(Edge(Point(0, 0), Point(10, 0)))) - assertEquals(true, t1.containsEdge(Edge(Point(10, 0), Point(0, 10)))) - assertEquals(true, t1.containsEdge(Edge(Point(0, 0), Point(0, 10)))) - assertEquals(false, t2.containsEdge(Edge(Point(0, 0), Point(0, 10)))) + assertEquals(true, t1.containsEdge(Edge(MPoint(0, 0), MPoint(10, 0)))) + assertEquals(true, t1.containsEdge(Edge(MPoint(10, 0), MPoint(0, 10)))) + assertEquals(true, t1.containsEdge(Edge(MPoint(0, 0), MPoint(0, 10)))) + assertEquals(false, t2.containsEdge(Edge(MPoint(0, 0), MPoint(0, 10)))) } @Test fun inside() { // Edges - assertEquals(true, t1.pointInsideTriangle(Point(0, 0))) - assertEquals(true, t1.pointInsideTriangle(Point(10, 0))) - assertEquals(true, t1.pointInsideTriangle(Point(0, 10))) + assertEquals(true, t1.pointInsideTriangle(MPoint(0, 0))) + assertEquals(true, t1.pointInsideTriangle(MPoint(10, 0))) + assertEquals(true, t1.pointInsideTriangle(MPoint(0, 10))) - assertEquals(true, t1.pointInsideTriangle(Point(2, 2))) + assertEquals(true, t1.pointInsideTriangle(MPoint(2, 2))) - assertEquals(false, t1.pointInsideTriangle(Point(-2, -2))) - assertEquals(false, t1.pointInsideTriangle(Point(2, -2))) - assertEquals(false, t1.pointInsideTriangle(Point(-2, 2))) + assertEquals(false, t1.pointInsideTriangle(MPoint(-2, -2))) + assertEquals(false, t1.pointInsideTriangle(MPoint(2, -2))) + assertEquals(false, t1.pointInsideTriangle(MPoint(-2, 2))) } @Test fun extra() { - assertEquals(Point(0, 10), t1.pointCW(Point(0, 0))) - assertEquals(Point(10, 0), t1.pointCCW(Point(0, 0))) + assertEquals(MPoint(0, 10), t1.pointCW(MPoint(0, 0))) + assertEquals(MPoint(10, 0), t1.pointCCW(MPoint(0, 0))) - assertEquals(Point(0, 0), t1.pointCW(Point(10, 0))) - assertEquals(Point(0, 10), t1.pointCCW(Point(10, 0))) + assertEquals(MPoint(0, 0), t1.pointCW(MPoint(10, 0))) + assertEquals(MPoint(0, 10), t1.pointCCW(MPoint(10, 0))) - assertEquals(Point(10, 0), t1.pointCW(Point(0, 10))) - assertEquals(Point(0, 0), t1.pointCCW(Point(0, 10))) + assertEquals(MPoint(10, 0), t1.pointCW(MPoint(0, 10))) + assertEquals(MPoint(0, 0), t1.pointCCW(MPoint(0, 10))) } } diff --git a/korma/src/commonTest/kotlin/com/soywiz/korma/geom/triangle/pathfind/SpatialMeshTest.kt b/korma/src/commonTest/kotlin/com/soywiz/korma/geom/triangle/pathfind/SpatialMeshTest.kt index a647f04c40..10b1bb1a2f 100644 --- a/korma/src/commonTest/kotlin/com/soywiz/korma/geom/triangle/pathfind/SpatialMeshTest.kt +++ b/korma/src/commonTest/kotlin/com/soywiz/korma/geom/triangle/pathfind/SpatialMeshTest.kt @@ -1,6 +1,6 @@ package com.soywiz.korma.geom.triangle.pathfind -import com.soywiz.korma.geom.Point +import com.soywiz.korma.geom.MPoint import com.soywiz.korma.geom.shape.* import com.soywiz.korma.geom.vector.* import com.soywiz.korma.triangle.pathfind.finder @@ -19,8 +19,8 @@ class SpatialMeshTest { }.triangulateSafe() val finder = triangles.spatialMesh().finder() - assertEquals("[(10, 10), (80, 20), (90, 90)]", "${finder.find(Point(10, 10), Point(90, 90))}") - assertEquals("[(90, 10), (80, 20), (90, 90)]", "${finder.find(Point(90, 10), Point(90, 90))}") - assertFailsWith("Point2d not inside triangles") { finder.find(Point(-10, -10), Point(90, 90)) } + assertEquals("[(10, 10), (80, 20), (90, 90)]", "${finder.find(MPoint(10, 10), MPoint(90, 90))}") + assertEquals("[(90, 10), (80, 20), (90, 90)]", "${finder.find(MPoint(90, 10), MPoint(90, 90))}") + assertFailsWith("Point2d not inside triangles") { finder.find(MPoint(-10, -10), MPoint(90, 90)) } } } diff --git a/korma/src/commonTest/kotlin/com/soywiz/korma/geom/triangle/triangulate/TriangulateTest.kt b/korma/src/commonTest/kotlin/com/soywiz/korma/geom/triangle/triangulate/TriangulateTest.kt index d78e4c1a74..139db62970 100644 --- a/korma/src/commonTest/kotlin/com/soywiz/korma/geom/triangle/triangulate/TriangulateTest.kt +++ b/korma/src/commonTest/kotlin/com/soywiz/korma/geom/triangle/triangulate/TriangulateTest.kt @@ -1,6 +1,6 @@ package com.soywiz.korma.geom.triangle.triangulate -import com.soywiz.korma.geom.Point +import com.soywiz.korma.geom.MPoint import com.soywiz.korma.triangle.triangulate.triangulate import kotlin.test.Test import kotlin.test.assertEquals @@ -20,11 +20,11 @@ class TriangulateTest { @Test fun test2() { val points = listOf( - Point(3, 10), - Point(1, 5), - Point(3, 1), - Point(4, 0), - Point(6, 0) + MPoint(3, 10), + MPoint(1, 5), + MPoint(3, 1), + MPoint(4, 0), + MPoint(6, 0) ) assertEquals( diff --git a/korma/src/commonTest/kotlin/com/soywiz/korma/geom/vector/EdgeTest.kt b/korma/src/commonTest/kotlin/com/soywiz/korma/geom/vector/EdgeTest.kt index d715fc846c..090455531f 100644 --- a/korma/src/commonTest/kotlin/com/soywiz/korma/geom/vector/EdgeTest.kt +++ b/korma/src/commonTest/kotlin/com/soywiz/korma/geom/vector/EdgeTest.kt @@ -1,6 +1,6 @@ package com.soywiz.korma.geom.vector -import com.soywiz.korma.geom.Point +import com.soywiz.korma.geom.MPoint import com.soywiz.korma.geom.assertEquals import com.soywiz.korma.geom.degrees import kotlin.test.Test @@ -13,8 +13,8 @@ class EdgeTest { val a = Edge(0, 10, 10, 0) val b = Edge(10, 0, 10, 10) val c = Edge().setToHalf(a, b) - assertEquals(Point(10, 0), Edge.getIntersectXY(a, b)) - assertEquals(Point(10, 0), Edge.getIntersectXY(a, c)) + assertEquals(MPoint(10, 0), Edge.getIntersectXY(a, b)) + assertEquals(MPoint(10, 0), Edge.getIntersectXY(a, c)) assertEquals(90.degrees, Edge.angleBetween(Edge(0, 0, 10, 0), Edge(10, 0, 10, 10))) } } diff --git a/korma/src/commonTest/kotlin/com/soywiz/korma/geom/vector/VectorBuilderTest.kt b/korma/src/commonTest/kotlin/com/soywiz/korma/geom/vector/VectorBuilderTest.kt index d947226c82..45f0111225 100644 --- a/korma/src/commonTest/kotlin/com/soywiz/korma/geom/vector/VectorBuilderTest.kt +++ b/korma/src/commonTest/kotlin/com/soywiz/korma/geom/vector/VectorBuilderTest.kt @@ -1,6 +1,6 @@ package com.soywiz.korma.geom.vector -import com.soywiz.korma.geom.Rectangle +import com.soywiz.korma.geom.MRectangle import com.soywiz.korma.geom.degrees import com.soywiz.korma.geom.shape.buildVectorPath import kotlin.test.Test @@ -9,9 +9,9 @@ import kotlin.test.assertEquals class VectorBuilderTest { @Test fun testParallelogram() { - assertEquals("M0,0 L100,0 L100,50 L0,50", buildVectorPath { parallelogram(Rectangle(0, 0, 100, 50), angle = 0.degrees, direction = true) }.toSvgString(), "angle of 0 generates a rectangle") - assertEquals("M0,0 L150,0 L100,50 L-50,50", buildVectorPath { parallelogram(Rectangle(0, 0, 100, 50), angle = 90.degrees, direction = true) }.toSvgString(), "angle of 90 with direction = true generates a parallelogram with lines doing a 45 degrees clockwise") - assertEquals("M-50,0 L100,0 L150,50 L0,50", buildVectorPath { parallelogram(Rectangle(0, 0, 100, 50), angle = 90.degrees, direction = false) }.toSvgString(), "angle of 90 with direction = false generates a parallelogram with lines doing a 45 degrees counter-clockwise") + assertEquals("M0,0 L100,0 L100,50 L0,50", buildVectorPath { parallelogram(MRectangle(0, 0, 100, 50), angle = 0.degrees, direction = true) }.toSvgString(), "angle of 0 generates a rectangle") + assertEquals("M0,0 L150,0 L100,50 L-50,50", buildVectorPath { parallelogram(MRectangle(0, 0, 100, 50), angle = 90.degrees, direction = true) }.toSvgString(), "angle of 90 with direction = true generates a parallelogram with lines doing a 45 degrees clockwise") + assertEquals("M-50,0 L100,0 L150,50 L0,50", buildVectorPath { parallelogram(MRectangle(0, 0, 100, 50), angle = 90.degrees, direction = false) }.toSvgString(), "angle of 90 with direction = false generates a parallelogram with lines doing a 45 degrees counter-clockwise") } @Test diff --git a/korma/src/commonTest/kotlin/com/soywiz/korma/geom/vector/VectorPathTest.kt b/korma/src/commonTest/kotlin/com/soywiz/korma/geom/vector/VectorPathTest.kt index 008d47720c..074f4122d7 100644 --- a/korma/src/commonTest/kotlin/com/soywiz/korma/geom/vector/VectorPathTest.kt +++ b/korma/src/commonTest/kotlin/com/soywiz/korma/geom/vector/VectorPathTest.kt @@ -1,7 +1,7 @@ package com.soywiz.korma.geom.vector -import com.soywiz.korma.geom.Matrix -import com.soywiz.korma.geom.Rectangle +import com.soywiz.korma.geom.MMatrix +import com.soywiz.korma.geom.MRectangle import com.soywiz.korma.geom.bezier.Bezier import com.soywiz.korma.geom.shape.buildVectorPath import kotlin.test.Test @@ -20,7 +20,7 @@ class VectorPathTest { assertEquals(true, g.containsPoint(50, 50)) assertEquals(false, g.containsPoint(150, 50)) - assertEquals(Rectangle(0, 0, 100, 100), g.getBounds()) + assertEquals(MRectangle(0, 0, 100, 100), g.getBounds()) } @Test @@ -56,7 +56,7 @@ class VectorPathTest { assertEquals(false, g.containsPoint(50, 50)) assertEquals(false, g.containsPoint(150, 50)) assertEquals(true, g.containsPoint(20, 50)) - assertEquals(Rectangle(0, 0, 100, 100), g.getBounds()) + assertEquals(MRectangle(0, 0, 100, 100), g.getBounds()) //g.filled(Context2d.Color(Colors.RED)).raster().showImageAndWaitExt() } @@ -179,7 +179,7 @@ class VectorPathTest { rect(110, 0, 100, 100) } - val path2b = path2.clone().applyTransform(Matrix().scale(2.0)) + val path2b = path2.clone().applyTransform(MMatrix().scale(2.0)) @Test fun testToString() { @@ -202,20 +202,20 @@ class VectorPathTest { fun testCollidesTransformed() { assertEquals(false, buildVectorPath(VectorPath()) { rect(0, 0, 15, 15) - }.intersectsWith(Matrix(), path2, Matrix().scale(2.0))) + }.intersectsWith(MMatrix(), path2, MMatrix().scale(2.0))) assertEquals(true, buildVectorPath(VectorPath()) { rect(0, 0, 15, 15) - }.intersectsWith(Matrix().scale(2.0, 2.0), path2, Matrix().scale(2.0))) + }.intersectsWith(MMatrix().scale(2.0, 2.0), path2, MMatrix().scale(2.0))) assertEquals(true, buildVectorPath(VectorPath()) { rect(0, 0, 15, 15) - }.intersectsWith(Matrix().scale(2.0, 2.0), path2, Matrix())) + }.intersectsWith(MMatrix().scale(2.0, 2.0), path2, MMatrix())) - assertEquals(true, VectorPath.intersects(path1, Matrix(), path1, Matrix())) - assertEquals(true, VectorPath.intersects(path1, Matrix().translate(101.0, 0.0), path1, Matrix().translate(101.0, 0.0))) - assertEquals(true, VectorPath.intersects(path1, Matrix().translate(50.0, 0.0), path1, Matrix().translate(100.0, 0.0))) - assertEquals(true, VectorPath.intersects(path1, Matrix().translate(100.0, 0.0), path1, Matrix().translate(50.0, 0.0))) - assertEquals(false, VectorPath.intersects(path1, Matrix().translate(101.0, 0.0), path1, Matrix())) - assertEquals(false, VectorPath.intersects(path1, Matrix(), path1, Matrix().translate(101.0, 0.0))) + assertEquals(true, VectorPath.intersects(path1, MMatrix(), path1, MMatrix())) + assertEquals(true, VectorPath.intersects(path1, MMatrix().translate(101.0, 0.0), path1, MMatrix().translate(101.0, 0.0))) + assertEquals(true, VectorPath.intersects(path1, MMatrix().translate(50.0, 0.0), path1, MMatrix().translate(100.0, 0.0))) + assertEquals(true, VectorPath.intersects(path1, MMatrix().translate(100.0, 0.0), path1, MMatrix().translate(50.0, 0.0))) + assertEquals(false, VectorPath.intersects(path1, MMatrix().translate(101.0, 0.0), path1, MMatrix())) + assertEquals(false, VectorPath.intersects(path1, MMatrix(), path1, MMatrix().translate(101.0, 0.0))) } @Test diff --git a/korma/src/jvmMain/kotlin/com/soywiz/korma/awt/AwtExt.kt b/korma/src/jvmMain/kotlin/com/soywiz/korma/awt/AwtExt.kt index e1c14f0490..7749199c32 100644 --- a/korma/src/jvmMain/kotlin/com/soywiz/korma/awt/AwtExt.kt +++ b/korma/src/jvmMain/kotlin/com/soywiz/korma/awt/AwtExt.kt @@ -1,25 +1,25 @@ package com.soywiz.korma.awt -import com.soywiz.korma.geom.Rectangle +import com.soywiz.korma.geom.MRectangle import com.soywiz.korma.geom.RectangleInt -import com.soywiz.korma.geom.Size +import com.soywiz.korma.geom.MSize import com.soywiz.korma.geom.setTo import java.awt.geom.Rectangle2D -fun Rectangle.toAwt(out: Rectangle2D.Float = Rectangle2D.Float()): Rectangle2D.Float = +fun MRectangle.toAwt(out: Rectangle2D.Float = Rectangle2D.Float()): Rectangle2D.Float = out.also { it.setRect(this.x.toFloat(), this.y.toFloat(), this.width.toFloat(), this.height.toFloat()) } fun RectangleInt.toAwt(out: java.awt.Rectangle = java.awt.Rectangle()): java.awt.Rectangle = out.also { out.setBounds(this.x, this.y, this.width, this.height) } -fun Rectangle2D.Float.toKorma(out: Rectangle = Rectangle()): Rectangle = +fun Rectangle2D.Float.toKorma(out: MRectangle = MRectangle()): MRectangle = out.also { it.setTo(this.x, this.y, this.width, this.height) } fun java.awt.Rectangle.toKorma(out: RectangleInt = RectangleInt()): RectangleInt = out.also { out.setTo(this.x, this.y, this.width, this.height) } -fun java.awt.geom.Dimension2D.toKorma(out: Size = Size()) = +fun java.awt.geom.Dimension2D.toKorma(out: MSize = MSize()) = out.also { out.setTo(this.width, this.height) } -fun Size.toAwt(out: java.awt.geom.Dimension2D = java.awt.Dimension()) = +fun MSize.toAwt(out: java.awt.geom.Dimension2D = java.awt.Dimension()) = out.also { out.setSize(this.width, this.height) }