Skip to content

fix eachpoint() with useLocalCoordinates=False coordinate transformation#1097

Open
greyltc wants to merge 1 commit into
CadQuery:masterfrom
greyltc:eachpoint-fix
Open

fix eachpoint() with useLocalCoordinates=False coordinate transformation#1097
greyltc wants to merge 1 commit into
CadQuery:masterfrom
greyltc:eachpoint-fix

Conversation

@greyltc

@greyltc greyltc commented Jun 5, 2022

Copy link
Copy Markdown
Contributor

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

@codecov

codecov Bot commented Jun 5, 2022

Copy link
Copy Markdown

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

jmwright commented Jun 5, 2022

Copy link
Copy Markdown
Member

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

@greyltc

greyltc commented Jun 5, 2022

Copy link
Copy Markdown
Contributor Author

@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

greyltc commented Jun 5, 2022

Copy link
Copy Markdown
Contributor Author

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

@jmwright

jmwright commented Jun 7, 2022

Copy link
Copy Markdown
Member

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

gumyr commented Jun 7, 2022 via email

Copy link
Copy Markdown
Contributor

@greyltc

greyltc commented Jun 8, 2022

Copy link
Copy Markdown
Contributor Author

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.

@jmwright jmwright left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @greyltc

@jmwright

jmwright commented Jan 7, 2023

Copy link
Copy Markdown
Member

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

@lorenzncode

Copy link
Copy Markdown
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
Copy Markdown
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

greyltc commented Jan 7, 2023

Copy link
Copy Markdown
Contributor Author

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