summaryrefslogtreecommitdiff
path: root/system/ZoneMinder/fix_zone_area_calc.patch
blob: d55488071ddceb362fb1087a287ca8b7c5d63f18 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
--- web/skins/classic/views/js/zone.js 2019-01-23 00:24:26.094085919 -0500
+++ web/skins/classic/views/js/zone.js.new 2019-01-23 00:25:13.871710907 -0500
@@ -347,6 +347,7 @@
   zone['Points'][index].x = x;
   var Point = $('zonePoly').points.getItem(index);
   Point.x = x;
+  updateArea();
 }

 function updateY( index ) {
@@ -359,6 +360,7 @@
   zone['Points'][index].y = y;
   var Point = $('zonePoly').points.getItem(index);
   Point.y = y;
+  updateArea();
 }

 function saveChanges( element ) {
@@ -697,11 +699,12 @@
   var n_coords = coords.length;
   var float_area = 0.0;

-  for ( i = 0, j = n_coords-1; i < n_coords; j = i++ ) {
-    var trap_area = ( ( coords[i].x - coords[j].x ) * ( coords[i].y + coords[j].y ) ) / 2;
-    float_area += trap_area;
-    //printf( "%.2f (%.2f)\n", float_area, trap_area );
+  for ( i = 0; i < n_coords-1; i++ ) {
+      var trap_area = (coords[i].x*coords[i+1].y - coords[i+1].x*coords[i].y) / 2;
+      float_area += trap_area;
   }
+  float_area += (coords[n_coords-1].x*coords[0].y - coords[0].x*coords[n_coords-1].y) / 2;
+
   return Math.round( Math.abs( float_area ) );
 }