[orx-gradient-descent] convert to MPP

This commit is contained in:
Edwin Jakobs
2021-06-29 15:26:59 +02:00
parent 6d1f2897f7
commit 4f3834df7b
9 changed files with 110 additions and 9 deletions

View File

@@ -0,0 +1,34 @@
import org.amshove.kluent.shouldBeNear
import org.openrndr.extra.gradientdescent.minimizeModel
import org.openrndr.math.Vector2
import org.spekframework.spek2.Spek
import org.spekframework.spek2.style.specification.describe
object TestMinimizeModel : Spek({
describe("a model") {
val m = object {
var x = 0.0
var y = 0.0
}
it("can be minimized") {
minimizeModel(m) { m->
(m.x - 4.0) * (m.x - 4.0) + (m.y - 3.0) * (m.y - 3.0)
}
m.x.shouldBeNear(4.0, 0.01)
m.y.shouldBeNear(3.0, 0.01)
}
}
describe("a model with a Vector2 property") {
val m = object {
var position = Vector2.ZERO
}
it("can be minimized") {
minimizeModel(m) { m->
(m.position.x - 4.0) * (m.position.x - 4.0) + (m.position.y - 3.0) * (m.position.y - 3.0)
}
m.position.x.shouldBeNear(4.0, 0.01)
m.position.y.shouldBeNear(3.0, 0.01)
}
}
})