Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSybren A. Stüvel <sybren@blender.org>2020-01-27 18:42:25 +0300
committerSybren A. Stüvel <sybren@blender.org>2020-01-27 18:42:25 +0300
commit84c537e68528177ef982479f5884af07cec322b9 (patch)
tree25f7f99d75db929e688ea401ebf11d8016c1c637 /tests
parent1094e560413d38e9834ae563ef248f898cb8b201 (diff)
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.
Diffstat (limited to 'tests')
-rw-r--r--tests/python/bl_pyapi_mathutils.py39
1 files changed, 38 insertions, 1 deletions
diff --git a/tests/python/bl_pyapi_mathutils.py b/tests/python/bl_pyapi_mathutils.py
index 5aa95f9a5f7..9dfc6c159cc 100644
--- a/tests/python/bl_pyapi_mathutils.py
+++ b/tests/python/bl_pyapi_mathutils.py
@@ -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 [])