Skip to content

Commit

Permalink
Merge pull request #713 from CacPixel/master
Browse files Browse the repository at this point in the history
fix: bezier curve initialization took too long
  • Loading branch information
anatawa12 committed Apr 7, 2024
2 parents 9eeff27 + 7afa4f9 commit fcb78f4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-SNAPSHOTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ The changelog for 2.0.23 and earlier is generated by [anatawa12's fork of `auto-
### Added

### Changed
- Improved performance of bezier curve initialization `#713`

### Deprecated

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Thanks to prepare-changelog.sh, we have some macros.
### Added

### Changed
- Improved performance of bezier curve initialization `#713`

### Deprecated

Expand Down
23 changes: 23 additions & 0 deletions src/main/ngtlib-patches/jp/ngt/ngtlib/math/BezierCurve.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,26 @@
}

private void initNP() {
@@ -107,11 +112,21 @@

for(int l = 0; l < this.split; ++l) {
float f2 = (float)l / (float)this.split;
int j = 0;

- for(j = 0; j < this.split - 1 && (!(afloat[j] <= f2) || !(f2 <= afloat[j + 1])); ++j) {
+ int searchMin = 0, searchMax = split - 1;
+ int loopTimes = 0;
+ while (!(afloat[j] <= f2 && f2 <= afloat[j + 1])) {
+ j = (searchMax - searchMin) / 2 + searchMin;
+ if (afloat[searchMin] <= f2 && f2 <= afloat[j + 1]){
+ searchMax = j;
+ } else {
+ searchMin = j;
+ }
+ if (++loopTimes >= split - 1)
+ break;
}

float f3 = (f2 - afloat[j]) / (afloat[j + 1] - afloat[j]);
f3 = ((float)j * (1.0F - f3) + (float)(1 + j) * f3) * (1.0F / (float)this.split);
this.normalizedParameters[l] = f3;

0 comments on commit fcb78f4

Please sign in to comment.