some of my procs can have no result so I'd like them to return false or a value. For now I have
proc lintersect(p1, p2, p3, p4: Vec2, segments=false): (bool, Vec2) =
.
if parallel
return (false, vec2(0,0))
.
.
return (true, vec2(x,y))
proc findCentre(d1, p1, p2,: Vec2): Vec2 =
let
p11 = p1+vec2(-d1.x, d1.y)
p22 = p2+d1
c = lintersect(p1,p11,p2,p22)
if c[0]==true:
result = c[1]
echo findCentre results in (0,0), a value, even if c[0] = false. Do I have to keep carrying the (bool, vec2) tuple along or is there a way to return None, False ...?
Actually solved it in a different way, created an enum to pass meaningful information to the next proc.
type
Intersection = enum
intersect,
parallel,
zerolength,
notsegment
proc lintersect(p1, .....): (Intersection, Vec2) =
...
return (indicator, vec2)