diff options
Diffstat (limited to 'src/3rdparty/assimp/contrib/poly2tri/poly2tri/common/utils.h')
-rw-r--r-- | src/3rdparty/assimp/contrib/poly2tri/poly2tri/common/utils.h | 40 |
1 files changed, 32 insertions, 8 deletions
diff --git a/src/3rdparty/assimp/contrib/poly2tri/poly2tri/common/utils.h b/src/3rdparty/assimp/contrib/poly2tri/poly2tri/common/utils.h index f123fedaf..2424c712c 100644 --- a/src/3rdparty/assimp/contrib/poly2tri/poly2tri/common/utils.h +++ b/src/3rdparty/assimp/contrib/poly2tri/poly2tri/common/utils.h @@ -1,4 +1,4 @@ -/* +/* * Poly2Tri Copyright (c) 2009-2010, Poly2Tri Contributors * http://code.google.com/p/poly2tri/ * @@ -28,18 +28,26 @@ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - + #ifndef UTILS_H #define UTILS_H +// Otherwise #defines like M_PI are undeclared under Visual Studio +#define _USE_MATH_DEFINES + #include <exception> +#include <math.h> + +// C99 removes M_PI from math.h +#ifndef M_PI +#define M_PI 3.14159265358979323846264338327 +#endif namespace p2t { -const double PI = 3.1415926535897932384626433832795029; -const double PI_2 = 2 * PI; -const double PI_3div4 = 3 * PI / 4; -const double EPSILON = 1e-15; +const double PI_3div4 = 3 * M_PI / 4; +const double PI_div2 = 1.57079632679489661923; +const double EPSILON = 1e-12; enum Orientation { CW, CCW, COLLINEAR }; @@ -53,7 +61,7 @@ enum Orientation { CW, CCW, COLLINEAR }; * = (x1-x3)*(y2-y3) - (y1-y3)*(x2-x3) * </pre> */ -Orientation Orient2d(Point& pa, Point& pb, Point& pc) +Orientation Orient2d(const Point& pa, const Point& pb, const Point& pc) { double detleft = (pa.x - pc.x) * (pb.y - pc.y); double detright = (pa.y - pc.y) * (pb.x - pc.x); @@ -66,6 +74,7 @@ Orientation Orient2d(Point& pa, Point& pb, Point& pc) return CW; } +/* bool InScanArea(Point& pa, Point& pb, Point& pc, Point& pd) { double pdx = pd.x; @@ -97,7 +106,22 @@ bool InScanArea(Point& pa, Point& pb, Point& pc, Point& pd) return true; } +*/ + +bool InScanArea(const Point& pa, const Point& pb, const Point& pc, const Point& pd) +{ + double oadb = (pa.x - pb.x)*(pd.y - pb.y) - (pd.x - pb.x)*(pa.y - pb.y); + if (oadb >= -EPSILON) { + return false; + } + + double oadc = (pa.x - pc.x)*(pd.y - pc.y) - (pd.x - pc.x)*(pa.y - pc.y); + if (oadc <= EPSILON) { + return false; + } + return true; } -#endif +} +#endif |