[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [50809] trunk/blender/source/blender/ blenlib: rect/point clamping function: BLI_rct*_clamp_pt_v

Campbell Barton ideasman42 at gmail.com
Sat Sep 22 14:23:18 CEST 2012


Revision: 50809
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=50809
Author:   campbellbarton
Date:     2012-09-22 12:23:17 +0000 (Sat, 22 Sep 2012)
Log Message:
-----------
rect/point clamping function: BLI_rct*_clamp_pt_v

Modified Paths:
--------------
    trunk/blender/source/blender/blenlib/BLI_rect.h
    trunk/blender/source/blender/blenlib/intern/rct.c

Modified: trunk/blender/source/blender/blenlib/BLI_rect.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_rect.h	2012-09-22 07:38:16 UTC (rev 50808)
+++ trunk/blender/source/blender/blenlib/BLI_rect.h	2012-09-22 12:23:17 UTC (rev 50809)
@@ -55,6 +55,8 @@
 void BLI_rctf_resize(struct rctf *rect, float x, float y);
 void BLI_rctf_interp(struct rctf *rect, const struct rctf *rect_a, const struct rctf *rect_b, const float fac);
 //void BLI_rcti_interp(struct rctf *rect, struct rctf *rect_a, struct rctf *rect_b, float fac);
+int  BLI_rctf_clamp_pt_v(const struct rctf *rect, float xy[2]);
+int  BLI_rcti_clamp_pt_v(const struct rcti *rect, int xy[2]);
 int  BLI_rctf_compare(const struct rctf *rect_a, const struct rctf *rect_b, const float limit);
 int  BLI_rcti_compare(const struct rcti *rect_a, const struct rcti *rect_b);
 int  BLI_rctf_isect(const struct rctf *src1, const struct rctf *src2, struct rctf *dest);

Modified: trunk/blender/source/blender/blenlib/intern/rct.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/rct.c	2012-09-22 07:38:16 UTC (rev 50808)
+++ trunk/blender/source/blender/blenlib/intern/rct.c	2012-09-22 12:23:17 UTC (rev 50809)
@@ -281,6 +281,27 @@
 
 /* BLI_rcti_interp() not needed yet */
 
+
+int BLI_rctf_clamp_pt_v(const struct rctf *rect, float xy[2])
+{
+	int change = 0;
+	if (xy[0] < rect->xmin) { xy[0] = rect->xmin; change = 1; }
+	if (xy[0] > rect->xmax) { xy[0] = rect->xmax; change = 1; }
+	if (xy[1] < rect->ymin) { xy[1] = rect->ymin; change = 1; }
+	if (xy[1] > rect->ymax) { xy[1] = rect->ymax; change = 1; }
+	return change;
+}
+
+int BLI_rcti_clamp_pt_v(const struct rcti *rect, int xy[2])
+{
+	int change = 0;
+	if (xy[0] < rect->xmin) { xy[0] = rect->xmin; change = 1; }
+	if (xy[0] > rect->xmax) { xy[0] = rect->xmax; change = 1; }
+	if (xy[1] < rect->ymin) { xy[1] = rect->ymin; change = 1; }
+	if (xy[1] > rect->ymax) { xy[1] = rect->ymax; change = 1; }
+	return change;
+}
+
 int BLI_rctf_compare(const struct rctf *rect_a, const struct rctf *rect_b, const float limit)
 {
 	if (fabsf(rect_a->xmin - rect_b->xmin) < limit)




More information about the Bf-blender-cvs mailing list