mirror of
https://github.com/HybridDog/vector_extras.git
synced 2024-11-22 15:33:44 +01:00
vector.triangle: (try to) avoid holes in neighbouring triangles
This commit is contained in:
parent
bc08421e20
commit
6f2bc919db
@ -3,3 +3,4 @@ TODO:
|
|||||||
* Figure out and implement 3D scanline search
|
* Figure out and implement 3D scanline search
|
||||||
* Add vector.hollowsphere, less positions than WorldEdit hollowsphere
|
* Add vector.hollowsphere, less positions than WorldEdit hollowsphere
|
||||||
* Add unit tests
|
* Add unit tests
|
||||||
|
* Use %a string format for vector.serialize so that it is reversible
|
||||||
|
6
init.lua
6
init.lua
@ -1041,6 +1041,10 @@ function funcs.triangle(pos1, pos2, pos3)
|
|||||||
return (pos[1] - p1[1]) * (p2[2] - p1[2])
|
return (pos[1] - p1[1]) * (p2[2] - p1[2])
|
||||||
- (pos[2] - p1[2]) * (p2[1] - p1[1])
|
- (pos[2] - p1[2]) * (p2[1] - p1[1])
|
||||||
end
|
end
|
||||||
|
-- eps is used to prevend holes in neighbouring triangles
|
||||||
|
-- It should be smaller than the smallest possible barycentric value
|
||||||
|
-- FIXME: I'm not sure if it really does what it should.
|
||||||
|
local eps = 0.5 / math.max(p2[1] - p1[1], p2[2] - p1[2])
|
||||||
local a_all_inv = 1.0 / edgefunc(pos1_2d, pos2_2d, pos3_2d)
|
local a_all_inv = 1.0 / edgefunc(pos1_2d, pos2_2d, pos3_2d)
|
||||||
local step_k3 = - (pos2_2d[1] - pos1_2d[1]) * a_all_inv
|
local step_k3 = - (pos2_2d[1] - pos1_2d[1]) * a_all_inv
|
||||||
local step_k1 = - (pos3_2d[1] - pos2_2d[1]) * a_all_inv
|
local step_k1 = - (pos3_2d[1] - pos2_2d[1]) * a_all_inv
|
||||||
@ -1055,7 +1059,7 @@ function funcs.triangle(pos1, pos2, pos3)
|
|||||||
local k1 = edgefunc(pos2_2d, pos3_2d, p) * a_all_inv
|
local k1 = edgefunc(pos2_2d, pos3_2d, p) * a_all_inv
|
||||||
for _ = p1[2], p2[2] do
|
for _ = p1[2], p2[2] do
|
||||||
local k2 = 1 - k1 - k3
|
local k2 = 1 - k1 - k3
|
||||||
if k1 >= 0 and k2 >= 0 and k3 >= 0 then
|
if k1 >= -eps and k2 >= -eps and k3 >= -eps then
|
||||||
-- On triangle
|
-- On triangle
|
||||||
local h = math.floor(k1 * pos1[dir] + k2 * pos2[dir] +
|
local h = math.floor(k1 * pos1[dir] + k2 * pos2[dir] +
|
||||||
k3 * pos3[dir] + 0.5)
|
k3 * pos3[dir] + 0.5)
|
||||||
|
Loading…
Reference in New Issue
Block a user