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

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntonio Vazquez <blendergit@gmail.com>2019-09-02 22:59:32 +0300
committerAntonio Vazquez <blendergit@gmail.com>2019-09-02 22:59:32 +0300
commit7e92cba70c11910363872d20af6afd5b47616264 (patch)
treef77eda4bfec82b52a56a6ed3a6f6ab722be7e982
parentdb4f7e2dc66d437b205f8097c2bdf9097b5c8834 (diff)
Fix T68964: Measureit Area computation error
The area was wrong when the scale was used because the scale was applied to the area, not to the sides of the are to compute.
-rw-r--r--measureit/measureit_geometry.py23
1 files changed, 15 insertions, 8 deletions
diff --git a/measureit/measureit_geometry.py b/measureit/measureit_geometry.py
index 8aa834dd..f1a09516 100644
--- a/measureit/measureit_geometry.py
+++ b/measureit/measureit_geometry.py
@@ -605,12 +605,17 @@ def draw_segments(context, myobj, op, region, rv3d):
if ms.gltype == 20: # Area
obverts = get_mesh_vertices(myobj)
tot = 0
+ if scene.measureit_scale is True:
+ ms_scale = scene.measureit_scale_factor
+ else:
+ ms_scale = 1.0
+
for face in ms.measureit_faces:
myvertices = []
for v in face.measureit_index:
myvertices.append(v.glidx)
- area = get_area_and_paint(myvertices, myobj, obverts, region, rv3d, rgba)
+ area = get_area_and_paint(myvertices, myobj, obverts, region, rv3d, rgba, ms_scale)
tot += area
# Draw Area number over first face
if len(ms.measureit_faces) > 0:
@@ -623,9 +628,6 @@ def draw_segments(context, myobj, op, region, rv3d):
d1, dn = distance(p1, p2)
midpoint3d = interpolate3d(p1, p2, fabs(d1 / 2))
- # Scale
- if scene.measureit_scale is True:
- tot = tot * scene.measureit_scale_factor
# mult by world scale
tot *= scale
@@ -659,7 +661,7 @@ def draw_segments(context, myobj, op, region, rv3d):
# Get polygon area and paint area
#
# ------------------------------------------
-def get_area_and_paint(myvertices, myobj, obverts, region, rv3d, rgba):
+def get_area_and_paint(myvertices, myobj, obverts, region, rv3d, rgba, ms_scale):
mymesh = myobj.data
totarea = 0
if len(myvertices) > 3:
@@ -687,7 +689,7 @@ def get_area_and_paint(myvertices, myobj, obverts, region, rv3d, rgba):
# Area
- area = get_triangle_area(p1, p2, p3)
+ area = get_triangle_area(p1, p2, p3, ms_scale)
totarea += area
elif len(myvertices) == 3:
@@ -702,7 +704,7 @@ def get_area_and_paint(myvertices, myobj, obverts, region, rv3d, rgba):
draw_triangle(screen_point_p1, screen_point_p2, screen_point_p3, rgba)
# Area
- area = get_triangle_area(p1, p2, p3)
+ area = get_triangle_area(p1, p2, p3, ms_scale)
totarea += area
else:
return 0.0
@@ -714,10 +716,15 @@ def get_area_and_paint(myvertices, myobj, obverts, region, rv3d, rgba):
# Get area using Heron formula
#
# ------------------------------------------
-def get_triangle_area(p1, p2, p3):
+def get_triangle_area(p1, p2, p3, scale=1.0):
d1, dn = distance(p1, p2)
d2, dn = distance(p2, p3)
d3, dn = distance(p1, p3)
+
+ d1 *= scale
+ d2 *= scale
+ d3 *= scale
+
per = (d1 + d2 + d3) / 2.0
area = sqrt(per * (per - d1) * (per - d2) * (per - d3))
return area