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(modeling): applyTransform ceate new geometry #970

Closed
wants to merge 10 commits into from

Conversation

hrgdavor
Copy link
Contributor

@hrgdavor hrgdavor commented Dec 26, 2021

The fix

old tests fixed

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?
  • Does your submission pass tests?

@z3dev
Copy link
Member

z3dev commented Dec 27, 2021

General comments.

The behavior change to applyTransforms is going to affect performance. There are many cases where measurements are being called, followed by calling toPoints.

Also, these changes don’t fix measureBoudingBox. At least, I can’t see the fix. So, I don’t think the test cases are robust.

@hrgdavor
Copy link
Contributor Author

the fix is in two parts:

First part is in the caching code

    // create a new boundingBox. Mutating the passed boundingBox would break cached calculations
    boundingBox = [
      vec3.transform(vec3.create(), boundingBox[0], transforms),
      vec3.transform(vec3.create(), boundingBox[1], transforms)
    ]

the second is in aplyTransform to not mutate/destroy the geometry.


There are many cases where measurements are being called, followed by calling toPoints.

That is a poor design choice, and such code should be optimized to perform better. I would like to see the examples where this applies.


unit test there in the code confirms both when error happens (without the fix), and works after fix .
the fix also works for the 2 more complex examples from related github issue #966

@z3dev
Copy link
Member

z3dev commented Dec 29, 2021

I think this should be split into two pieces. The fix for measureBoundingBoz should not rely upon other changes.

@hrgdavor hrgdavor changed the title fix(modeling): undo-revert measureBoundingBox fix(modeling): applyTransform ceate new geometry Dec 29, 2021
@hrgdavor
Copy link
Contributor Author

ok, it is split now, but both are needed for the fix to be complete

@t1u1
Copy link
Contributor

t1u1 commented Feb 2, 2022

Thanks for your work @hrgdavor

This looks like an important fix.

I have been building a complex model using jscad, and it has been going fine until today. When I added a transform.rotate inside the model, things started looking weird. It took me a long while to realize that it was the rotation that was causing the weird geometry.

Perhaps it is related to this issue. I will try to reduce the model to a smaller test case, but in the meanwhile, if this PR looks good it will be great to have this merged.

@hrgdavor
Copy link
Contributor Author

hrgdavor commented Feb 2, 2022

@t1u1 this PR is more pragmatic change than a bug-fix. But when you have a test example, we can take look what is causing you issues.

@z3dev
Copy link
Member

z3dev commented Feb 2, 2022

Thanks for your work @hrgdavor

This looks like an important fix.

I have been building a complex model using jscad, and it has been going fine until today. When I added a transform.rotate inside the model, things started looking weird. It took me a long while to realize that it was the rotation that was causing the weird geometry.

Perhaps it is related to this issue. I will try to reduce the model to a smaller test case, but in the meanwhile, if this PR looks good it will be great to have this merged.

See issue #985 about some viewer issues.

You can check if it’s a viewer issue. Just call toPolygons() before returning the shape from main(). That will rest the transforms, and the viewer should display properly.

@t1u1
Copy link
Contributor

t1u1 commented Feb 3, 2022

Thanks @hrgdavor @z3dev

After some more experiments I think the issue I am seeing is something else. Boolean operations involving geometries that touch each other cause weirdness. It was just getting triggered during rotation at certain angles.

Will file a separate issue for it.

@z3dev
Copy link
Member

z3dev commented May 16, 2022

@hrgdavor i think these changes are no longer important. There were changes to improve copy() functions as well as transform() functions.

if you still think these are important then let's discuss further.

@hrgdavor
Copy link
Contributor Author

I need to consider it a bit more, and see if it could cause issues. I vageuely rememeber that it could actually be ok, in the sense it would not break other instances.

@hrgdavor
Copy link
Contributor Author

I will revisit this at later time, adn create new issue if needed

@hrgdavor hrgdavor closed this May 16, 2022
@z3dev z3dev deleted the fix-measureboundingbox branch June 12, 2022 03:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants