[Bf-blender-cvs] [6a4567b] master: BLI Rect: utility function to transform a point using 2 rect's

Campbell Barton noreply at git.blender.org
Sun Mar 9 06:21:37 CET 2014


Commit: 6a4567b9ab957ef912129f24aa4d3f60c3363c4f
Author: Campbell Barton
Date:   Sun Mar 9 15:48:09 2014 +1100
https://developer.blender.org/rB6a4567b9ab957ef912129f24aa4d3f60c3363c4f

BLI Rect: utility function to transform a point using 2 rect's

===================================================================

M	source/blender/blenlib/BLI_rect.h
M	source/blender/blenlib/intern/rct.c

===================================================================

diff --git a/source/blender/blenlib/BLI_rect.h b/source/blender/blenlib/BLI_rect.h
index dddfb8c..b86a5bc 100644
--- a/source/blender/blenlib/BLI_rect.h
+++ b/source/blender/blenlib/BLI_rect.h
@@ -52,6 +52,8 @@ void BLI_rctf_init_minmax(struct rctf *rect);
 void BLI_rcti_do_minmax_v(struct rcti *rect, const int xy[2]);
 void BLI_rctf_do_minmax_v(struct rctf *rect, const float xy[2]);
 
+void BLI_rctf_transform_pt_v(const rctf *dst, const rctf *src, float xy_dst[2], const float xy_src[2]);
+
 void BLI_rctf_translate(struct rctf *rect, float x, float y);
 void BLI_rcti_translate(struct rcti *rect, int x, int y);
 void BLI_rcti_recenter(struct rcti *rect, int x, int y);
diff --git a/source/blender/blenlib/intern/rct.c b/source/blender/blenlib/intern/rct.c
index 51bd9ee..61e5783 100644
--- a/source/blender/blenlib/intern/rct.c
+++ b/source/blender/blenlib/intern/rct.c
@@ -347,6 +347,16 @@ void BLI_rctf_do_minmax_v(rctf *rect, const float xy[2])
 	if (xy[1] > rect->ymax) rect->ymax = xy[1];
 }
 
+/* given 2 rectangles - transform a point from one to another */
+void BLI_rctf_transform_pt_v(const rctf *dst, const rctf *src, float xy_dst[2], const float xy_src[2])
+{
+	xy_dst[0] = ((xy_src[0] - src->xmin) / (src->xmax - src->xmin));
+	xy_dst[0] =               dst->xmin + ((dst->xmax - dst->xmin) * xy_dst[0]);
+
+	xy_dst[1] = ((xy_src[1] - src->ymin) / (src->ymax - src->ymin));
+	xy_dst[1] =               dst->ymin + ((dst->ymax - dst->ymin) * xy_dst[1]);
+}
+
 void BLI_rcti_translate(rcti *rect, int x, int y)
 {
 	rect->xmin += x;




More information about the Bf-blender-cvs mailing list