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

Allow Path/Image to take TReadOnlyProperty with shapeProperty/imageProperty #1613

Closed
jonathanolson opened this issue Feb 20, 2024 · 12 comments
Closed

Comments

@jonathanolson
Copy link
Contributor

It looks like these will need to take a slightly more unhooked approach, due to:

  1. Imageable (where _image lives, and _imageProperty will) is mixed by non-Node things. TinyForwardingProperty.setTargetProperty has a lot of assumptions about Node/NodeLike. SpriteImage is not Node-like. @zepumph I'm curious about review, I wasn't expecting the setTargetProperty implementation (... it looks safe to me to pass null in?)
  2. image.image is... not what you pass in (in many cases). It coerces things to HTMLImageElement/HTMLCanvasElement (and mipmap things get stored elsewhere). Long story short, we need to still store _image, while _imageProperty can be this pure and amazing representation of "what is the current input" (which is great and valuable).
  3. Path also coerces (away from string)
  4. Path subtypes lazily construct actual Shape instances (when asked, and track whether it needs to be regenerated). This requires extra storage.

Finishing testing and adding some implementations in sims (where we were clearly linking something that could be a Property/DerivedProperty).

jonathanolson added a commit to phetsims/capacitor-lab-basics that referenced this issue Feb 20, 2024
jonathanolson added a commit to phetsims/faradays-electromagnetic-lab that referenced this issue Feb 20, 2024
jonathanolson added a commit to phetsims/circuit-construction-kit-common that referenced this issue Feb 20, 2024
jonathanolson added a commit to phetsims/area-model-common that referenced this issue Feb 20, 2024
jonathanolson added a commit to phetsims/balloons-and-static-electricity that referenced this issue Feb 20, 2024
jonathanolson added a commit to phetsims/density-buoyancy-common that referenced this issue Feb 20, 2024
@jonathanolson
Copy link
Contributor Author

Additionally in phetsims/beers-law-lab@7c794ec, I had to add strictAxonDependencies:false to something (otherwise... reading Node bounds inside of a DerivedProperty would be prohibited?).

@samreid thoughts on whether this issue (related to phetsims/axon#441) qualifies as a good catch (hey, should we listen to the bodyNode/probeNode bounds?) or as noise?

@jonathanolson
Copy link
Contributor Author

@zepumph, available to review?

@samreid
Copy link
Member

samreid commented Feb 20, 2024

@samreid thoughts on whether this issue (related to phetsims/axon#441) qualifies as a good catch (hey, should we listen to the bodyNode/probeNode bounds?) or as noise?

It seems unfortunate that the framework cannot figure out that listening to body.positionProperty counts towards listening for the bodyNode.centerX, but on the other hand, it is possible to imagine those getting out of sync. For instance, if the listener order was different, then you could get the callback on body.positionProperty having changed before the bodyNode.centerX has updated, then it would be buggy.

@zepumph
Copy link
Member

zepumph commented Feb 22, 2024

From review:

  • I'd like to talk about how Imageable supports (or doesn't support) null. It doesn't seem like it has a place there, but nulling out a shape in Path seemed useful. I'm curious about the discrepancy. For example asserting we have an image set:
    assert && assert( this._image !== null );
    .
  • On slack you mentioned that it was awkward to have ParsedImage as the type for getHitTestData. I'll leave it up to you if you want to expand the definition of what a ParsedImage is, or hard code them for that function. Either sounds great to me.

Thus far I have only completed the Path and Imageable files review.

@zepumph
Copy link
Member

zepumph commented Feb 22, 2024

And I stopped looking there (made it to joist/)


Otherwise I completed the review and everything looks really nice. Thank you!

@zepumph zepumph assigned jonathanolson and unassigned zepumph Feb 22, 2024
@jonathanolson
Copy link
Contributor Author

I'd like to talk about how Imageable supports (or doesn't support) null. It doesn't seem like it has a place there, but nulling out a shape in Path seemed useful. I'm curious about the discrepancy. For example asserting we have an image set:

A lot of code is needed to support a null value there. It would take more plumbing to adjust (SVG path with empty path info is fine, SVG image with empty src seems to have issues). I realize there is a discrepancy, but I would resolve that discrepancy by not letting Path take null (and instead use an empty Shape).

@jonathanolson
Copy link
Contributor Author

Here are some usages for 'shape' that maybe want to include 'shapeProperty' too.

The cases of drawableMarkFlags don't actually include 'shapeProperty', so there is no need to remove them.

@jonathanolson
Copy link
Contributor Author

Here are some usages for 'shape' that maybe want to include 'shapeProperty' too.

The Density/Buoyancy ones aren't based on Path, so that won't work either:

image

@jonathanolson
Copy link
Contributor Author

Created an issue for potential chip-away to refactor using the new patterns as noted above: #1651

@jonathanolson
Copy link
Contributor Author

Created an issue for the highlight overlay shapeProperty in #1652.

@jonathanolson
Copy link
Contributor Author

@zepumph thoughts on the above? Is everything handled?

@zepumph
Copy link
Member

zepumph commented Aug 19, 2024

I think this all looks great. Thanks for handling this.

@zepumph zepumph closed this as completed Aug 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants