Skip to content
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

fix: fix bounce occuring when circular is set in only one direction #207

Merged
merged 1 commit into from
Oct 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/axes/src/InputObserver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ export class InputObserver implements InputTypeObserver {
const out = opt.bounce;
const circular = opt.circular;

if (circular && (circular[0] || circular[1])) {
if ((circular[0] && v < min) || (circular[1] && v > max)) {
return v;
} else if (v < min) {
// left
Expand Down
28 changes: 26 additions & 2 deletions packages/axes/test/unit/InputObserver.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ describe("InputObserver", () => {
},
z: {
range: [-100, 200],
bounce: [50, 0],
circular: true,
bounce: [0, 0],
circular: [false, true],
},
};
options = {
Expand Down Expand Up @@ -229,6 +229,30 @@ describe("InputObserver", () => {
}
inst.release(inputType, {}, [0, 0, 0]);
});
it("should check bounce not occur to direction where the circular is false", (done) => {
// Given
// start pos
let z = 0;
axes.setTo({ z: 0 }, 0);
axes.on("change", ({ delta }) => {
z += delta.z;
expect(z).to.be.not.lt(-100);
});
axes.on("finish", () => {
done();
});

// When
const inputType = {
axes: ["z"],
};
inst.hold(inputType);
// 40 * 25
for (let i = 0; i < 25; ++i) {
inst.change(inputType, {}, { z: -40 });
}
inst.release(inputType, {}, [0, 0, 0]);
});
it("should check delta that there is no bounce and the position is out", (done) => {
// Given
const inputType = {
Expand Down