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 eachpoint() with useLocalCoordinates=False coordinate transformation #1097

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

greyltc
Copy link
Contributor

@greyltc greyltc commented Jun 5, 2022

I think the coordinate transformation for the eachpoint() function with useLocalCoordinates=False was backwards
fixes #1098

@codecov
Copy link

codecov bot commented Jun 5, 2022

Codecov Report

Merging #1097 (ae2db62) into master (a5fadeb) will not change coverage.
The diff coverage is 100.00%.

❗ Current head ae2db62 differs from pull request most recent head 5881c36. Consider uploading reports for the commit 5881c36 to get more accurate results

@@           Coverage Diff           @@
##           master    #1097   +/-   ##
=======================================
  Coverage   96.34%   96.34%           
=======================================
  Files          40       40           
  Lines        9533     9533           
  Branches     1259     1259           
=======================================
  Hits         9185     9185           
  Misses        205      205           
  Partials      143      143           
Impacted Files Coverage Δ
cadquery/cq.py 92.43% <100.00%> (ø)

📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more

@jmwright
Copy link
Member

jmwright commented Jun 5, 2022

@greyltc Is there an example that shows how it was wrong?

@greyltc
Copy link
Contributor Author

greyltc commented Jun 5, 2022

@greyltc Is there an example that shows how it was wrong?

I kinda hoped you'd look at this and say "oh yeah" ;-)

I do have an example (from when I ran into this the other day), but it's a long way from being minimal. I'll see if I can put something minimal together. Is there any case anywhere eachpoint(...,useLocalCoordinates=False) works? Could it be that be bug only appears when there's rotation involved in the transformation?

@greyltc
Copy link
Contributor Author

greyltc commented Jun 5, 2022

@jmwright, hopefully that ^^ issue report makes it clear!

@jmwright
Copy link
Member

jmwright commented Jun 7, 2022

I tried a few things with this change and I think the fix makes sense. It seems odd that this bug would have gone undiscovered for so long, so that made me suspicious that the way it was working was just counter-intuitive and not broken.

@gumyr Have you run into this bug before while working on cq_warehouse? Here's the accompanying issue: #1098

@gumyr
Copy link
Contributor

gumyr commented Jun 7, 2022 via email

@greyltc
Copy link
Contributor Author

greyltc commented Jun 8, 2022

I tried a few things with this change and I think the fix makes sense. It seems odd that this bug would have gone undiscovered for so long, so that made me suspicious that the way it was working was just counter-intuitive and not broken.

@gumyr Have you run into this bug before while working on cq_warehouse? Here's the accompanying issue: #1098

I think nobody's ever seen this because eachpoint(...,useLocalCoordinates=False) is never used. I haven't been able to find any instance where eachpoint() is used in the wild with useLocalCoordinates=False. Everyone seemingly always calls it with useLocalCoordinates=True, which does not run the line that his PR fixes.

Copy link
Member

@jmwright jmwright left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @greyltc

@jmwright
Copy link
Member

jmwright commented Jan 7, 2023

@adam-urbanczyk @lorenzncode Any objections to merging this?

@lorenzncode
Copy link
Member

@jmwright I would suggest not to merge this. There doesn't seem to be agreement on a description of the issue.

Here is a simpler example tested with master that looks correct to me.:

# global coordinates
pts = [
    (0, 20, 40),
    (10, 20, 40),
    (0, -20, 40),
]

cyl = cq.Solid.makeCylinder(2, 8, (0, 0, -4))

r = (
    cq.Workplane("XZ")
    .pushPoints(pts)
    .eachpoint(
        lambda loc: cyl.moved(loc),
        #useLocalCoordinates=True,
        useLocalCoordinates=False,
    )
)

With useLocalCoordinates=False, the cylinder centers are the same as pts.:

cq-editor console:

%precision 0
Out[1]: '%.0f'

[s.Center().toTuple() for s in r.solids().vals()]
Out[2]: [(-0, 20, 40), (10, 20, 40), (-0, -20, 40)]

The normal direction is also as expected (IMO).

r.faces("%Plane").val().normalAt()
Out[3]: Vector: (0.0, -1.0, 0.0)

When I test with this PR and again useLocalCoordinates=False I get:

[s.Center().toTuple() for s in r.solids().vals()]
Out[3]: [(-0, -40, 20), (10, -40, 20), (-0, -40, -20)]

@adam-urbanczyk
Copy link
Member

@adam-urbanczyk @lorenzncode Any objections to merging this?

We did not reach a conclusion on this topic, so -1 on merging as-is.

@greyltc
Copy link
Contributor Author

greyltc commented Jan 7, 2023

I think the root issue is #1099
This PR and the associated issue were my attempt at making things as consistent as I could in the case that root issue isn't solved.

So my favorite solution is to merge #1100 which obsoletes both issue #1098 and this PR

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.

eachpoint(...,useLocalCoordinates=False) has a coordinate transformation bug
5 participants