[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnuastro-commits] master e371182: Library(polygon): Fixed wrong ordinan

From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master e371182: Library(polygon): Fixed wrong ordinand index array during sorting
Date: Tue, 30 Jun 2020 11:47:40 -0400 (EDT)

branch: master
commit e371182148bd42878ff4012d064fdf78d764eff2
Author: Sachin Kumar Singh <>
Commit: Mohammad Akhlaghi <>

    Library(polygon): Fixed wrong ordinand index array during sorting
    During concave sorting of points, the ordinand index in
    `gal_polygon_verices_sort` was a bit wrong due to points being used from
    the partially sorted arrays A and B, which ideally should have been the
    user given `vertices` array.
    It fixed now and no changes have to be made on the function prototypes
    and hence no major changes have to be done for the options that uses it.
 lib/polygon.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/lib/polygon.c b/lib/polygon.c
index b476d5b..545a3c8 100644
--- a/lib/polygon.c
+++ b/lib/polygon.c
@@ -862,8 +862,11 @@ gal_polygon_vertices_sort(double *vertices, size_t n, 
size_t *ordinds)
   /* Now, we put the contents of A and B in the temporary array. Firstly,
      we put the contents of A and then save the last index of A (stored in
      i) and continue from that index while copying from B(using j). */
-  for(i=0; i<A_size; i++) tordinds[i]=A[i];
-  for(j=0; j<B_size; j++) tordinds[i++]=B[j];
+  for(i=0; i<A_size+B_size; i++)
+    {
+      tordinds[i].x=vertices[i*2];
+      tordinds[i].y=vertices[i*2+1];
+    }
   /* Now sort the arrays A and B w.r.t their x axis, sorting A in ascending
      order and B in descending order. */
@@ -874,6 +877,11 @@ gal_polygon_vertices_sort(double *vertices, size_t n, 
size_t *ordinds)
   for(i=0; i<A_size; i++) sorted[i]=A[i];
   for(j=0; j<B_size; j++) sorted[i++]=B[j];
+  /* For a check.
+  for(i=0; i<A_size+B_size; i++)
+    printf("sorted array := %lf %lf\n", sorted[i], sorted[i*2+1]);
+  */
   /* The temporary array is now used to find the location of points stored
      in sorted array and assign index in ordinds accordingly.*/
   for(i=0; i<n; i++)
@@ -883,4 +891,8 @@ gal_polygon_vertices_sort(double *vertices, size_t n, 
size_t *ordinds)
+  /* For a check.
+  for(i=0;i<n;i++) printf("%ld\n", ordinds[i]);
+  */

reply via email to

[Prev in Thread] Current Thread [Next in Thread]