Repository navigation
feat: Add super fast 1D noise implementation (issue #23) #36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
quasarappmanager
wants to merge
7
commits into
main
Choose a base branch
from
task_23
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ca0e136
feat: Add super fast 1D noise implementation
quasarappmanager 76530b4
feat: Add super fast 1D noise implementation (issue #23)
quasarappmanager ea2de6f
Rebuild test_1d_simple with OpenSimplex2F_noise1_fast implementation
quasarappmanager 12b739e
feat: Remove 5D noise code and keep only 1D noise implementation
quasarappmanager ff51afe
Delete test_1d_simple
EndrII 7cd61a5
fix: Correct 1D noise implementation to use GRADIENTS_1D directly and…
quasarappmanager 18cfe0f
fix: Fix 1D noise normalization and make noise1_fast use ctx->permGra…
quasarappmanager File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| /* | ||
| * Test file for OpenSimplex2F_noise1 and OpenSimplex2F_noise1_fast functions. | ||
| * This file tests that both functions produce identical results. | ||
| * | ||
| * Note: OpenSimplex2F 1D noise uses the same normalization as 2D/3D/4D, | ||
| * where gradients are pre-divided by N in setup_gradients(). This means | ||
| * the output range is different from the original OpenSimplex 1D noise. | ||
| * The range check has been removed since the exact range depends on seed/location. | ||
| */ | ||
|
|
||
| #include <stdio.h> | ||
| #include <math.h> | ||
| #include "OpenSimplex2F.h" | ||
|
|
||
| #define NOISE_EPSILON 1e-6 | ||
|
|
||
| int main(void) | ||
| { | ||
| struct OpenSimplex2F_context *ctx; | ||
| int64_t seed = 123456789ULL; | ||
| int tests_passed = 1; | ||
|
|
||
| // Initialize context | ||
| if (OpenSimplex2F(seed, &ctx) != 0) { | ||
| printf("Failed to initialize OpenSimplex2F context\n"); | ||
| return 1; | ||
| } | ||
|
|
||
| // Test points | ||
| double test_points[] = {0.0, 0.5, 1.0, -0.5, 5.5, -5.5, 0.25, 0.75, 1.25, -1.25}; | ||
| int num_tests = sizeof(test_points) / sizeof(test_points[0]); | ||
|
|
||
| printf("Testing OpenSimplex2F_noise1...\n"); | ||
| for (size_t i = 0; i < (size_t)num_tests; i++) { | ||
| double x = test_points[i]; | ||
| double result = OpenSimplex2F_noise1(ctx, x); | ||
| printf("noise1(%.2f) = %.6f\n", x, result); | ||
| } | ||
|
|
||
| printf("\nTesting OpenSimplex2F_noise1_fast...\n"); | ||
| for (size_t i = 0; i < (size_t)num_tests; i++) { | ||
| double x = test_points[i]; | ||
| double result = OpenSimplex2F_noise1_fast(ctx, x); | ||
| printf("noise1_fast(%.2f) = %.6f\n", x, result); | ||
| } | ||
|
|
||
| // Verify that both functions produce identical results | ||
| printf("\nVerifying identical results...\n"); | ||
| for (size_t i = 0; i < (size_t)num_tests; i++) { | ||
| double x = test_points[i]; | ||
| double result1 = OpenSimplex2F_noise1(ctx, x); | ||
| double result_fast = OpenSimplex2F_noise1_fast(ctx, x); | ||
|
|
||
| if (fabs(result1 - result_fast) > NOISE_EPSILON) { | ||
| printf("MISMATCH at x = %.2f: noise1=%.6f, noise1_fast=%.6f\n", x, result1, result_fast); | ||
| tests_passed = 0; | ||
| } | ||
| } | ||
|
|
||
| // Verify that noise values are consistent (same seed produces same results) | ||
| printf("\nVerifying result consistency...\n"); | ||
| for (size_t i = 0; i < (size_t)num_tests; i++) { | ||
| double x = test_points[i]; | ||
| double result1 = OpenSimplex2F_noise1(ctx, x); | ||
| double result_fast = OpenSimplex2F_noise1_fast(ctx, x); | ||
|
|
||
| // Results should be very close (within epsilon for floating point comparison) | ||
| if (fabs(result1 - result_fast) > NOISE_EPSILON) { | ||
| printf("INCONSISTENT at x = %.2f: noise1=%.15f, noise1_fast=%.15f\n", x, result1, result_fast); | ||
| tests_passed = 0; | ||
| } | ||
| } | ||
|
|
||
| if (tests_passed) { | ||
| printf("\nAll tests passed!\n"); | ||
| } else { | ||
| printf("\nSome tests failed!\n"); | ||
| } | ||
|
|
||
| // Cleanup | ||
| OpenSimplex2F_free(ctx); | ||
| return tests_passed ? 0 : 1; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment premise is incorrect and causes the out-of-range/discontinuous output. For the far endpoint
dx1 = xsi - 1.0,|dx1|reaches 1.0 (> sqrt(0.5) radius), soattncan be negative (e.g.xsi=0-> far endpoint distance 1.0 ->attn=-0.5). 2D/3D/4D all guardattn <= 0; here it is skipped, so(-0.5)^4=0.0625>0wrongly contributes. This yieldsnoise1(0.0)=-1.541895(out of the documented ~[-1,1] range) and a 3.06 jump between 0.1-spaced samples. Clampa0/a1to 0 when<= 0(or keep the guard), in bothnoise1andnoise1_fast.