[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnuastro-commits] master b0ffbef: book: update gal_polygon_clip definit
From: |
Mohammad Akhlaghi |
Subject: |
[gnuastro-commits] master b0ffbef: book: update gal_polygon_clip definition |
Date: |
Wed, 15 Dec 2021 06:50:19 -0500 (EST) |
branch: master
commit b0ffbef4788bf09ce0fc43da341c0377d0c8b551
Author: Pedram Ashofteh Ardakani <pedramardakani@pm.me>
Commit: Pedram Ashofteh Ardakani <pedramardakani@pm.me>
book: update gal_polygon_clip definition
Until now, the gal_polygon_clip had a small definition in the
manual. However, it was defined pretty well in the lib/polygon.c file.
With this commit, I have relocated the detailed definition to the Gnuastro
manual. Now, developers can read more about it in the manual itself,
without the need to visit the lib/polygon.c file for a better understanding
of gal_polygon_clip innerworkings.
---
doc/gnuastro.texi | 27 ++++++++++++++++++++++++++-
lib/polygon.c | 30 ++----------------------------
2 files changed, 28 insertions(+), 29 deletions(-)
diff --git a/doc/gnuastro.texi b/doc/gnuastro.texi
index 9e4d168..7fa39e1 100644
--- a/doc/gnuastro.texi
+++ b/doc/gnuastro.texi
@@ -29114,13 +29114,38 @@ Note that the polygon vertices have to be sorted
before calling this function.
Arrange the vertices of the sorted polygon in place, to be in a
counter-clockwise direction.
If the input polygon already has a counter-clockwise direction it won't touch
the input.
The return value is @code{1} on successful execution.
-This function is just a wrapper over @code{gal_polygon_is_counterclockwise},
and will reverse the order of the vertices when necessary necessary.
+This function is just a wrapper over @code{gal_polygon_is_counterclockwise},
and will reverse the order of the vertices when necessary.
@end deftypefun
@deftypefun void gal_polygon_clip (double @code{*s}, size_t @code{n}, double
@code{*c}, size_t @code{m}, double @code{*o}, size_t @code{*numcrn})
Clip (find the overlap of) two polygons.
This function uses the
@url{https://en.wikipedia.org/wiki/Sutherland%E2%80%93Hodgman_algorithm,
Sutherland-Hodgman} polygon clipping algorithm.
Note that the vertices of both polygons have to be sorted in an
anti-clock-wise manner.
+
+The Pseudocode from Wikipedia:
+@verbatim
+List outputList = subjectPolygon;
+for (Edge clipEdge in clipPolygon) do
+ List inputList = outputList;
+ outputList.clear();
+ Point S = inputList.last;
+ for (Point E in inputList) do
+ if (E inside clipEdge) then
+ if (S not inside clipEdge) then
+ outputList.add(ComputeIntersection(S,E,clipEdge));
+ end if
+ outputList.add(E);
+ else if (S inside clipEdge) then
+ outputList.add(ComputeIntersection(S,E,clipEdge));
+ end if
+ S = E;
+ done
+done
+@end verbatim
+
+The difference is that we are not using lists, but arrays to keep polygon
vertices.
+The two polygons are called Subject @code{s} and Clip @code{c} with @code{n}
and @code{m} vertices respectively.
+The output is stored in @code{o} and the number of elements in the output are
stored in what @code{*numcrn} (for number of corners) points to.
@end deftypefun
@deftypefun void gal_polygon_vertices_sort (double @code{*vertices}, size_t
@code{n}, size_t @code{*ordinds})
diff --git a/lib/polygon.c b/lib/polygon.c
index 7566f1c..6655a05 100644
--- a/lib/polygon.c
+++ b/lib/polygon.c
@@ -6,6 +6,7 @@ Original author:
Mohammad Akhlaghi <mohammad@akhlaghi.org>
Contributing author(s):
Sachin Kumar Singh <sachinkumarsingh092@gmail.com>
+ Pedram Ashofteh Ardakani <pedramardakani@pm.me>
Copyright (C) 2015-2021, Free Software Foundation, Inc.
Gnuastro is free software: you can redistribute it and/or modify it
@@ -529,34 +530,7 @@ seginfintersection(double *Aa, double *Ab, double *Ba,
double *Bb,
-/* Clip (find the overlap of) two polygons. This function uses the
- Sutherland-Hodgman polygon clipping psudocode from Wikipedia:
-
- List outputList = subjectPolygon;
- for (Edge clipEdge in clipPolygon) do
- List inputList = outputList;
- outputList.clear();
- Point S = inputList.last;
- for (Point E in inputList) do
- if (E inside clipEdge) then
- if (S not inside clipEdge) then
- outputList.add(ComputeIntersection(S,E,clipEdge));
- end if
- outputList.add(E);
- else if (S inside clipEdge) then
- outputList.add(ComputeIntersection(S,E,clipEdge));
- end if
- S = E;
- done
- done
-
- The difference is that we are not using lists, but arrays to keep
- polygon vertices. The two polygons are called Subject ('s') and
- Clip ('c') with 'n' and 'm' vertices respectively.
-
- The output is stored in 'o' and the number of elements in the
- output are stored in what '*numcrn' (for number of corners) points
- to.*/
+/* Clip (find the overlap of) two polygons. */
void
gal_polygon_clip(double *s, size_t n, double *c, size_t m,
double *o, size_t *numcrn)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnuastro-commits] master b0ffbef: book: update gal_polygon_clip definition,
Mohammad Akhlaghi <=