Skip to content

Commit

Permalink
fix: fix bounce when circular set in only one direction (#207)
Browse files Browse the repository at this point in the history
  • Loading branch information
malangfox authored Oct 25, 2022
1 parent c49817d commit 4806cfa
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
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

0 comments on commit 4806cfa

Please sign in to comment.