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>2012-07-11 22:17:48 +0400
committerCampbell Barton <ideasman42@gmail.com>2012-07-11 22:17:48 +0400
commita5127dba57490e0c0215e9cabfac1749585c53d1 (patch)
tree98911e5020e54806155e3a77db345f2b6882cb9f /source/blender/blenlib
parent2070cd5d4929b969046492e55da34736a9d6304c (diff)
vector versions of BLI_in_rctf / BLI_in_rcti, (BLI_in_rctf_v, BLI_in_rcti_v)
use where possible.
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r--source/blender/blenlib/BLI_rect.h28
-rw-r--r--source/blender/blenlib/BLI_scanfill.h3
-rw-r--r--source/blender/blenlib/intern/rct.c50
3 files changed, 52 insertions, 29 deletions
diff --git a/source/blender/blenlib/BLI_rect.h b/source/blender/blenlib/BLI_rect.h
index 0cf32eeb276..4d0e54e344c 100644
--- a/source/blender/blenlib/BLI_rect.h
+++ b/source/blender/blenlib/BLI_rect.h
@@ -48,26 +48,30 @@ extern "C" {
*
* \return True if \a rect is empty.
*/
-int BLI_rcti_is_empty(struct rcti *rect);
-int BLI_rctf_is_empty(struct rctf *rect);
+int BLI_rcti_is_empty(const struct rcti *rect);
+int BLI_rctf_is_empty(const struct rctf *rect);
void BLI_init_rctf(struct rctf *rect, float xmin, float xmax, float ymin, float ymax);
void BLI_init_rcti(struct rcti *rect, int xmin, int xmax, int ymin, int ymax);
void BLI_translate_rctf(struct rctf *rect, float x, float y);
void BLI_translate_rcti(struct rcti *rect, int x, int y);
void BLI_resize_rcti(struct rcti *rect, int x, int y);
void BLI_resize_rctf(struct rctf *rect, float x, float y);
-int BLI_in_rcti(struct rcti *rect, int x, int y);
-int BLI_in_rctf(struct rctf *rect, float x, float y);
-int BLI_segment_in_rcti(struct rcti *rect, int s1[2], int s2[2]);
-// int BLI_segment_in_rctf(struct rcti *rect, int s1[2], int s2[2]); // NOT NEEDED YET
-int BLI_isect_rctf(struct rctf *src1, struct rctf *src2, struct rctf *dest);
-int BLI_isect_rcti(struct rcti *src1, struct rcti *src2, struct rcti *dest);
-void BLI_union_rctf(struct rctf *rcta, struct rctf *rctb);
-void BLI_union_rcti(struct rcti *rcti1, struct rcti *rcti2);
+int BLI_in_rcti(const struct rcti *rect, const int x, const int y);
+int BLI_in_rcti_v(const struct rcti *rect, const int xy[2]);
+int BLI_in_rctf(const struct rctf *rect, const float x, const float y);
+int BLI_in_rctf_v(const struct rctf *rect, const float xy[2]);
+int BLI_segment_in_rcti(const struct rcti *rect, const int s1[2], const int s2[2]);
+#if 0 /* NOT NEEDED YET */
+int BLI_segment_in_rctf(struct rcti *rect, int s1[2], int s2[2]);
+#endif
+int BLI_isect_rctf(const struct rctf *src1, const struct rctf *src2, struct rctf *dest);
+int BLI_isect_rcti(const struct rcti *src1, const struct rcti *src2, struct rcti *dest);
+void BLI_union_rctf(struct rctf *rctf1, const struct rctf *rctf2);
+void BLI_union_rcti(struct rcti *rcti1, const struct rcti *rcti2);
void BLI_copy_rcti_rctf(struct rcti *tar, const struct rctf *src);
-void print_rctf(const char *str, struct rctf *rect);
-void print_rcti(const char *str, struct rcti *rect);
+void print_rctf(const char *str, const struct rctf *rect);
+void print_rcti(const char *str, const struct rcti *rect);
#ifdef __cplusplus
}
diff --git a/source/blender/blenlib/BLI_scanfill.h b/source/blender/blenlib/BLI_scanfill.h
index ceef378358b..cb996119fff 100644
--- a/source/blender/blenlib/BLI_scanfill.h
+++ b/source/blender/blenlib/BLI_scanfill.h
@@ -65,7 +65,8 @@ typedef struct ScanFillVert {
union {
struct ScanFillVert *v;
void *p;
- intptr_t l;
+ intptr_t l;
+ unsigned int u;
} tmp;
float co[3]; /* vertex location */
float xy[2]; /* 2D copy of vertex location (using dominant axis) */
diff --git a/source/blender/blenlib/intern/rct.c b/source/blender/blenlib/intern/rct.c
index b36c3c717c0..b4397ea4546 100644
--- a/source/blender/blenlib/intern/rct.c
+++ b/source/blender/blenlib/intern/rct.c
@@ -38,17 +38,17 @@
#include "DNA_vec_types.h"
#include "BLI_rect.h"
-int BLI_rcti_is_empty(rcti *rect)
+int BLI_rcti_is_empty(const rcti *rect)
{
return ((rect->xmax <= rect->xmin) || (rect->ymax <= rect->ymin));
}
-int BLI_rctf_is_empty(rctf *rect)
+int BLI_rctf_is_empty(const rctf *rect)
{
return ((rect->xmax <= rect->xmin) || (rect->ymax <= rect->ymin));
}
-int BLI_in_rcti(rcti *rect, int x, int y)
+int BLI_in_rcti(const rcti *rect, const int x, const int y)
{
if (x < rect->xmin) return 0;
if (x > rect->xmax) return 0;
@@ -57,7 +57,16 @@ int BLI_in_rcti(rcti *rect, int x, int y)
return 1;
}
-int BLI_in_rctf(rctf *rect, float x, float y)
+int BLI_in_rcti_v(const rcti *rect, const int xy[2])
+{
+ if (xy[0] < rect->xmin) return 0;
+ if (xy[0] > rect->xmax) return 0;
+ if (xy[1] < rect->ymin) return 0;
+ if (xy[1] > rect->ymax) return 0;
+ return 1;
+}
+
+int BLI_in_rctf(const rctf *rect, const float x, const float y)
{
if (x < rect->xmin) return 0;
if (x > rect->xmax) return 0;
@@ -66,6 +75,15 @@ int BLI_in_rctf(rctf *rect, float x, float y)
return 1;
}
+int BLI_in_rctf_v(const rctf *rect, const float xy[2])
+{
+ if (xy[0] < rect->xmin) return 0;
+ if (xy[0] > rect->xmax) return 0;
+ if (xy[1] < rect->ymin) return 0;
+ if (xy[1] > rect->ymax) return 0;
+ return 1;
+}
+
/* based closely on 'isect_line_line_v2_int', but in modified so corner cases are treated as intersections */
static int isect_segments(const int v1[2], const int v2[2], const int v3[2], const int v4[2])
{
@@ -80,7 +98,7 @@ static int isect_segments(const int v1[2], const int v2[2], const int v3[2], con
}
}
-int BLI_segment_in_rcti(rcti *rect, int s1[2], int s2[2])
+int BLI_segment_in_rcti(const rcti *rect, const int s1[2], const int s2[2])
{
/* first do outside-bounds check for both points of the segment */
if (s1[0] < rect->xmin && s2[0] < rect->xmin) return 0;
@@ -89,7 +107,7 @@ int BLI_segment_in_rcti(rcti *rect, int s1[2], int s2[2])
if (s1[1] > rect->ymax && s2[1] > rect->ymax) return 0;
/* if either points intersect then we definetly intersect */
- if (BLI_in_rcti(rect, s1[0], s1[1]) || BLI_in_rcti(rect, s2[0], s2[1])) {
+ if (BLI_in_rcti_v(rect, s1) || BLI_in_rcti_v(rect, s2)) {
return 1;
}
else {
@@ -115,7 +133,7 @@ int BLI_segment_in_rcti(rcti *rect, int s1[2], int s2[2])
}
}
-void BLI_union_rctf(rctf *rct1, rctf *rct2)
+void BLI_union_rctf(rctf *rct1, const rctf *rct2)
{
if (rct1->xmin > rct2->xmin) rct1->xmin = rct2->xmin;
if (rct1->xmax < rct2->xmax) rct1->xmax = rct2->xmax;
@@ -123,7 +141,7 @@ void BLI_union_rctf(rctf *rct1, rctf *rct2)
if (rct1->ymax < rct2->ymax) rct1->ymax = rct2->ymax;
}
-void BLI_union_rcti(rcti *rct1, rcti *rct2)
+void BLI_union_rcti(rcti *rct1, const rcti *rct2)
{
if (rct1->xmin > rct2->xmin) rct1->xmin = rct2->xmin;
if (rct1->xmax < rct2->xmax) rct1->xmax = rct2->xmax;
@@ -207,7 +225,7 @@ void BLI_resize_rctf(rctf *rect, float x, float y)
rect->ymax = rect->ymin + y;
}
-int BLI_isect_rctf(rctf *src1, rctf *src2, rctf *dest)
+int BLI_isect_rctf(const rctf *src1, const rctf *src2, rctf *dest)
{
float xmin, xmax;
float ymin, ymax;
@@ -237,7 +255,7 @@ int BLI_isect_rctf(rctf *src1, rctf *src2, rctf *dest)
}
}
-int BLI_isect_rcti(rcti *src1, rcti *src2, rcti *dest)
+int BLI_isect_rcti(const rcti *src1, const rcti *src2, rcti *dest)
{
int xmin, xmax;
int ymin, ymax;
@@ -269,19 +287,19 @@ int BLI_isect_rcti(rcti *src1, rcti *src2, rcti *dest)
void BLI_copy_rcti_rctf(rcti *tar, const rctf *src)
{
- tar->xmin = floor(src->xmin + 0.5f);
- tar->xmax = floor((src->xmax - src->xmin) + 0.5f);
- tar->ymin = floor(src->ymin + 0.5f);
- tar->ymax = floor((src->ymax - src->ymin) + 0.5f);
+ tar->xmin = floorf(src->xmin + 0.5f);
+ tar->xmax = floorf((src->xmax - src->xmin) + 0.5f);
+ tar->ymin = floorf(src->ymin + 0.5f);
+ tar->ymax = floorf((src->ymax - src->ymin) + 0.5f);
}
-void print_rctf(const char *str, rctf *rect)
+void print_rctf(const char *str, const rctf *rect)
{
printf("%s: xmin %.3f, xmax %.3f, ymin %.3f, ymax %.3f (%.3fx%.3f)\n", str,
rect->xmin, rect->xmax, rect->ymin, rect->ymax, rect->xmax - rect->xmin, rect->ymax - rect->ymin);
}
-void print_rcti(const char *str, rcti *rect)
+void print_rcti(const char *str, const rcti *rect)
{
printf("%s: xmin %d, xmax %d, ymin %d, ymax %d (%dx%d)\n", str,
rect->xmin, rect->xmax, rect->ymin, rect->ymax, rect->xmax - rect->xmin, rect->ymax - rect->ymin);