From 2633fda0ed1a08fef35fc5caf820fd455a21d16b Mon Sep 17 00:00:00 2001
From: Jean-Yves TINEVEZ <tinevez@pasteur.fr>
Date: Tue, 30 Jun 2020 23:30:35 +0200
Subject: [PATCH] Refactor center point into a function.

---
 src/area3d.m          |  8 ++------
 src/centered_points.m | 12 ++++++++++++
 2 files changed, 14 insertions(+), 6 deletions(-)
 create mode 100644 src/centered_points.m

diff --git a/src/area3d.m b/src/area3d.m
index c9b4d61..b47b52d 100644
--- a/src/area3d.m
+++ b/src/area3d.m
@@ -3,15 +3,11 @@ function [ area, uncorr_area ] = area3d( o )
     
     %% Deprojected 3D version.
     
-    p = o.boundary;
+     % Put all vertex coordinates with respect to center.
+    p = centered_points( o );
 
     n_vertices = size( p, 1 );
 
-    % Put all vertex coordinates with respect to center.
-    center = mean( p );
-    center = repmat( center, [ n_vertices, 1 ] );
-    p = p - center;
-    
     % Build small triangles.
     index = [ 2 : n_vertices 1 ];
     p1 = p;
diff --git a/src/centered_points.m b/src/centered_points.m
new file mode 100644
index 0000000..29f7cbb
--- /dev/null
+++ b/src/centered_points.m
@@ -0,0 +1,12 @@
+function p = centered_points( o )
+%CENTERED_POINTS Returns the 3D coordinates of the object bounds, with
+%respect to its center.
+
+    p = o.boundary;
+    n_vertices = size( p ,1 );
+    center = mean( p );
+    center = repmat( center, [ n_vertices, 1 ] );
+    p = p - center;
+
+end
+
-- 
GitLab