From 74cfdb50a9c6dad3fb4f74ba3ccdb36719fc7854 Mon Sep 17 00:00:00 2001 From: Ben Highgate <91388545+Mageconvict@users.noreply.github.com> Date: Tue, 28 Mar 2023 19:53:04 +0100 Subject: [PATCH] test: added matrix 3x3 test (#1258) * began implementation of UI font size scaling --- .../fxgl/physics/box2d/common/Mat33Test.kt | 76 +++++++++++++++++++ .../ui/FXGLDialogFactoryServiceProvider.kt | 6 +- .../kotlin/com/almasb/fxgl/app/Settings.kt | 8 ++ 3 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 fxgl-entity/src/test/kotlin/com/almasb/fxgl/physics/box2d/common/Mat33Test.kt diff --git a/fxgl-entity/src/test/kotlin/com/almasb/fxgl/physics/box2d/common/Mat33Test.kt b/fxgl-entity/src/test/kotlin/com/almasb/fxgl/physics/box2d/common/Mat33Test.kt new file mode 100644 index 000000000..91055af7a --- /dev/null +++ b/fxgl-entity/src/test/kotlin/com/almasb/fxgl/physics/box2d/common/Mat33Test.kt @@ -0,0 +1,76 @@ +/* + * FXGL - JavaFX Game Library. The MIT License (MIT). + * Copyright (c) AlmasB (almaslvl@gmail.com). + * See LICENSE for details. + */ + +package com.almasb.fxgl.physics.box2d.common + +import com.almasb.fxgl.core.math.Vec3 +import org.hamcrest.CoreMatchers.* +import org.hamcrest.MatcherAssert.* +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test + +/** + * @author Ben Highgate (ben.highgate@gmail.com) + */ +class Mat33Test { + + @Test + fun `Matrix mul vector`() { + val mat = Mat33() + + mat.ex.set(3f, 4f, 2f) + mat.ey.set(6f, 2f, 5f) + mat.ez.set(4f, 3f, 3f) + + val v = Vec3(2f, 1f, 4f) + + // [ 3 6 4 ] x [ 2 ] = [ 28 ] + // [ 4 2 3 ] [ 1 ] [ 22 ] + // [ 2 5 3 ] [ 4 ] [ 21 ] + + val out = Vec3() + + Mat33.mulToOutUnsafe(mat, v, out) + + assertThat(out, `is`(Vec3(28f, 22f, 21f))) + } + + @Test + fun `Solve Ax = b`() { + val A = Mat33() + A.ex.set(3.0f, 4.0f, 2.0f) + A.ey.set(6.0f, 2.0f, 5.0f) + A.ez.set(4.0f, 3.0f, 3.0f) + + val b = Vec3(28.0f, 22.0f, 21.0f) + val out = Vec3() + + // [ 3 6 4 ] x [ 2 ] = [ 28 ] + // [ 4 2 3 ] [ 1 ] [ 22 ] + // [ 2 5 3 ] [ 4 ] [ 21 ] + + A.solve33ToOut(b, out) + + assertEquals(2.0f, out.x, 0.0001f) + assertEquals(1.0f, out.y, 0.0001f) + assertEquals(4.0f, out.z, 0.0001f) + } + + @Test + fun `Symmetrical Invert`() { + val A = Mat33() + A.ex.set(3.0f, 4.0f, 2.0f) + A.ey.set(6.0f, 2.0f, 5.0f) + A.ez.set(4.0f, 3.0f, 3.0f) + + val b = Mat33() + A.getSymInverse33(b) + + assertThat(b.ex, `is`(Vec3(-3.0f, -6.0f, 10.0f))) + assertThat(b.ey, `is`(Vec3(-6.0f, -7.0f, 15.0f))) + assertThat(b.ez, `is`(Vec3(10.0f, 15.0f, -30.0f))) + } +} \ No newline at end of file diff --git a/fxgl-scene/src/main/kotlin/com/almasb/fxgl/ui/FXGLDialogFactoryServiceProvider.kt b/fxgl-scene/src/main/kotlin/com/almasb/fxgl/ui/FXGLDialogFactoryServiceProvider.kt index 55e114aeb..9b592e22f 100644 --- a/fxgl-scene/src/main/kotlin/com/almasb/fxgl/ui/FXGLDialogFactoryServiceProvider.kt +++ b/fxgl-scene/src/main/kotlin/com/almasb/fxgl/ui/FXGLDialogFactoryServiceProvider.kt @@ -6,6 +6,7 @@ package com.almasb.fxgl.ui +import com.almasb.fxgl.core.Inject import com.almasb.fxgl.core.util.EmptyRunnable import com.almasb.fxgl.localization.LocalizationService import javafx.beans.binding.StringBinding @@ -34,6 +35,9 @@ import java.util.function.Predicate */ class FXGLDialogFactoryServiceProvider : DialogFactoryService() { + @Inject("fontSizeScaleUI") + private var fontSizeScaleUI = 1.0 + private lateinit var uiFactory: UIFactoryService private lateinit var local: LocalizationService @@ -286,7 +290,7 @@ class FXGLDialogFactoryServiceProvider : DialogFactoryService() { } private fun createMessage(message: String): Text { - return uiFactory.newText(message) + return uiFactory.newText(message, fontSizeScaleUI * 18.0) } private fun localizedStringProperty(key: String): StringBinding { diff --git a/fxgl/src/main/kotlin/com/almasb/fxgl/app/Settings.kt b/fxgl/src/main/kotlin/com/almasb/fxgl/app/Settings.kt index 86e51be3a..1d1b32de4 100644 --- a/fxgl/src/main/kotlin/com/almasb/fxgl/app/Settings.kt +++ b/fxgl/src/main/kotlin/com/almasb/fxgl/app/Settings.kt @@ -241,6 +241,11 @@ class GameSettings( var soundMenuPress: String = "menu/press.wav", var soundMenuSelect: String = "menu/select.wav", + /** + * Set the scale value for UI text size, default = 1.0. + */ + var fontSizeScaleUI: Double = 1.0, + var pixelsPerMeter: Double = 50.0, var collisionDetectionStrategy: CollisionDetectionStrategy = CollisionDetectionStrategy.BRUTE_FORCE, @@ -391,6 +396,7 @@ class GameSettings( soundMenuBack, soundMenuPress, soundMenuSelect, + fontSizeScaleUI, pixelsPerMeter, collisionDetectionStrategy, secondsIn24h, @@ -562,6 +568,8 @@ class ReadOnlyGameSettings internal constructor( val soundMenuPress: String, val soundMenuSelect: String, + val fontSizeScaleUI: Double, + val pixelsPerMeter: Double, val collisionDetectionStrategy: CollisionDetectionStrategy,