diff options
author | Campbell Barton <ideasman42@gmail.com> | 2013-08-22 03:33:50 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2013-08-22 03:33:50 +0400 |
commit | ccc1fc1499936aab7a98a1ff6a3df93b62859a41 (patch) | |
tree | 629e8d23d872f8ad9bbcd60bd6fe6c3636aaf2a6 | |
parent | 636b200709c457588b64176e45c9ef5c0ea0a3b2 (diff) |
minor internal change: isect_point_poly_v2 was assigning a value past the array bounds,
not that bad since it wasn't read but this isnt good practice and its simple to avoid.
-rw-r--r-- | source/blender/blenlib/BLI_math_geom.h | 4 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_geom.c | 16 |
2 files changed, 10 insertions, 10 deletions
diff --git a/source/blender/blenlib/BLI_math_geom.h b/source/blender/blenlib/BLI_math_geom.h index 6cb7103be9b..4c98c4be897 100644 --- a/source/blender/blenlib/BLI_math_geom.h +++ b/source/blender/blenlib/BLI_math_geom.h @@ -138,8 +138,8 @@ bool isect_ray_tri_epsilon_v3(const float p1[3], const float d[3], const float v0[3], const float v1[3], const float v2[3], float *r_lambda, float r_uv[2], const float epsilon); /* point in polygon */ -bool isect_point_poly_v2(const float pt[2], const float verts[][2], const int nr); -bool isect_point_poly_v2_int(const int pt[2], const int verts[][2], const int nr); +bool isect_point_poly_v2(const float pt[2], const float verts[][2], const unsigned int nr); +bool isect_point_poly_v2_int(const int pt[2], const int verts[][2], const unsigned int nr); int isect_point_quad_v2(const float p[2], const float a[2], const float b[2], const float c[2], const float d[2]); diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c index 9b8fd0ad85b..c0457d45f34 100644 --- a/source/blender/blenlib/intern/math_geom.c +++ b/source/blender/blenlib/intern/math_geom.c @@ -696,16 +696,15 @@ int isect_line_sphere_v2(const float l1[2], const float l2[2], } /* point in polygon (keep float and int versions in sync) */ -bool isect_point_poly_v2(const float pt[2], const float verts[][2], const int nr) +bool isect_point_poly_v2(const float pt[2], const float verts[][2], const unsigned int nr) { /* we do the angle rule, define that all added angles should be about zero or (2 * PI) */ float angletot = 0.0; float fp1[2], fp2[2]; - int i; + unsigned int i; const float *p1, *p2; p1 = verts[nr - 1]; - p2 = verts[0]; /* first vector */ fp1[0] = (float)(p1[0] - pt[0]); @@ -714,6 +713,8 @@ bool isect_point_poly_v2(const float pt[2], const float verts[][2], const int nr for (i = 0; i < nr; i++) { float dot, ang, cross; + p2 = verts[i]; + /* second vector */ fp2[0] = (float)(p2[0] - pt[0]); fp2[1] = (float)(p2[1] - pt[1]); @@ -730,21 +731,19 @@ bool isect_point_poly_v2(const float pt[2], const float verts[][2], const int nr /* circulate */ copy_v2_v2(fp1, fp2); p1 = p2; - p2 = verts[i + 1]; } return (fabsf(angletot) > 4.0f); } -bool isect_point_poly_v2_int(const int pt[2], const int verts[][2], const int nr) +bool isect_point_poly_v2_int(const int pt[2], const int verts[][2], const unsigned int nr) { /* we do the angle rule, define that all added angles should be about zero or (2 * PI) */ float angletot = 0.0; float fp1[2], fp2[2]; - int i; + unsigned int i; const int *p1, *p2; p1 = verts[nr - 1]; - p2 = verts[0]; /* first vector */ fp1[0] = (float)(p1[0] - pt[0]); @@ -753,6 +752,8 @@ bool isect_point_poly_v2_int(const int pt[2], const int verts[][2], const int nr for (i = 0; i < nr; i++) { float dot, ang, cross; + p2 = verts[i]; + /* second vector */ fp2[0] = (float)(p2[0] - pt[0]); fp2[1] = (float)(p2[1] - pt[1]); @@ -769,7 +770,6 @@ bool isect_point_poly_v2_int(const int pt[2], const int verts[][2], const int nr /* circulate */ copy_v2_v2(fp1, fp2); p1 = p2; - p2 = verts[i + 1]; } return (fabsf(angletot) > 4.0f); |