Skip to content

Commit

Permalink
Fix #748: better error message for signarea
Browse files Browse the repository at this point in the history
  • Loading branch information
juliohm committed Feb 13, 2024
1 parent 3a9e8d5 commit d9d3bd9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/polytopes/ngon.jl
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ function signarea(t::Triangle{2})
signarea(v[1], v[2], v[3])
end

signarea(::Triangle{3}) = error("signed area only defined for triangles embedded in R², use `area` instead")

function normal(t::Triangle{3})
A, B, C = t.vertices
((B - A) × (C - A)) / 2
Expand Down
3 changes: 3 additions & 0 deletions test/polytopes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,9 @@
t = Triangle(P3(0, 0, 0), P3(1, 0, 0), P3(0, 1, 0))
@test isconvex(t)

t = Triangle(P3(0, 0, 0), P3(1, 0, 0), P3(0, 1, 0))
@test_throws ErrorException("signed area only defined for triangles embedded in R², use `area` instead") signarea(t)

t = Triangle(P2(0, 0), P2(1, 0), P2(0, 1))
@test sprint(show, t) == "Triangle((0.0, 0.0), (1.0, 0.0), (0.0, 1.0))"
if T === Float32
Expand Down

0 comments on commit d9d3bd9

Please sign in to comment.