Skip to content

Commit fcb78f4

Browse files
authored
Merge pull request #713 from CacPixel/master
fix: bezier curve initialization took too long
2 parents 9eeff27 + 7afa4f9 commit fcb78f4

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

CHANGELOG-SNAPSHOTS.md

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ The changelog for 2.0.23 and earlier is generated by [anatawa12's fork of `auto-
1212
### Added
1313

1414
### Changed
15+
- Improved performance of bezier curve initialization `#713`
1516

1617
### Deprecated
1718

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Thanks to prepare-changelog.sh, we have some macros.
1919
### Added
2020

2121
### Changed
22+
- Improved performance of bezier curve initialization `#713`
2223

2324
### Deprecated
2425

src/main/ngtlib-patches/jp/ngt/ngtlib/math/BezierCurve.java.patch

+23
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,26 @@
1616
}
1717

1818
private void initNP() {
19+
@@ -107,11 +112,21 @@
20+
21+
for(int l = 0; l < this.split; ++l) {
22+
float f2 = (float)l / (float)this.split;
23+
int j = 0;
24+
25+
- for(j = 0; j < this.split - 1 && (!(afloat[j] <= f2) || !(f2 <= afloat[j + 1])); ++j) {
26+
+ int searchMin = 0, searchMax = split - 1;
27+
+ int loopTimes = 0;
28+
+ while (!(afloat[j] <= f2 && f2 <= afloat[j + 1])) {
29+
+ j = (searchMax - searchMin) / 2 + searchMin;
30+
+ if (afloat[searchMin] <= f2 && f2 <= afloat[j + 1]){
31+
+ searchMax = j;
32+
+ } else {
33+
+ searchMin = j;
34+
+ }
35+
+ if (++loopTimes >= split - 1)
36+
+ break;
37+
}
38+
39+
float f3 = (f2 - afloat[j]) / (afloat[j + 1] - afloat[j]);
40+
f3 = ((float)j * (1.0F - f3) + (float)(1 + j) * f3) * (1.0F / (float)this.split);
41+
this.normalizedParameters[l] = f3;

0 commit comments

Comments
 (0)