Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2008-09-29 06:16:18 +0400
committerCampbell Barton <ideasman42@gmail.com>2008-09-29 06:16:18 +0400
commit25fc47aaf2a7898b81eb4617a1cd877832d675c2 (patch)
tree08f52b379f9a787044de0d3c7338a780b8acc0f1 /source/blender/blenlib
parentf001e587680a399cadc0db0d7d6737d890c7b784 (diff)
tests for 2d triangle and quad intersection would only work if the points were ordered clockwise.
now return 1 for clockwise, -1 for counter-clockwise and 0 for no intersection.
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r--source/blender/blenlib/intern/arithb.c48
1 files changed, 33 insertions, 15 deletions
diff --git a/source/blender/blenlib/intern/arithb.c b/source/blender/blenlib/intern/arithb.c
index 888a5ab2f64..0dda84b09fd 100644
--- a/source/blender/blenlib/intern/arithb.c
+++ b/source/blender/blenlib/intern/arithb.c
@@ -2553,29 +2553,47 @@ short IsectLLPt2Df(float x0,float y0,float x1,float y1,
} // end Intersect_Lines
#define SIDE_OF_LINE(pa,pb,pp) ((pa[0]-pp[0])*(pb[1]-pp[1]))-((pb[0]-pp[0])*(pa[1]-pp[1]))
-#define ISECT_EPSILON 1e-6
-
/* point in tri */
int IsectPT2Df(float pt[2], float v1[2], float v2[2], float v3[2])
{
- if ((SIDE_OF_LINE(v1,v2,pt)>=-ISECT_EPSILON) &&
- (SIDE_OF_LINE(v2,v3,pt)>=-ISECT_EPSILON) &&
- (SIDE_OF_LINE(v3,v1,pt)>=-ISECT_EPSILON))
- return 1;
- else {
- return 0;
+ if (SIDE_OF_LINE(v1,v2,pt)>=0.0) {
+ if (SIDE_OF_LINE(v2,v3,pt)>=0.0) {
+ if (SIDE_OF_LINE(v3,v1,pt)>=0.0) {
+ return 1;
+ }
+ }
+ } else {
+ if (! (SIDE_OF_LINE(v2,v3,pt)>=0.0) ) {
+ if (! (SIDE_OF_LINE(v3,v1,pt)>=0.0)) {
+ return -1;
+ }
+ }
}
+
+ return 0;
}
/* point in quad - only convex quads */
int IsectPQ2Df(float pt[2], float v1[2], float v2[2], float v3[2], float v4[2])
{
- if ((SIDE_OF_LINE(v1,v2,pt)>=-ISECT_EPSILON) &&
- (SIDE_OF_LINE(v2,v3,pt)>=-ISECT_EPSILON) &&
- (SIDE_OF_LINE(v3,v4,pt)>=-ISECT_EPSILON) &&
- (SIDE_OF_LINE(v4,v1,pt)>=-ISECT_EPSILON))
- return 1;
- else
- return 0;
+ if (SIDE_OF_LINE(v1,v2,pt)>=0.0) {
+ if (SIDE_OF_LINE(v2,v3,pt)>=0.0) {
+ if (SIDE_OF_LINE(v3,v4,pt)>=0.0) {
+ if (SIDE_OF_LINE(v4,v1,pt)>=0.0) {
+ return 1;
+ }
+ }
+ }
+ } else {
+ if (! (SIDE_OF_LINE(v2,v3,pt)>=0.0) ) {
+ if (! (SIDE_OF_LINE(v3,v4,pt)>=0.0)) {
+ if (! (SIDE_OF_LINE(v4,v1,pt)>=0.0)) {
+ return -1;
+ }
+ }
+ }
+ }
+
+ return 0;
}