Skip to content

Commit 1a7acc2

Browse files
committed
Create a TracingError type that stores all context
Better than printing out since we can (A) check on it and (B) access the polygons as well as the a_list and b_list in Julia. I have a few plot recipes for them but not sure if they are worth putting in a Makie extension...they would also be inaccessible there. Maybe in GeoMakie? Then we can make full use of customizations etc.
1 parent 157a06d commit 1a7acc2

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

src/methods/clipping/clipping_processor.jl

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,45 @@ PolyNode(node::PolyNode{T};
9090

9191
# Checks equality of two PolyNodes by backing point value, fractional value, and intersection status
9292
equals(pn1::PolyNode, pn2::PolyNode) = pn1.point == pn2.point && pn1.inter == pn2.inter && pn1.fracs == pn2.fracs
93+
Base.:(==)(pn1::PolyNode, pn2::PolyNode) = equals(pn1, pn2)
94+
95+
# Finally, we define a nice error type for when the clipping tracing algorithm hits every point in a polygon.
96+
# This stores the polygons, the a_list, and the b_list, and the a_idx_list.
97+
# allowing the user to understand what happened and why.
98+
"""
99+
TracingError{T1, T2} <: Exception
100+
101+
An error that is thrown when the clipping tracing algorithm fails somehow.
102+
This is a bug in the algorithm, and should be reported.
103+
104+
The polygons are contained in the exception object, accessible by try-catch or as `err` in the REPL.
105+
"""
106+
struct TracingError{T1, T2, T} <: Exception
107+
message::String
108+
poly_a::T1
109+
poly_b::T2
110+
a_list::Vector{PolyNode{T}}
111+
b_list::Vector{PolyNode{T}}
112+
a_idx_list::Vector{Int}
113+
end
114+
115+
function Base.showerror(io::IO, e::TracingError{T1, T2}) where {T1, T2}
116+
print(io, "TracingError: ")
117+
println(io, e.message)
118+
println(io, "Please open an issue with the polygons contained in this error object.")
119+
println(io)
120+
if max(GI.npoint(e.poly_a), GI.npoint(e.poly_b)) < 10
121+
println(io, "Polygon A:")
122+
println(io, GI.coordinates(e.poly_a))
123+
println(io)
124+
println(io, "Polygon B:")
125+
println(io, GI.coordinates(e.poly_b))
126+
else
127+
println(io, "The polygons are contained in the exception object, accessible by try-catch or as `err` in the REPL.")
128+
end
129+
end
130+
131+
93132

94133
#=
95134
_build_ab_list(::Type{T}, poly_a, poly_b, delay_cross_f, delay_bounce_f; exact) ->

0 commit comments

Comments
 (0)