Skip to content

Check coplanarity using all points and distance tolerance - #1536

Open
antonsoo wants to merge 13 commits into
compas-dev:mainfrom
antonsoo:bugfix-coplanar-collinear-prefix
Open

antonsoo wants to merge 13 commits into
compas-dev:mainfrom
antonsoo:bugfix-coplanar-collinear-prefix

Conversation

@antonsoo

@antonsoo antonsoo commented Oct 18, 2026 •

Copy link
Copy Markdown

is_coplanar discards complete collinear triples while searching for a plane, then checks only the remaining points. Discarded points can lie outside that plane, so nonplanar clouds can return True. Polygon.is_planar inherits the result. For example:

from compas.geometry import is_coplanar

points = [[0, 0, 0], [1, 0, 0], [2, 0, 0],
          [0, 0, 1], [0, 1, 1], [1, 0, 1]]
assert not is_coplanar(points)  # Currently returns True.

Retain every input and use a stable baseline to define an initial plane. Center that plane between the extreme projections, allowing residuals on its basis points as well as the other samples. If it exceeds tolerance, fit a plane to all points in a stable local frame using the existing pure-Python fitter, then repeat the centered distance check. This handles noisy coplanar data without making three noisy samples exact constraints. tol consistently measures perpendicular distance; signature and dependencies stay the same.

Regressions cover discarded triples, duplicate prefixes, point order, weak normals, coordinate scales and noisy planes. All 1,069 tests pass, with 12 skips, in the compas3 Conda environment on Python 3.12. Independent recorded-image audits retain all prior corrections and exact controls across the original and smaller-unit clouds. A constructed noisy-plane audit derived from recorded scan coordinates corrects 72 rejected configurations out of 96, with an independent known-plane distance reference. These are repeated configurations of the source assets.

What type of change is this?

  • Bug fix in a backwards-compatible manner.

Checklist

  • Added a line to CHANGELOG.md under Unreleased.
  • All tests pass locally (invoke test).
  • Full-tree lint reports no errors (invoke lint).
  • Added tests that prove the fix is effective.

invoke format leaves all 472 files unchanged. Changed files pass Ruff lint and format checks. Full read-only lint reports the same two existing Rhino import-order errors on base and head; the automatic unrelated edits from invoke lint were restored.

The Sphinx HTML build passes. Documentation warnings and the unchanged baseline lint diagnostics are recorded with the validation results.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-25T23:27:19.726048Z ad84a74 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: af83cc2118

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +133 to +135
for c_index in range(1, len(points)):
if not is_colinear(a, points[b_index], points[c_index], tol):
break

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Select a well-conditioned third basis point

When the first three points are collinear and the next candidate is only just outside tol, this loop stops at that candidate, so the cross-product normal can itself be about tol; is_perpendicular_vector_vector then compares the unnormalised dot product to the same absolute tolerance and accepts points far from the plane. With the default tolerance, [[0,0,0],[1,0,0],[2,0,0],[10,0,0],[0,2.2e-10,0],[0,1,.4],[0,.5,-.4]] now returns True (both final points are 0.4 away from the selected z=0 plane, and the parent returned False). Choose c by maximum area/distance from the baseline, or otherwise condition the normal, before applying the plane checks.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed in a915f4b. The fallback now chooses the maximum-area third point. The four tolerance/order regressions, 1,032-test suite and documentation build pass. All 18,144 original image results remain unchanged.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a915f4ba78

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +132 to +133
b_index = max(range(1, len(points)), key=lambda i: distance_point_point(a, points[i]))
c_index = max(range(1, len(points)), key=lambda i: area_triangle([a, points[b_index], points[i]]))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Search all triangles when conditioning the fallback plane

When the first three points are collinear, this only maximizes triangles that contain fixed a and farthest b, so it can still select a weaker normal than a triangle elsewhere in the same cloud. The new evidence after the earlier third-point fix is [[0,0,0],[.05,0,0],[.1,0,0],[0,1e-4,0],[0,-1e-4,0],[.1,0,0],[0,0,9e-5]]: with the default tolerance this revision returns True whereas the parent returns False; the selected normal gives the last point a dot product of 9e-10, but the plane from points 3–5 gives 1.8e-9, and the point is actually 9e-5 away. Search all candidate triangles (or normalize the plane normal before testing distances) so the fallback cannot accept this noncoplanar cloud.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed in f76a38e. The predicate now divides by the normal length and uses distance tolerance throughout, including collinear detection. Your example is rejected; all 1,045 tests pass, and all 18,144 original image results remain unchanged.

@antonsoo antonsoo changed the title Check all points when determining coplanarity Check coplanarity using all points and distance tolerance Oct 19, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f76a38ebe0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

break
if not temp:
return True
c_index = max(range(1, len(points)), key=lambda i: distance_point_line(points[i], (a, b)))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Fit the tolerance plane instead of pinning noisy points

When samples lie on both sides of an underlying plane near tol, choosing three samples and forcing them to have zero residual can reject a cloud whose every point is within the documented distance tolerance. For [[0,0,0],[1,0,0],[0,1,0],[10,10,6e-10],[10,-10,-6e-10],[-10,10,-6e-10],[-10,-10,6e-10]], every point is at most 6e-10 from z=0 and the parent accepts it, but this revision selects indices 3 and 4 for the basis and measures the opposite corners at 1.2e-9, returning False with the default 1e-9 tolerance. Use a fitted/consensus plane, or otherwise allow residuals for the basis points, so an absolute point-to-plane tolerance does not produce these false negatives.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed in d5d3919. The plane offset now allows residuals for every point; if the initial plane fails, the existing pure-Python fitter runs in a stable local frame. Your example and all 96 noisy-plane configurations pass. All 1,069 tests pass, and every earlier recorded-workload result stays unchanged.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d5d3919998

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

for point, distance in zip(points, distances):
vector = subtract_vectors(point, a)
local.append([dot_vectors(vector, u), dot_vectors(vector, v), distance])
_, normal = bestfit_plane(local)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Avoid a sample-weighted fit as the rejection plane

When a noisy cloud has duplicate or densely sampled locations, bestfit_plane weights those samples and does not minimize the maximum residual, so this fallback can reject a cloud even though one plane satisfies the documented tolerance. For example, at the default tolerance, [[0,0,0],[1,0,0],[0,1,0]] + 5 * [[1,2,9e-10],[1,-2,9e-10],[-1,2,-9e-10],[-1,-2,-9e-10]] + [[10,0,-9e-10]] returns False: the fallback's centered half-width is about 1.27e-9, although every input is at most 9e-10 from z=0 (and the parent implementation accepts it). Use a minimax/consensus plane, or otherwise do not treat failure of this sample-weighted fit as proof of non-coplanarity.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Confirmed: this cloud returns False on this branch and True on main, and it returns True here once the duplicate points are removed. The fallback uses the existing least-squares bestfit_plane, which weights repeated samples. Exactly deciding whether some plane fits every point within tol needs a minimax (Chebyshev) plane fit, which is a linear program, and that seems too much for this predicate. main accepts this case only because it tests against the plane of the first three points. I've left this as is. If maintainers prefer, I can deduplicate the points before the fallback fit, which handles exact repeats but not dense near-repeats.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a66a1d7bfd

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

n = cross_vectors(subtract_vectors(b, a), subtract_vectors(c, a))
length = length_vector(n)

distances = [dot_vectors(n, subtract_vectors(point, a)) / length for point in points]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Guard against zero normals after the collinearity check

For exactly collinear floating-point inputs at large coordinate scales, the line-distance check can disagree with the cross product used here. With b = [100000000.1, 100000000.2, 0.0], calling is_coplanar([[0, 0, 0], b, [x / 4 for x in b], [x / 2 for x in b]]) raises ZeroDivisionError at the default tolerance, whereas the parent returns True. distance_point_line reports approximately 1.77e-9 for the quarter-point, bypassing the collinear early return, but n is exactly zero. Use the same baseline cross product for the collinearity check and normal construction, or otherwise handle a zero normal before dividing, so valid collinear inputs and Polygon.is_planar do not crash.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Confirmed and fixed in bca56d2. The collinearity check now uses the same cross product as the normal, so exactly collinear points return True instead of dividing by zero. Your example is now a test; it raises ZeroDivisionError before this commit. tests/compas/geometry: 587 passed.

For exactly collinear points far from the origin, distance_point_line could
report a point just above the tolerance while the cross product used for the
normal was exactly zero, so is_coplanar divided by zero.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bca56d28b7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

for point, distance in zip(points, distances):
vector = subtract_vectors(point, a)
local.append([dot_vectors(vector, u), dot_vectors(vector, v), distance])
_, normal = bestfit_plane(local)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Guard the fallback against singular local covariance

At the default tolerance, set b = [100000000.1, 100000000.2, 100000000.3] and points = [[0, 0, 0], b, [x / 2 for x in b], [x * (2.0 / 3.0) for x in b]]. Both is_coplanar(points) and Polygon(points).is_planar now raise ZeroDivisionError, whereas the parent returns True. These points are exactly coplanar because the third point is exactly half of the second. Unlike the earlier zero-normal failure, this input selects a nonzero cross product [0, 1, 0]; the local covariance then has three zero minors, and bestfit_plane divides by zero. Handle singular local fits or stabilize the frame before invoking the fitter so valid coplanar inputs cannot crash this boolean predicate.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Confirmed and fixed in f715afa. The largest cross product here is only rounding noise, so its direction gave a meaningless normal and the local fit got a rank-one cloud. A normal shorter than about 4 * eps * |ab| * |ac| now counts as collinear, so this returns True. Your case is now in the test; it raises ZeroDivisionError before this commit. With 3,000 random collinear, coplanar, near-collinear and off-plane sets per scale from 1 to 1e9, the new code raised nothing, and at scales 1 and 1e4 its results match the previous commit. tests/compas/geometry: 588 passed.

For points that are collinear up to rounding far from the origin, the
largest cross product with the baseline can be pure rounding noise. Its
direction then gave a meaningless normal, and the local fit of the
resulting rank-one cloud divided by zero. A normal shorter than about
4 eps |ab| |ac| now counts as collinear.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f715afaaa5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +146 to +147
if length <= noise or TOL.is_zero(length / baseline_length, tol):
return True

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Check other candidates before treating the cloud as collinear

For a long, thin cloud, the maximum-area candidate can fall below this noise bound even though another candidate has a reliable normal. With [[0,0,0],[1e8,0,0],[5e7,2e-8,0],[0,0,1e-8]], default-tolerance is_coplanar and Polygon.is_planar now return True (parent: False), although the narrowest enclosing slab has half-width approximately 4.47e-9, above 1e-9. The selected candidate has normal length 2 versus noise 4.44, but the last point has normal length 1 versus noise 8.9e-16; returning here ignores that usable direction. Check the other candidates or perform a robust distance test instead of accepting the entire cloud from one uncertain normal.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Confirmed, fixed in 5008ae1. The rounding bound is now computed per component from the products that form it, so the exact cross products of axis-aligned points get a bound near zero, and the normal comes from the candidate that exceeds its bound by the most. Your example returns False again and is now a test.

return True

n = cross_vectors(subtract_vectors(b, a), subtract_vectors(c, a))
distances = [dot_vectors(n, vector) / length for vector in vectors]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Normalize the normal before computing signed projections

For exactly planar points at large coordinate scales, taking the dot product with the unnormalized area vector first loses precision that the subsequent division cannot recover. [[0.,0.,0.],[1.,0.,-1.],[1e8,200000001.,-300000001.],[25000002.,50000001.25,-75000003.25]] lies exactly on x+y+z=0, but this revision returns False from both is_coplanar and Polygon.is_planar at the default tolerance, whereas the parent returns True. Here the unscaled dot product for the last point rounds to 2.0 instead of zero, injecting a false 3.85e-9 residual that also contaminates the fallback fit. Normalize n before projecting the points and use those consistent distances in the fit; doing so makes this example pass.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed in 5008ae1. The normal is normalized before projecting, and first loses its component along the baseline, where rounding puts error that tilts the plane along the points. Your example returns True and is now a test. A new seeded test checks 1,500 sets of a line plus one point 3e-9 off it at 1e4 scale; the previous commit reported 5 of them as not coplanar. Across random collinear, coplanar and off-plane sets at scales 1 and 1e4 the results otherwise match the previous commit, and nothing raises at any scale up to 1e9. At 1e8 a 1e-9 tolerance is below the float64 spacing there (1.5e-8), so for general orientations the answer depends on rounding for any method.

…e baseline

The worst-case bound eps |ab| |ac| was too loose for axis-aligned points,
whose cross products are exact, so a point with a usable normal could be
treated as collinear. Bound the rounding error from the products that
form each component instead, and take the candidate that exceeds its
bound by the most.

Rounding also tilts the normal along the baseline, which tilts the plane
along the points: a line and one point a few tolerances off it could be
reported as not coplanar. Remove that component, then normalize before
projecting.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5008ae1e6d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +160 to +161
if margins[c] <= 0:
return True

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Re-anchor before accepting an uncertain cloud as collinear

For a long, thin cloud, all margins can be nonpositive because the first point is a poor anchor, even when another anchor gives reliable normals. With L=2.**27, h=2.**-24, and points=[[0,0,0],[L,L,L],[L+h,L,L],[L,L+h,L]], the default-tolerance result is True (parent: False), although the narrowest enclosing slab's half-width is approximately 1.22e-8, over twelve times the tolerance. Moving the first point to the end returns False for the identical cloud. Unlike the earlier single-candidate failure, every candidate here is below its bound, so checking all candidates against the same anchor is insufficient; retry from the other baseline endpoint or use a robust fallback before declaring the cloud collinear.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I've left this one. The coordinates are 2^27, where the float64 spacing is 2^-25 (about 3e-8), and the slab half-width of 1.22e-8 is about 0.4 of that spacing. Distances computed from these coordinates carry rounding errors of the same size, so any method decides this case by rounding; the parent gets it right because the inputs are exact powers of two. Adding anchor retries would change which sub-ulp cases come out right, not whether they do. If you'd prefer a deterministic rule at that scale, the tolerance could be raised to a few ulps of the largest coordinate.

Comment on lines +166 to +167
along = dot_vectors(normals[c], u)
n = [normals[c][i] - along * u[i] for i in range(3)]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Prevent re-orthogonalization from tilting exact plane normals

For large exactly planar inputs, this re-orthogonalization can introduce rather than remove tilt. Set s=2.**24 and use [[0,0,0],[4*s,0,-4*s],[4*s,s,-5*s],[s,2*s,-3*s]]: every point lies exactly on x+y+z=0, but both is_coplanar and Polygon.is_planar return False at default tolerance (parent: True). Unlike the earlier unnormalized-projection issue, the cross product here is exact; the new along calculation rounds to 0.1875, changes one normalized component by an ulp, and produces a spurious 7.45e-9 residual. Removing only this correction makes the input pass. Use an error-aware orthogonalization so dot-product roundoff cannot corrupt an already accurate normal.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed in ad84a74. The correction is now skipped when the component along the baseline is within the rounding error of computing it (4 * eps * |n|), so an exact normal stays as it is, while the near-collinear cases that need the correction still pass. Your example is now a test.

For an exact normal, the computed component along the baseline is only
rounding, and subtracting it moved the normal by an ulp, enough for a
false residual at large coordinates.
@antonsoo

Copy link
Copy Markdown
Author

A summary of the Codex rounds, since there are several threads. On every input I tried, is_coplanar no longer raises: random collinear, coplanar, near-collinear and off-plane sets at scales from 1 to 1e9. At scales 1 and 1e4 it returns the expected answer for all of them, including a line with one point a few tolerances off it. From about 1e7 up, the default 1e-9 tolerance is smaller than the float64 spacing of the coordinates, so results there depend on rounding for any method; the thread I left open is such a case.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ad84a74489

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

n = [n[i] - along * u[i] for i in range(3)]
length = length_vector(n)
n = [value / length for value in n]
distances = [dot_vectors(n, vector) for vector in vectors]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Account for roundoff in normalized plane projections

For exactly planar points with large coordinates, these normalized dot products can still manufacture out-of-plane residuals. On Python 3.12, set s = 2.**25 and use [[0,0,0],[2*s,0,-s],[0,2*s,-s],[6*s,4*s,-5*s]]: every point exactly satisfies x+y+2*z=0, yet is_coplanar and consequently Polygon.is_planar return False at the default tolerance, while the parent returns True. This survives the earlier projection fixes: the normal is already normalized and the guarded along correction is not applied. The last projection rounds to -1.49e-8, and fitting those corrupted local coordinates still leaves a half-width of 1.74e-9. Use a compensated or error-aware distance computation before treating these projections as evidence of nonplanarity.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

This is another sub-ulp case: the coordinates reach 2e8, where the float64 spacing is about 3e-8, and the -1.49e-8 projection is half of that. An error-aware tolerance would accept it, but it would also accept the earlier [[0,0,0],[1e8,0,0],[5e7,2e-8,0],[0,0,1e-8]] case (slab half-width 4.5e-9), which needs to return False. At this scale the two requirements conflict without exact arithmetic, so I'm leaving it, as described in the summary comment.

This branch has not been deployed

No deployments
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.

1 participant