diff --git a/build.gradle b/build.gradle index 02ee7ae5..fa43c4c4 100644 --- a/build.gradle +++ b/build.gradle @@ -23,12 +23,14 @@ def multiplatformModules = [ "orx-compositor", "orx-easing", "orx-fx", + "orx-gradient-descent", "orx-image-fit", "orx-noise", "orx-parameters", "orx-shade-styles", "orx-shader-phrases", "orx-quadtree", + ] project.ext { diff --git a/orx-gradient-descent/build.gradle.kts b/orx-gradient-descent/build.gradle.kts new file mode 100644 index 00000000..6e6dff4c --- /dev/null +++ b/orx-gradient-descent/build.gradle.kts @@ -0,0 +1,96 @@ +import Orx_embed_shaders_gradle.EmbedShadersTask + +plugins { + kotlin("multiplatform") + kotlin("plugin.serialization") + id("orx.embed-shaders") +} + +val kotlinxSerializationVersion: String by rootProject.extra +val kotestVersion: String by rootProject.extra +val junitJupiterVersion: String by rootProject.extra +val jvmTarget: String by rootProject.extra +val kotlinApiVersion: String by rootProject.extra +val kotlinVersion: String by rootProject.extra +val kotlinLoggingVersion: String by rootProject.extra +val kluentVersion: String by rootProject.extra +val openrndrVersion: String by rootProject.extra +val openrndrOS: String by rootProject.extra +val spekVersion: String by rootProject.extra + +kotlin { + jvm { + compilations { + val demo by creating { + defaultSourceSet { + kotlin.srcDir("src/demo") + dependencies { + implementation(project(":orx-camera")) + implementation("org.openrndr:openrndr-application:$openrndrVersion") + implementation("org.openrndr:openrndr-extensions:$openrndrVersion") + runtimeOnly("org.openrndr:openrndr-gl3:$openrndrVersion") + runtimeOnly("org.openrndr:openrndr-gl3-natives-$openrndrOS:$openrndrVersion") + implementation(compilations["main"]!!.output.allOutputs) + } + } + } + } + compilations.all { + kotlinOptions.jvmTarget = jvmTarget + kotlinOptions.apiVersion = kotlinApiVersion + } + testRuns["test"].executionTask.configure { + useJUnitPlatform() + } + } + js(IR) { + browser() + nodejs() + } + + sourceSets { + @Suppress("UNUSED_VARIABLE") + val commonMain by getting { + dependencies { + implementation(project(":orx-parameters")) + implementation(project(":orx-shader-phrases")) + implementation("org.jetbrains.kotlinx:kotlinx-serialization-core:$kotlinxSerializationVersion") + implementation("org.openrndr:openrndr-application:$openrndrVersion") + implementation("org.openrndr:openrndr-draw:$openrndrVersion") + implementation("org.openrndr:openrndr-filter:$openrndrVersion") + implementation("org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion") + implementation("io.github.microutils:kotlin-logging:$kotlinLoggingVersion") + } + } + @Suppress("UNUSED_VARIABLE") + val commonTest by getting { + dependencies { + implementation(kotlin("test-common")) + implementation(kotlin("test-annotations-common")) + implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:$kotlinxSerializationVersion") + implementation("io.kotest:kotest-assertions-core:$kotestVersion") + } + } + + @Suppress("UNUSED_VARIABLE") + val jvmTest by getting { + dependencies { + implementation(kotlin("test-common")) + implementation(kotlin("test-annotations-common")) + implementation(kotlin("test-junit5")) + implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:$kotlinxSerializationVersion") + runtimeOnly("org.junit.jupiter:junit-jupiter-api:$junitJupiterVersion") + runtimeOnly("org.junit.jupiter:junit-jupiter-engine:$junitJupiterVersion") + implementation("org.spekframework.spek2:spek-dsl-jvm:$spekVersion") + implementation("org.amshove.kluent:kluent:$kluentVersion") + } + } + + @Suppress("UNUSED_VARIABLE") + val jsTest by getting { + dependencies { + implementation(kotlin("test-js")) + } + } + } +} \ No newline at end of file diff --git a/orx-gradient-descent/src/main/kotlin/GradientDescent.kt b/orx-gradient-descent/src/commonMain/kotlin/GradientDescent.kt similarity index 94% rename from orx-gradient-descent/src/main/kotlin/GradientDescent.kt rename to orx-gradient-descent/src/commonMain/kotlin/GradientDescent.kt index 314bf14e..341466e0 100644 --- a/orx-gradient-descent/src/main/kotlin/GradientDescent.kt +++ b/orx-gradient-descent/src/commonMain/kotlin/GradientDescent.kt @@ -175,12 +175,3 @@ fun minimize(_x0: DoubleArray, return MinimizationResult(x0, f0, g0, H1, iteration) } -fun minimizeModel(model: T, endOnLineSearch: Boolean = false, tol: Double = 1e-8, maxIterations: Int = 1000, function: (T) -> Double) { - val doubles = modelToArray(model) - val weights = DoubleArray(doubles.size) { 1.0 } - val solution = minimize(doubles, weights, endOnLineSearch, tol, maxIterations) { - arrayToModel(it, model) - function(model) - } - arrayToModel(solution.solution, model) -} \ No newline at end of file diff --git a/orx-gradient-descent/src/main/kotlin/DataBinding.kt b/orx-gradient-descent/src/jvmMain/kotlin/DataBinding.kt similarity index 100% rename from orx-gradient-descent/src/main/kotlin/DataBinding.kt rename to orx-gradient-descent/src/jvmMain/kotlin/DataBinding.kt diff --git a/orx-gradient-descent/src/jvmMain/kotlin/GradientDescent.kt b/orx-gradient-descent/src/jvmMain/kotlin/GradientDescent.kt new file mode 100644 index 00000000..0e5729a7 --- /dev/null +++ b/orx-gradient-descent/src/jvmMain/kotlin/GradientDescent.kt @@ -0,0 +1,12 @@ +@file:JvmName("GradientDescentJvmKt") +package org.openrndr.extra.gradientdescent + +fun minimizeModel(model: T, endOnLineSearch: Boolean = false, tol: Double = 1e-8, maxIterations: Int = 1000, function: (T) -> Double) { + val doubles = modelToArray(model) + val weights = DoubleArray(doubles.size) { 1.0 } + val solution = minimize(doubles, weights, endOnLineSearch, tol, maxIterations) { + arrayToModel(it, model) + function(model) + } + arrayToModel(solution.solution, model) +} \ No newline at end of file diff --git a/orx-gradient-descent/src/test/kotlin/TestDot.kt b/orx-gradient-descent/src/jvmTest/kotlin/TestDot.kt similarity index 100% rename from orx-gradient-descent/src/test/kotlin/TestDot.kt rename to orx-gradient-descent/src/jvmTest/kotlin/TestDot.kt diff --git a/orx-gradient-descent/src/test/kotlin/TestGradient.kt b/orx-gradient-descent/src/jvmTest/kotlin/TestGradient.kt similarity index 100% rename from orx-gradient-descent/src/test/kotlin/TestGradient.kt rename to orx-gradient-descent/src/jvmTest/kotlin/TestGradient.kt diff --git a/orx-gradient-descent/src/test/kotlin/TestMinimize.kt b/orx-gradient-descent/src/jvmTest/kotlin/TestMinimize.kt similarity index 100% rename from orx-gradient-descent/src/test/kotlin/TestMinimize.kt rename to orx-gradient-descent/src/jvmTest/kotlin/TestMinimize.kt diff --git a/orx-gradient-descent/src/test/kotlin/TestMinimizeModel.kt b/orx-gradient-descent/src/jvmTest/kotlin/TestMinimizeModel.kt similarity index 100% rename from orx-gradient-descent/src/test/kotlin/TestMinimizeModel.kt rename to orx-gradient-descent/src/jvmTest/kotlin/TestMinimizeModel.kt