Skip to content

Commit 301edbe

Browse files
authored
Merge pull request #129 from NucodeLabs/development
Interpolation Pseudo Section performance optimization. Refactoring
2 parents c1a13ac + b3a54d3 commit 301edbe

28 files changed

+205
-323
lines changed

build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ dependencies {
117117
implementation group: "org.apache.commons", name: "commons-math3", version: "3.6.1"
118118

119119
implementation group: "com.google.inject", name: "guice", version: guiceVersion
120-
implementation group: "org.tinfour", name: "TinfourCore", version: "2.1.8"
121120
implementation "com.fasterxml.jackson.module:jackson-module-kotlin:$jacksonVersion"
122121
implementation "org.apache.commons:commons-collections4:4.4"
123122

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package ru.nucodelabs.util
2+
3+
data class Point(
4+
val x: Double,
5+
val y: Double,
6+
val z: Double
7+
)
8+
9+
fun Point(x: Double, y: Double) = Point(x, y, .0)

kfx-utils/build.gradle

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
11
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
22

33
plugins {
4-
id 'org.jetbrains.kotlin.jvm' version '2.2.0'
5-
id 'java-library'
6-
id 'org.openjfx.javafxplugin' version '0.1.0'
4+
id "org.jetbrains.kotlin.jvm" version "2.2.0"
5+
id "java-library"
6+
id "org.openjfx.javafxplugin" version "0.1.0"
77
}
88

99
version = rootProject.version
1010

1111
tasks.withType(JavaCompile).configureEach {
12-
options.encoding = 'UTF-8'
12+
options.encoding = "UTF-8"
1313
}
1414

1515
javafx {
16-
version = rootProject['javafx']['version']
17-
modules = ['javafx.controls', 'javafx.fxml', 'javafx.graphics', 'javafx.swing']
16+
version = rootProject["javafx"]["version"]
17+
modules = ["javafx.controls", "javafx.fxml", "javafx.graphics", "javafx.swing"]
1818
}
1919

2020
repositories {
21-
// Use Maven Central for resolving dependencies.
2221
mavenCentral()
2322
}
2423

@@ -39,14 +38,14 @@ compileKotlin {
3938
}
4039

4140
dependencies {
42-
implementation platform('org.jetbrains.kotlin:kotlin-bom')
43-
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8'
41+
implementation platform("org.jetbrains.kotlin:kotlin-bom")
42+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
4443

45-
testImplementation 'org.jetbrains.kotlin:kotlin-test'
46-
testImplementation 'org.jetbrains.kotlin:kotlin-test-junit'
44+
testImplementation "org.jetbrains.kotlin:kotlin-test"
45+
testImplementation "org.jetbrains.kotlin:kotlin-test-junit"
4746
testImplementation "org.openjfx:javafx:${javafx.version}"
4847

4948
api "org.openjfx:javafx:${javafx.version}"
50-
api group: 'com.google.inject', name: 'guice', version: rootProject.guiceVersion
51-
api 'no.tornado:tornadofx:1.7.20'
49+
api group: "com.google.inject", name: "guice", version: rootProject.guiceVersion
50+
api "no.tornado:tornadofx:1.7.20"
5251
}

src/main/java/ru/nucodelabs/gem/config/AppModule.java

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@
3232
import ru.nucodelabs.geo.target.RelativeErrorAwareTargetFunction;
3333
import ru.nucodelabs.geo.target.impl.SquareDiffTargetFunction;
3434

35-
import java.io.FileInputStream;
3635
import java.io.IOException;
3736
import java.math.RoundingMode;
3837
import java.net.URL;
3938
import java.nio.charset.StandardCharsets;
39+
import java.nio.file.Files;
4040
import java.nio.file.Paths;
4141
import java.text.DecimalFormat;
4242
import java.text.DecimalFormatSymbols;
@@ -69,8 +69,8 @@ private Locale currentLocale() {
6969

7070
@Provides
7171
@Singleton
72-
private ResourceBundle uiProperties() {
73-
return ResourceBundle.getBundle("ui", currentLocale());
72+
private ResourceBundle uiProperties(Locale currentLocale) {
73+
return ResourceBundle.getBundle("ui", currentLocale);
7474
}
7575

7676
@Provides
@@ -149,6 +149,7 @@ private Preferences preferences() {
149149

150150
@Provides
151151
@Named(Name.PRECISE_FORMAT)
152+
@Singleton
152153
DecimalFormat preciseFormat() {
153154
DecimalFormat decimalFormat = new DecimalFormat();
154155
decimalFormat.setRoundingMode(RoundingMode.HALF_UP);
@@ -162,6 +163,7 @@ DecimalFormat preciseFormat() {
162163
}
163164

164165
@Provides
166+
@Singleton
165167
private DecimalFormat decimalFormat() {
166168
DecimalFormat decimalFormat = new DecimalFormat();
167169
decimalFormat.setRoundingMode(RoundingMode.HALF_UP);
@@ -176,6 +178,7 @@ private DecimalFormat decimalFormat() {
176178
}
177179

178180
@Provides
181+
@Singleton
179182
private StringConverter<Double> doubleStringConverter(DecimalFormat decimalFormat) {
180183
return new StringConverter<>() {
181184
@Override
@@ -199,6 +202,7 @@ public Double fromString(String string) {
199202
}
200203

201204
@Provides
205+
@Singleton
202206
StringConverter<Number> numberStringConverter(StringConverter<Double> doubleStringConverter) {
203207
return new StringConverter<>() {
204208
@Override
@@ -216,44 +220,42 @@ public Number fromString(String string) {
216220
@Provides
217221
@Singleton
218222
@Named(Name.DEFAULT_CLR)
219-
ClrInfo clrInfo() throws IOException {
223+
LoadedClr colormapFile() throws IOException {
220224
// Firstly lookup next to executable
221-
var externalFile = Paths.get("colormap/default.clr").toFile();
222-
if (!externalFile.exists()) {
225+
var externalFile = Paths.get("colormap/default.clr");
226+
if (Files.notExists(externalFile)) {
223227
// Load default from resources if no external .clr file found
224228
var defaultResourceStream = Objects.requireNonNull(
225229
this.getClass().getClassLoader().getResourceAsStream("colormap/default.clr"),
226-
"Resource colormap/default.clr is null"
230+
"Resource colormap/default.clr must not be null"
227231
);
232+
log.info("Loading default .clr file from resources");
228233
try (defaultResourceStream) {
229-
log.info("Loading default .clr file from resources");
230-
return new ClrInfo(
234+
return new LoadedClr(
231235
"Default",
232236
new String(defaultResourceStream.readAllBytes(), StandardCharsets.UTF_8)
233237
);
234238
}
235239
}
236-
try (var externalFileStream = new FileInputStream(externalFile)) {
237-
log.info("Loading external .clr file");
238-
return new ClrInfo(
239-
externalFile.getAbsolutePath(),
240-
new String(externalFileStream.readAllBytes(), StandardCharsets.UTF_8)
241-
);
242-
}
240+
log.info("Loading external .clr file");
241+
return new LoadedClr(
242+
externalFile.toAbsolutePath().toString(),
243+
Files.readString(externalFile, StandardCharsets.UTF_8)
244+
);
243245
}
244246

245247
@Provides
246248
@Singleton
247249
@Named(Name.CLR_SOURCE)
248-
String clrSource(@Named(Name.DEFAULT_CLR) ClrInfo clrInfo) {
249-
return clrInfo.source();
250+
String clrSource(@Named(Name.DEFAULT_CLR) LoadedClr loadedClr) {
251+
return loadedClr.source();
250252
}
251253

252254
@Provides
253255
@Named(Name.DEFAULT_CLR)
254256
@Singleton
255-
ClrParser clrParser(@Named(Name.DEFAULT_CLR) ClrInfo clrInfo) {
256-
return new ClrParser(clrInfo.content());
257+
ClrParser clrParser(@Named(Name.DEFAULT_CLR) LoadedClr loadedClr) {
258+
return new ClrParser(loadedClr.content());
257259
}
258260

259261
@Provides
@@ -283,6 +285,6 @@ RelativeErrorAwareTargetFunction targetFunction() {
283285
return new SquareDiffTargetFunction();
284286
}
285287

286-
private record ClrInfo(String source, String content) {
288+
private record LoadedClr(String source, String content) {
287289
}
288290
}

src/main/java/ru/nucodelabs/gem/config/ChartsModule.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22

33
import com.google.inject.AbstractModule;
44
import com.google.inject.Provides;
5+
import com.google.inject.Singleton;
56
import ru.nucodelabs.geo.forward.ForwardSolver;
7+
import ru.nucodelabs.geo.ves.calc.graph.MathVesNativeMisfitsFunction;
68
import ru.nucodelabs.geo.ves.calc.graph.MisfitsFunction;
79

810
public class ChartsModule extends AbstractModule {
911

1012
@Provides
13+
@Singleton
1114
MisfitsFunction misfitValuesFactory(ForwardSolver forwardSolver) {
12-
return MisfitsFunction.createDefault(forwardSolver);
15+
return new MathVesNativeMisfitsFunction(forwardSolver);
1316
}
1417
}

0 commit comments

Comments
 (0)