-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve plotter output, introduce randomness (#135)
This improves the `sample` function central to Mafs' plotter. ### Bug fix: duplicate points, incorrect subdivision First, it corrects a bug that was causing duplicate points to be evaluated. For example, when sampling the domain [-16, 16] with sampling depth 4, these points were being generated: ``` [-16,-15,-13,-12,-12,-11,-9,-8,-8,-7,-5,-4,-4,-3,-1,0,0,1,3,4,4,5,7,8,8,9,11,12,12,13,15,16] ``` Of course, duplicates make no sense here, and we would actually expect a uniform distribution between -16 and 16. Also, we would expect depth _5_ to produce 32 segments (33 points), not depth 4. So that was fixed by, thankfully, removing code. ### Randomness Additionally, for quite some time, I have been wanting to introduce some stable randomness to the sampling function, in a way that prevents the function from changing with every render. I finally decided to research that and introduce a pseudo-random hash function when evaluating the midpoint of the domain. This also required the `midpoint` function in `sample` to become a `lerp`, since we can no longer simply measure against the midpoint to compute errors.
- Loading branch information
1 parent
d7d0b50
commit 2a0fbde
Showing
9 changed files
with
71 additions
and
37 deletions.
There are no files selected for viewing
This file contains 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 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 modified
BIN
+38.5 KB
(250%)
...ec.tsx-snapshots/guide-examples-plots-SineStressTest-1-Mobile-Chrome-darwin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+9.2 KB
(120%)
...ec.tsx-snapshots/guide-examples-plots-SineStressTest-1-Mobile-Safari-darwin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+45.8 KB
(280%)
...rt.spec.tsx-snapshots/guide-examples-plots-SineStressTest-1-chromium-darwin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+85.7 KB
(310%)
...vrt.spec.tsx-snapshots/guide-examples-plots-SineStressTest-1-firefox-darwin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+16.2 KB
(120%)
...-vrt.spec.tsx-snapshots/guide-examples-plots-SineStressTest-1-webkit-darwin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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,23 @@ | ||
import { sample } from "./PlotUtils" | ||
|
||
test("sample", () => { | ||
const ts: number[] = [] | ||
|
||
sample<number>({ | ||
domain: [0, 8], | ||
minDepth: 3, | ||
maxDepth: 3, | ||
error: () => Number.POSITIVE_INFINITY, | ||
fn: (t) => t, | ||
lerp: () => 0, | ||
onPoint(t) { | ||
ts.push(t) | ||
}, | ||
threshold: 0, | ||
}) | ||
|
||
// Since the sample function deliberately introduces randomness, we round to test. | ||
const roundedTs = ts.map(Math.round) | ||
|
||
expect(roundedTs).toEqual([0, 1, 2, 3, 4, 5, 6, 7, 8]) | ||
}) |
This file contains 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
2a0fbde
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.
Successfully deployed to the following URLs:
mafs – ./
mafs-stevenpetryk.vercel.app
mafs-docs.vercel.app
mafs.dev
mafs-git-main-stevenpetryk.vercel.app
www.mafs.dev