Skip to content

Vector angles - #1529

Merged
chenkasirer merged 13 commits into
mainfrom
vector_angles
Aug 14, 2026
Merged

Vector angles#1529
chenkasirer merged 13 commits into
mainfrom
vector_angles

Conversation

@chenkasirer

Copy link
Copy Markdown
Member

This is a follow up to #1462
closes #1528

While there's no API change, this could be considered a breaking behavior change so flagged as such.

What type of change is this?

  • Bug fix in a backwards-compatible manner.
  • New feature in a backwards-compatible manner.
  • Breaking change: bug fix or new feature that involve incompatible API changes.
  • Other (e.g. doc update, configuration, etc)

Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.

  • I added a line to the CHANGELOG.md file in the Unreleased section under the most fitting heading (e.g. Added, Changed, Removed).
  • I ran all tests on my computer and it's all green (i.e. invoke test).
  • I ran lint on my computer and there are no errors (i.e. invoke lint).
  • I added new functions/classes and made them available on a second-level import, e.g. compas.datastructures.Mesh.
  • I have added tests that prove my fix is effective or that my feature works.
  • I have added necessary documentation (if appropriate)

@codecov

codecov Bot commented Aug 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 62.38%. Comparing base (256f6da) to head (b4fdcae).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1529      +/-   ##
==========================================
- Coverage   62.38%   62.38%   -0.01%     
==========================================
  Files         208      208              
  Lines       22486    22487       +1     
==========================================
  Hits        14029    14029              
- Misses       8457     8458       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Updates COMPAS’ vector angle utilities to treat undefined inputs as errors (instead of silently returning 0 / other sentinel values), aligning behavior with the discussion in #1528 and the follow-up context from #1462.

Changes:

  • angle_vectors now raises ValueError when either input vector has zero length.
  • angle_vectors_projected now raises ValueError when an input vector is parallel to the projection normal.
  • Adds/updates tests and documents the breaking behavior change in CHANGELOG.md.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
tests/compas/geometry/test_core.py Adds coverage for angle_vectors zero-vector inputs and angle_vectors_projected invalid projection cases.
src/compas/geometry/_core/angles.py Changes core angle helpers to raise ValueError for undefined inputs (zero-length / parallel-to-normal).
CHANGELOG.md Records the breaking behavior changes for both angle functions.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines 146 to +150
u_cross = cross_vectors(u, normal)
v_cross = cross_vectors(v, normal)

if TOL.is_allclose(u_cross, [0.0, 0.0, 0.0]) or TOL.is_allclose(v_cross, [0.0, 0.0, 0.0]):
raise ValueError("Cannot compute angle between vectors projected onto a plane defined by the normal vector. One of the vectors is parallel to the normal vector.")
Comment thread tests/compas/geometry/test_core.py
L = length_vector(u) * length_vector(v)
if TOL.is_zero(L, tol):
return 0
raise ValueError("Cannot compute the angle between one or more zero-length vectors.")

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.

perhaps the length check should be done on the individual vectors. otherwise two small vectors will also trigger the error, even when both vectors individually would qualify for a valid angle calculation

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.

something like

a = length_vector(u)
b = length_vector(v)

if TOL.is_zero(a, tol) or TOL.is_zero(b, tol):
    raise ValueError(...)

cosine = dot_vectors(u, v) / (a * b)

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.

btw, this is more or less what you do in the projected version

@chenkasirer
chenkasirer requested a review from tomvanmele August 13, 2026 11:44
@chenkasirer
chenkasirer merged commit 5fc43fe into main Aug 14, 2026
18 checks passed
@chenkasirer
chenkasirer deleted the vector_angles branch August 14, 2026 09:48
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.

angle_vectors returns 0 for zero-length vectors instead of raising an error

3 participants