Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1559 from anne-glerum/distance_to_polygon
Add distance to polygon function
- Loading branch information
Showing
5 changed files
with
128 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#include <aspect/simulator.h> | ||
#include <aspect/simulator_access.h> | ||
#include <aspect/utilities.h> | ||
|
||
#include <iostream> | ||
#include <typeinfo> | ||
|
||
int f() | ||
{ | ||
using namespace aspect::Utilities; | ||
|
||
const int dim=3; | ||
|
||
// A square polygon | ||
std::vector< Point<2> > polygon(4); | ||
polygon[0] = Point<2>(0.0,0.0); | ||
polygon[1] = Point<2>(1.0,0.0); | ||
polygon[2] = Point<2>(1.0,1.0); | ||
polygon[3] = Point<2>(0.0,1.0); | ||
|
||
// Some points inside and outside the polygon | ||
Point<2> points[] = {Point<2>(0.5,-1), Point<2>(0.5,0.5), Point<2>(0.001,0.2), Point<2>(2.0,2.0), Point<2>(0.001,0.75)}; | ||
|
||
std::cout << "Testing distance to polygon function with the following parameters: (polygon) " << polygon[0] << ", " << polygon[1] << ", " << polygon[2] << ", " << polygon[3] | ||
<< ", (points) " | ||
<< points[0] << ", " << points[1] << ", " << points[2] << ", " << points[3] << ", " | ||
<< points[4] << std::endl; | ||
|
||
for (unsigned int i = 0; i < 5; i++) | ||
{ | ||
std::cout << "Minimal distance of point " << points[i] << " to polygon = " << signed_distance_to_polygon<dim>(polygon,points[i]) << std::endl; | ||
} | ||
|
||
exit(0); | ||
return 42; | ||
} | ||
// run this function by initializing a global variable by it | ||
int i = f(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
set Additional shared libraries = tests/libprm_distance_polygon.so |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
----------------------------------------------------------------------------- | ||
----------------------------------------------------------------------------- | ||
|
||
Loading shared library <./libprm_distance_polygon.so> | ||
Testing distance to polygon function with the following parameters: (polygon) 0 0, 1 0, 1 1, 0 1, (points) 0.5 -1, 0.5 0.5, 0.001 0.2, 2 2, 0.001 0.75 | ||
Minimal distance of point 0.5 -1 to polygon = -1 | ||
Minimal distance of point 0.5 0.5 to polygon = 0.5 | ||
Minimal distance of point 0.001 0.2 to polygon = 0.001 | ||
Minimal distance of point 2 2 to polygon = -1.41421 | ||
Minimal distance of point 0.001 0.75 to polygon = 0.001 |