Skip to content

Commit

Permalink
Increase precision of dot bounds check
Browse files Browse the repository at this point in the history
  • Loading branch information
Denneisk committed Nov 19, 2024
1 parent f73616c commit a5afa5c
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lua/entities/gmod_wire_egp/lib/egplib/usefulfunctions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -349,12 +349,12 @@ function EGP:DrawPath( vertices, size, closed )
else
local dot = dir.x*lastdir.x + dir.y*lastdir.y
local scaling = size*math.tan(math.acos(dot)/2) -- complicated math, could be also be `size*sqrt(1-dot)/sqrt(dot+1)` (no idea what is faster)
if dot > 0.999 then -- also account for rounding errors, somehow the dot product can be >1, which makes scaling nan
if dot > 1 then -- also account for rounding errors, somehow the dot product can be >1, which makes scaling nan
-- direction stays the same, no need for a corner, just skip this point, unless it is the last segment of a closed path (last segment of a open path is handled explicitly above)
if i == num+1 then
corners[#corners+1] = { r={x=x1-dir.y*size, y=y1+dir.x*size}, l={x=x1+dir.y*size, y=y1-dir.x*size} }
end
elseif dot < -0.999 then -- new direction is inverse, just add perpendicular nodes
elseif dot < -1 then -- new direction is inverse, just add perpendicular nodes
corners[#corners+1] = { r={x=x1-dir.y*size, y=y1+dir.x*size}, l={x=x1+dir.y*size, y=y1-dir.x*size} }
elseif dir.x*-lastdir.y + dir.y*lastdir.x > 0 then -- right bend, checked by getting the dot product between dir and lastDir:rotate(90)
local offsetx = -lastdir.y*size-lastdir.x*scaling
Expand Down

0 comments on commit a5afa5c

Please sign in to comment.