-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Added example and Unit tests for ClampToZero method on p5.Vector. #7199
base: main
Are you sure you want to change the base?
Changes from 7 commits
0eba307
7bfb747
70bd6ac
aa57c05
9a57378
52b0c63
b64675f
ad63298
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1882,5 +1882,48 @@ suite('p5.Vector', function() { | |
expect(p5.Vector.equals(a1, a2)).to.be.true; | ||
}); | ||
}); | ||
|
||
suite('p5.Vector.clampToZero()', function() { | ||
let v; | ||
|
||
test('should clamp very small positive number of vector components to zero', function() { | ||
v = new p5.Vector(0.0000000000000002, 5); | ||
v.clampToZero(); | ||
expect(v.x).to.equal(0); | ||
expect(v.y).to.equal(5); | ||
}); | ||
|
||
test('should clamp very small negative number of vector components to zero', function() { | ||
v = new p5.Vector(-0.0000000000000002, 5); | ||
v.clampToZero(); | ||
expect(v.x).to.equal(0); | ||
expect(v.y).to.equal(5); | ||
}); | ||
Comment on lines
+1896
to
+1901
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe we use |
||
|
||
test('should not clamp regular numbers of vector components', function() { | ||
v = new p5.Vector(0.01, 5); | ||
v.clampToZero(); | ||
expect(v.x).to.equal(0.01); | ||
expect(v.y).to.equal(5); | ||
}); | ||
Comment on lines
+1903
to
+1908
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here as well, it looks like we are checking for the same test and we are specifically testing for something with :
With these three values, we can create different combinations to verify if clampToZero() works correctly. Since unit tests can be time-consuming to run, this would be a kind of optimization. Let me know what you think ;) |
||
|
||
test('should leave zero components of a 2D vector unchanged', function() { | ||
v = new p5.Vector(0, 0); | ||
v.clampToZero(); | ||
expect(v.x).to.equal(0); | ||
expect(v.y).to.equal(0); | ||
}); | ||
|
||
test('should clamp very small numbers in all components of a 3D vector to zero', function() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like how you mentioned that we are clamping "components of a vector", I think it would be awesome if other tests followed the same wording ie instead of saying that we are rounding down the number we can say rounding down the component of a vector |
||
v = new p5.Vector( | ||
0.00000000000000005, | ||
-0.0000000000000002220446049250313, | ||
0.0000000000000002220446049250313); | ||
v.clampToZero(); | ||
expect(v.x).to.equal(0); | ||
expect(v.y).to.equal(0); | ||
expect(v.z).to.equal(0); | ||
}); | ||
}); | ||
}); | ||
}); |
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.
I am sorry I don't know this word 'negigabe' , can you please check if this is something intentional