-
Notifications
You must be signed in to change notification settings - Fork 0
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
Document why the electrons are positioned as position.x + radius #146
Comments
The offset (2nd arg) to electronNode.toCanvas( ( canvas, x, y, width, height ) => {
spriteImage = new SpriteImage( canvas, new Vector2( ( x + electronNode.width / 2 ), ( y + electronNode.height / 2 ) ), { If I change to: spriteImage = new SpriteImage( canvas, new Vector2( electronNode.width / 2, electronNode.height / 2 ), { ... then I can also make this change: this.matrix.rowMajor(
- ELECTRON_INVERSE_SCALE, 0, this.electron.x + ELECTRON_RADIUS,
- 0, ELECTRON_INVERSE_SCALE, this.electron.y + ELECTRON_RADIUS,
+ ELECTRON_INVERSE_SCALE, 0, this.electron.x,
+ 0, ELECTRON_INVERSE_SCALE, this.electron.y,
0, 0, 1
); But.... This pattern for the offset to compassNeedleNode.toCanvas( ( canvas, x, y, width, height ) => {
spriteImage = new SpriteImage( canvas, new Vector2( ( x + compassNeedleNode.width / 2 ), ( y + compassNeedleNode.height / 2 ) ), { But then I do not see an adjustment of position in CompassNeedleSpriteInstance: // Inlined translation/rotation/scale for efficiency
this.matrix.setToScaleTranslationRotationPoint( COMPASS_NEEDLE_INVERSE_SCALE, this.position, rotation ); That leads me to believe that the position of the needles may not be correct in FieldNode. I'll need to consult with @jonathanolson on this. |
Presumably the stroke width changed the bounds off of the (0,0,width,height) for the field lines, that's why it was slightly off. Electrons were probably centered (approximately) and way off. Committed a fix above, let me know how it looks. |
To further clarify, if you remove the |
The explanation from @jonathanolson sounds reasonable, I'll leave this assigned to @pixelzoom to review. Self-unassigning. |
Thanks @jonathanolson, your explanation makes sense, and the fix looks good. I should apply this same fix to FieldNode, where I suspect that the position of the needles is slightly off for the same reason. (And I should take a look at the particles in Gas Properties too -- see phetsims/gas-properties#219.) |
Looks like @jonathanolson already did this -- thanks! As a debugging tool (which I should have added a long time ago) I added FieldPositionsNode and the Prior to @jonathanolson's fix, the positions were off by quite a bit: After @jonathanolson's fix, the positions are spot on: So thanks all for working on this, it exposed an important problem that is now fixed. Closing. |
During code review #103, we observed this code in ElectronsNode.ts
We were surprised to see the transform set to the position plus the radius. Normally we would expect to see position minus the radius to locate it correctly. If the sign is correct, please add documentation explaining why.
The text was updated successfully, but these errors were encountered: