forked from bartvdbraak/blender
Document that tessellate_polygon() doesn't handle degenerate geometry
This 'fixes' T68554: 'API mathutils.geometry.tessellate_polygon returns bad results sometimes' by documenting the limitations of the current implementation. I've also added a unit test for the function, so that any change in this behaviour will get noticed. No functional changes.
This commit is contained in:
parent
1094e56041
commit
84c537e685
@ -1246,7 +1246,8 @@ PyDoc_STRVAR(M_Geometry_tessellate_polygon_doc,
|
||||
".. function:: tessellate_polygon(veclist_list)\n"
|
||||
"\n"
|
||||
" Takes a list of polylines (each point a pair or triplet of numbers) and returns "
|
||||
"the point indices for a polyline filled with triangles.\n"
|
||||
"the point indices for a polyline filled with triangles. Does not handle degenerate "
|
||||
"geometry (such as zero-length lines due to consecutive identical points).\n"
|
||||
"\n"
|
||||
" :arg veclist_list: list of polylines\n"
|
||||
" :rtype: list\n");
|
||||
|
@ -3,7 +3,7 @@
|
||||
# ./blender.bin --background -noaudio --python tests/python/bl_pyapi_mathutils.py -- --verbose
|
||||
import unittest
|
||||
from mathutils import Matrix, Vector, Quaternion
|
||||
from mathutils import kdtree
|
||||
from mathutils import kdtree, geometry
|
||||
import math
|
||||
|
||||
# keep globals immutable
|
||||
@ -488,6 +488,43 @@ class KDTreeTesting(unittest.TestCase):
|
||||
k.find((0,) * 3, filter=lambda i: None)
|
||||
|
||||
|
||||
class TesselatePolygon(unittest.TestCase):
|
||||
def test_empty(self):
|
||||
self.assertEqual([], geometry.tessellate_polygon([]))
|
||||
|
||||
def test_2d(self):
|
||||
polyline = [
|
||||
Vector((-0.14401324093341827, 0.1266411542892456)),
|
||||
Vector((-0.14401324093341827, 0.13)),
|
||||
Vector((0.13532273471355438, 0.1266411542892456)),
|
||||
Vector((0.13532273471355438, 0.13)),
|
||||
]
|
||||
expect = [(0, 1, 2), (0, 3, 2)]
|
||||
self.assertEqual(expect, geometry.tessellate_polygon([polyline]))
|
||||
|
||||
def test_3d(self):
|
||||
polyline = [
|
||||
Vector((-0.14401324093341827, 0.1266411542892456, -0.13966798782348633)),
|
||||
Vector((-0.14401324093341827, 0.1266411542892456, 0.13966798782348633)),
|
||||
Vector((0.13532273471355438, 0.1266411542892456, 0.13966798782348633)),
|
||||
Vector((0.13532273471355438, 0.1266411542892456, -0.13966798782348633)),
|
||||
]
|
||||
expect = [(2, 3, 0), (2, 0, 1)]
|
||||
self.assertEqual(expect, geometry.tessellate_polygon([polyline]))
|
||||
|
||||
def test_3d_degenerate(self):
|
||||
polyline = [
|
||||
Vector((-0.14401324093341827, -0.15269476175308228, -0.13966798782348633)),
|
||||
Vector((0.13532273471355438, -0.15269476175308228, -0.13966798782348633)),
|
||||
Vector((0.13532273471355438, -0.15269476175308228, -0.13966798782348633)),
|
||||
Vector((-0.14401324093341827, -0.15269476175308228, -0.13966798782348633)),
|
||||
]
|
||||
# If this returns a proper result, rather than [(0, 0, 0)], it could mean that
|
||||
# degenerate geometry is handled properly.
|
||||
expect = [(0, 0, 0)]
|
||||
self.assertEqual(expect, geometry.tessellate_polygon([polyline]))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
import sys
|
||||
sys.argv = [__file__] + (sys.argv[sys.argv.index("--") + 1:] if "--" in sys.argv else [])
|
||||
|
Loading…
Reference in New Issue
Block a user