Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
ak-git committed Sep 12, 2024
2 parents 8acb731 + 9971025 commit 55f2309
Show file tree
Hide file tree
Showing 11 changed files with 97 additions and 59 deletions.
5 changes: 3 additions & 2 deletions Communication/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ dependencies {
implementation libs.tech.units

testImplementation(platform(libs.junit))
testImplementation libs.bundles.test
testRuntimeOnly libs.junit.platform.launcher
testImplementation libs.bundles.test.implementation
testCompileOnly libs.bundles.test.compile
testRuntimeOnly libs.bundles.test.runtime
}
4 changes: 2 additions & 2 deletions Desktop/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ dependencies {
implementation libs.javafx.base
implementation libs.javafx.graphics

implementation 'org.springframework.boot:spring-boot-starter'
implementation(platform(libs.spring.bom))
implementation libs.bundles.spring.boot

// https://github.com/junit-team/junit5/issues/1773
testImplementation(platform(libs.junit))
testImplementation libs.junit.jupiter
testImplementation libs.junit.jupiter.api
testImplementation libs.assertj
testRuntimeOnly libs.junit.jupiter
testRuntimeOnly libs.junit.platform.launcher
}

Expand Down
74 changes: 52 additions & 22 deletions Desktop/src/main/java/com/ak/fx/scene/GridCell.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
import java.util.EnumSet;
import java.util.LinkedList;
import java.util.List;
import java.util.function.DoubleBinaryOperator;
import java.util.function.ToDoubleFunction;

enum GridCell {
enum GridCell implements GridCellCoordinate {
POINTS(1.0) {
private static final int FACTOR = 4;

Expand All @@ -35,20 +37,20 @@ Path newPath() {
SMALL(1.0) {
@Override
@Nonnegative
double minCoordinate(@Nonnegative double size) {
return GridCell.minCoordinate(getStep(), size);
public double minCoordinate(@Nonnegative double size) {
return defaultImplementation().minCoordinate(size);
}

@Override
@Nonnegative
double maxValue(@Nonnegative double size) {
return GridCell.maxValue(getStep(), size);
public double maxValue(@Nonnegative double size) {
return defaultImplementation().maxValue(size);
}

@Override
@Nonnegative
double roundCoordinate(@Nonnegative double size) {
return GridCell.roundCoordinate(getStep(), size);
public double roundCoordinate(@Nonnegative double size) {
return defaultImplementation().roundCoordinate(size);
}
},
BIG(3.0) {
Expand All @@ -59,6 +61,26 @@ Path newPath() {
}
};

private final GridCellCoordinate defaultImplementation = new GridCellCoordinate() {
@Override
public double minCoordinate(double size) {
double step = getStep();
return size / 2.0 - Math.floor(size / 2.0 / step) * step;
}

@Override
public double maxValue(double size) {
double step = getStep();
return Math.floor((size - minCoordinate(size)) / step) * step;
}

@Override
public double roundCoordinate(double size) {
double step = getStep();
return Numbers.toInt(size / step) * step;
}
};

@Nonnegative
private final double strokeWidth;

Expand All @@ -71,6 +93,10 @@ final double getStrokeWidth() {
return strokeWidth;
}

final GridCellCoordinate defaultImplementation() {
return defaultImplementation;
}

@Nonnegative
double getStep() {
return ScreenResolutionMonitor.getDpi() / 2.54;
Expand All @@ -89,18 +115,26 @@ Path newPath() {
}

@Nonnegative
double minCoordinate(@Nonnegative double size) {
return Math.max(minCoordinate(getStep(), size), SMALL.minCoordinate(size));
@Override
public double minCoordinate(@Nonnegative double size) {
return doCoordinate(Math::max, value -> value.minCoordinate(size));
}

@Nonnegative
@Override
public double maxValue(@Nonnegative double size) {
return doCoordinate(Math::min, value -> value.maxValue(size));
}

@Nonnegative
double maxValue(@Nonnegative double size) {
return Math.min(maxValue(getStep(), size), SMALL.maxValue(size));
@Override
public double roundCoordinate(@Nonnegative double size) {
return doCoordinate(Math::min, value -> value.roundCoordinate(size));
}

@Nonnegative
double roundCoordinate(@Nonnegative double size) {
return Math.min(roundCoordinate(getStep(), size), SMALL.roundCoordinate(size));
private double doCoordinate(DoubleBinaryOperator action, ToDoubleFunction<GridCellCoordinate> coordinate) {
return action.applyAsDouble(coordinate.applyAsDouble(defaultImplementation), coordinate.applyAsDouble(SMALL));
}

static List<Path> newPaths() {
Expand All @@ -116,19 +150,15 @@ static double mmToScreen(int value) {
static int mm(double value) {
return Numbers.toInt(value / (SMALL.getStep() / 10.0));
}
}

interface GridCellCoordinate {
@Nonnegative
private static double minCoordinate(@Nonnegative double step, @Nonnegative double size) {
return size / 2.0 - Math.floor(size / 2.0 / step) * step;
}
double minCoordinate(@Nonnegative double size);

@Nonnegative
private static double maxValue(@Nonnegative double step, @Nonnegative double size) {
return Math.floor((size - minCoordinate(step, size)) / step) * step;
}
double maxValue(@Nonnegative double size);

@Nonnegative
private static double roundCoordinate(@Nonnegative double step, @Nonnegative double size) {
return Numbers.toInt(size / step) * step;
}
double roundCoordinate(@Nonnegative double size);
}
3 changes: 1 addition & 2 deletions Desktop/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

requires commons.math3;
requires java.logging;
requires java.json;
requires java.desktop;
requires java.measure;
requires tech.units.indriya;
requires jsr305;
Expand All @@ -20,6 +18,7 @@
requires spring.context;
requires spring.core;
requires spring.beans;
requires java.desktop;

opens com.ak.appliance.suntech.fx.desktop to javafx.fxml;
opens com.ak.fx.desktop to javafx.fxml, spring.core;
Expand Down
5 changes: 3 additions & 2 deletions FxCore/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ dependencies {
implementation libs.jspecify

testImplementation(platform(libs.junit))
testImplementation libs.bundles.test
testRuntimeOnly libs.junit.platform.launcher
testImplementation libs.bundles.test.implementation
testCompileOnly libs.bundles.test.compile
testRuntimeOnly libs.bundles.test.runtime
}

javafx {
Expand Down
5 changes: 3 additions & 2 deletions Util/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ dependencies {
implementation libs.jenetics

testImplementation(platform(libs.junit))
testImplementation libs.bundles.test
testRuntimeOnly libs.junit.platform.launcher
testImplementation libs.bundles.test.implementation
testCompileOnly libs.bundles.test.compile
testRuntimeOnly libs.bundles.test.runtime
}
3 changes: 1 addition & 2 deletions Util/src/main/java/com/ak/logging/LogBuilder.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package com.ak.logging;

import com.ak.util.Extension;
import com.ak.util.LocalFileIO;

import java.util.logging.FileHandler;

final class LogBuilder extends LogPathBuilder {
LogBuilder(Class<? extends FileHandler> fileHandlerClass) {
super(Extension.LOG, fileHandlerClass);
fileName(LocalFileIO.AbstractBuilder.localDate("yyyy-MM-dd") + ".%u.%g");
fileName(localDate("yyyy-MM-dd") + ".%u.%g");
}
}
6 changes: 3 additions & 3 deletions Util/src/main/java/com/ak/math/Simplex.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ PointValuePair optimize(MultivariateFunction function, Bounds... bounds) {
}
}
return function.value(point);
}, Simplex.toInitialGuess(bounds), Simplex.toInitialSteps(bounds));
}, toInitialGuess(bounds), toInitialSteps(bounds));
}

private static PointValuePair optimize(MultivariateFunction function, double[] initialGuess, double[] initialSteps) {
Expand All @@ -64,9 +64,9 @@ PointValuePair optimize(MultivariateFunction function, Bounds... bounds) {
new MaxEval(MAX_ITERATIONS),
new ObjectiveFunction(function),
GoalType.MINIMIZE,
new InitialGuess(Simplex.toInitialGuess(bounds)),
new InitialGuess(toInitialGuess(bounds)),
simpleBounds,
new CMAESOptimizer.Sigma(Simplex.toInitialSteps(bounds)),
new CMAESOptimizer.Sigma(toInitialSteps(bounds)),
new CMAESOptimizer.PopulationSize(4 + (int) (3.0 * StrictMath.log(bounds.length)))
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
import com.ak.util.Metrics;
import com.ak.util.Numbers;
import com.ak.util.Strings;
import org.jspecify.annotations.Nullable;

import javax.annotation.Nonnegative;
import javax.measure.MetricPrefix;
import java.util.Arrays;
import java.util.Collection;
import java.util.Objects;
import java.util.PrimitiveIterator;
import java.util.function.BiFunction;
import java.util.function.DoubleUnaryOperator;
Expand Down Expand Up @@ -103,7 +105,7 @@ public DhHolder(DoubleUnaryOperator converter, double dh) {

private static class Builder extends TetrapolarResistance.AbstractTetrapolarBuilder<DerivativeResistance>
implements PreBuilder {
private DhHolder dhHolder;
private @Nullable DhHolder dhHolder;

private Builder(TetrapolarSystem system) {
super(DoubleUnaryOperator.identity(), system);
Expand All @@ -121,7 +123,7 @@ public TetrapolarResistance.PreBuilder<DerivativeResistance> dh(double dh) {

@Override
public DerivativeResistance rho(double... rhos) {
if (Double.isNaN(dhHolder.dh)) {
if (Double.isNaN(Objects.requireNonNull(dhHolder).dh)) {
return PreBuilder.check(rhos,
() -> new TetrapolarDerivativeResistance(TetrapolarResistance.of(system).rho(rhos[0]), rhos[1], Double.NaN)
);
Expand All @@ -136,38 +138,39 @@ public DerivativeResistance ofOhms(double... rOhms) {
return PreBuilder.check(rOhms,
() -> {
TetrapolarResistance.PreBuilder<Resistance> b = TetrapolarResistance.of(system);
return new TetrapolarDerivativeResistance(b.ofOhms(rOhms[0]), b.ofOhms(rOhms[1]), dhHolder.dh);
return new TetrapolarDerivativeResistance(b.ofOhms(rOhms[0]), b.ofOhms(rOhms[1]), Objects.requireNonNull(dhHolder).dh);
}
);
}

@Override
public DerivativeResistance build() {
var builder = TetrapolarResistance.of(system).rho1(rho1).rho2(rho2);
double dh = Objects.requireNonNull(dhHolder).dh;
if (Double.isNaN(hStep)) {
return new TetrapolarDerivativeResistance(builder.h(h), builder.h(h + dhHolder.dh), dhHolder.dh);
return new TetrapolarDerivativeResistance(builder.h(h), builder.h(h + dh), dh);
}
else {
if (Double.isNaN(dhHolder.dh)) {
if (Double.isNaN(dh)) {
throw new IllegalArgumentException("dh NULL is not supported in 3-layer model");
}
if (Math.abs(dhHolder.dh) < hStep) {
throw new IllegalArgumentException("|dh| < hStep -> |%s| < %s".formatted(dhHolder.dh, hStep));
if (Math.abs(dh) < hStep) {
throw new IllegalArgumentException("|dh| < hStep -> |%s| < %s".formatted(dh, hStep));
}

var builder3 = builder.rho3(rho3).hStep(hStep);
return new TetrapolarDerivativeResistance(
builder3.p(p1, p2mp1),
builder3.p(p1 + Numbers.toInt(dhHolder.dh / hStep), p2mp1),
dhHolder.dh);
builder3.p(p1 + Numbers.toInt(dh / hStep), p2mp1),
dh);
}
}
}

private static class MultiBuilder
extends TetrapolarResistance.AbstractMultiTetrapolarBuilder<DerivativeResistance>
implements MultiPreBuilder {
private DhHolder dhHolder;
private @Nullable DhHolder dhHolder;

protected MultiBuilder(DoubleUnaryOperator converter) {
super(converter);
Expand All @@ -181,12 +184,12 @@ public TetrapolarResistance.MultiPreBuilder<DerivativeResistance> dh(double dh)

@Override
public Collection<DerivativeResistance> rho(double... rhos) {
return MultiPreBuilder.split(systems, rhos, (s, rho) -> new Builder(s).dh(dhHolder.dh).rho(rho));
return MultiPreBuilder.split(systems, rhos, (s, rho) -> new Builder(s).dh(Objects.requireNonNull(dhHolder).dh).rho(rho));
}

@Override
public Collection<DerivativeResistance> ofOhms(double... rOhms) {
return MultiPreBuilder.split(systems, rOhms, (s, ohms) -> new Builder(s).dh(dhHolder.dh).ofOhms(ohms));
return MultiPreBuilder.split(systems, rOhms, (s, ohms) -> new Builder(s).dh(Objects.requireNonNull(dhHolder).dh).ofOhms(ohms));
}

@Override
Expand All @@ -196,7 +199,7 @@ public Collection<DerivativeResistance> build() {
s -> {
Builder builder = new Builder(s);
builder.h = h;
builder.dhHolder = dhHolder;
builder.dhHolder = Objects.requireNonNull(dhHolder);
return builder.rho1(rho1).rho2(rho2).rho3(rho3).hStep(hStep).p(p1, p2mp1);
})
.toList();
Expand Down
2 changes: 0 additions & 2 deletions Util/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
module com.ak.util {
requires java.json;
requires java.sql;

requires commons.math3;
requires org.apache.commons.csv;
requires jsr305;
Expand Down
20 changes: 13 additions & 7 deletions libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ javafxplugin = '0.1.0'
spring = '6.1.12'
springframework-boot = '3.3.3'
spring-dependency-management = '1.1.6'
snakeyaml = '2.3'
javafx = '24-ea+5'

inject-api = '2.0.1'
Expand Down Expand Up @@ -46,6 +47,7 @@ junit = { module = 'org.junit:junit-bom', version.ref = 'junit' }
junit-jupiter = { module = 'org.junit.jupiter:junit-jupiter', version.ref = 'junit' }
junit-jupiter-api = { module = 'org.junit.jupiter:junit-jupiter-api', version.ref = 'junit' }
junit-jupiter-params = { module = 'org.junit.jupiter:junit-jupiter-params', version.ref = 'junit' }
junit-jupiter-engine = { module = 'org.junit.jupiter:junit-jupiter-engine', version.ref = 'junit' }
junit-platform-launcher = { module = 'org.junit.platform:junit-platform-launcher', version.ref = 'junit-platform-launcher' }
assertj = { module = 'org.assertj:assertj-core', version.ref = 'assertj' }

Expand All @@ -61,12 +63,16 @@ jenetics = { module = 'io.jenetics:jenetics', version.ref = 'jenetics' }
javafx-base = { module = 'org.openjfx:javafx-base', version.ref = 'javafx' }
javafx-graphics = { module = 'org.openjfx:javafx-graphics', version.ref = 'javafx' }

spring-boot = { module = 'org.springframework.boot:spring-boot', version.ref = 'springframework-boot' }
spring-boot-autoconfigure = { module = 'org.springframework.boot:spring-boot-autoconfigure', version.ref = 'springframework-boot' }
spring-core = { module = 'org.springframework:spring-core', version.ref = 'spring' }
spring-beans = { module = 'org.springframework:spring-beans', version.ref = 'spring' }
spring-context = { module = 'org.springframework:spring-context', version.ref = 'spring' }
spring-bom = { module = 'org.springframework:spring-framework-bom', version.ref = 'spring' }
spring-boot = { module = 'org.springframework.boot:spring-boot' }
spring-boot-autoconfigure = { module = 'org.springframework.boot:spring-boot-autoconfigure' }
spring-core = { module = 'org.springframework:spring-core' }
spring-beans = { module = 'org.springframework:spring-beans' }
spring-context = { module = 'org.springframework:spring-context' }
snakeyaml = { module = 'org.yaml:snakeyaml', version.ref = 'snakeyaml' }

[bundles]
spring-boot = ['spring-boot', 'spring-boot-autoconfigure', 'spring-core', 'spring-beans', 'spring-context']
test = ['junit-jupiter', 'junit-jupiter-api', 'junit-jupiter-params', 'assertj']
spring-boot = ['spring-boot', 'spring-boot-autoconfigure', 'spring-core', 'spring-beans', 'spring-context', 'snakeyaml']
test-implementation = ['junit-jupiter-api', 'junit-jupiter-params', 'assertj']
test-compile = ['junit-jupiter', 'junit-jupiter-engine']
test-runtime = ['junit-jupiter-engine', 'junit-platform-launcher']

0 comments on commit 55f2309

Please sign in to comment.