Skip to content

Commit

Permalink
test: added matrix 3x3 test (#1258)
Browse files Browse the repository at this point in the history
* began implementation of UI font size scaling
  • Loading branch information
Mageconvict committed Mar 28, 2023
1 parent 875f5ff commit 74cfdb5
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 1 deletion.
@@ -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)))
}
}
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 8 additions & 0 deletions fxgl/src/main/kotlin/com/almasb/fxgl/app/Settings.kt
Expand Up @@ -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,
Expand Down Expand Up @@ -391,6 +396,7 @@ class GameSettings(
soundMenuBack,
soundMenuPress,
soundMenuSelect,
fontSizeScaleUI,
pixelsPerMeter,
collisionDetectionStrategy,
secondsIn24h,
Expand Down Expand Up @@ -562,6 +568,8 @@ class ReadOnlyGameSettings internal constructor(
val soundMenuPress: String,
val soundMenuSelect: String,

val fontSizeScaleUI: Double,

val pixelsPerMeter: Double,

val collisionDetectionStrategy: CollisionDetectionStrategy,
Expand Down

0 comments on commit 74cfdb5

Please sign in to comment.