-
Notifications
You must be signed in to change notification settings - Fork 88
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
refactor(YawPitchControl): add unit test and refactor src #42
Conversation
also, fixed typo at MoveKeyInput.spec.js ref #35
if (evt.delta.fov !== 0) { | ||
this._setPanScale(evt.pos.fov); | ||
this._updateControlScale(); | ||
} | ||
this._triggerChange(); |
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 agree removing code because it is process by change event. but how about change event name? current is "change" but... I think it would be better to notice it's release event.
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.
Whether or not to provide a release event will be discussed in a separate issue.
Issue opened
#43
this._applyOptions(changedKeyList, beforeOptions); | ||
return this; | ||
} | ||
|
||
_option(key, value) { | ||
if (arguments.length >= 2) { |
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.
As you know it makes available following.
this.option("key", "value")
And I think it is general pattern (interface) for setting value. If it is not unreachable it would be better to add some test case.
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.
Actually, in '_option' method, it's not using key, value parameter anymore.
It supports three API patterns below.
this._option("key"); // Getter
this._option(); // Global Getter
this._option({
"key": value
}); // Setter
The value portion of the argument is expected to be deleted.
} | ||
|
||
_applyOptions(keys, prevOptions) { | ||
// If one of below is changed, call updateControlScale() | ||
if (keys.some(key => | ||
key === "showPole" || key === "fov" || key === "aspectRatio")) { | ||
this._setYawPitchRange(prevOptions); |
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.
It's good to change code to exit recursive. but It is missing to change yaw/pitch range if fov or aspect ratio is changed.
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 understand what you mean. I will fix that.
I changed _getValidYawRange, _getValidPitchRange methods to use new fov and aspectRatio parameter.
const horizontalFov = fov * ratio; | ||
const isValid = !(newYawRange[1] - newYawRange[0] < horizontalFov); |
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.
Is it right? Isn't your intend following?
// ! is removed
const isValid = (newYawRange[1] - newYawRange[0] < horizontalFov);
Although it's your intend I think It would be better to not put ! like below
const isValid = (newYawRange[1] - newYawRange[0] >= horizontalFov);
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.
Thanks. I will fix that.
this.option("pitchRange", prevPitchRange); | ||
_getValidPitchRange(newPitchRange) { | ||
const fov = this.axes.get().fov; | ||
const isValid = !(newPitchRange[1] - newPitchRange[0] < fov); |
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.
Same as above.
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.
Thanks. I will fix that, too
if (isValid) { | ||
return newPitchRange; | ||
} else { | ||
return this.options.pitchRange || [-PITCH_RANGE_HALF, PITCH_RANGE_HALF]; |
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.
How about default range as fov ranges instead of DEFAULT?
// Then | ||
const appliedOption = this.inst.option(); | ||
expect(appliedOption.yawRange).to.deep.equal([-180, 180]); | ||
expect(appliedOption.pitchRange).to.deep.equal([-90, 90]); |
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.
It's related with code that I commented above.
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.
You can ignore this comment.
@@ -203,6 +221,23 @@ describe("YawPitchControl", function() { | |||
done(); | |||
} | |||
}); | |||
|
|||
it("should lookAt trigger change event once when enable called multiple times.", () => { | |||
// Given |
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.
Is this case for checking axes not connected PanInput multiple times?
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.
Yes! Exactly.
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.
OK Thank you!
inst.option("yawRange", [-1, 1]); | ||
|
||
// Then | ||
console.log(inst.option("yawRange")); |
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.
No expect code.
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 will add assertion.
inst.option("pitchRange", [-1, 1]); | ||
|
||
// Then | ||
console.log(inst.option("pitchRange")); |
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.
No expect code.
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 will add assertion.
@@ -168,25 +170,28 @@ const YawPitchControl = class YawPitchControl extends Component { | |||
|
|||
// adjustOption | |||
if (changedKeyList.some(key => key === "yawRange")) { |
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.
@happyhj how about moving this call to _applyOption. and I have other things to talk . let's take meeting.
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.
LGTM
Issue
#35
Details
add unit test and refactor YawPitchControl.js for better testability.
also, fixed typo at MoveKeyInput.spec.js