summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSubodh Kumar <s7158.kumar@samsung.com>2015-08-28 16:27:21 +0900
committerChunEon Park <hermet@hermet.pe.kr>2015-08-28 16:30:29 +0900
commitb35d2f976267b3b03124108aafb1d56219930ab2 (patch)
treef13fb60bbf7a1797f2d92d0f96f99ae6b10ef941
parent0a7726252427029ee8506d33ce2d4447bd5e17c4 (diff)
Eina rectangle: Check for valid rectangle before taking intersection
Summary: Check for valid rectangle If any dst or src rectangle has zero width or height, intersection should not return true. @fix Test Plan: Added test cases Reviewers: cedric, herdsman, Hermet Reviewed By: Hermet Subscribers: shilpasingh, cedric Differential Revision: https://phab.enlightenment.org/D2990
-rw-r--r--src/lib/eina/eina_inline_rectangle.x22
-rw-r--r--src/tests/eina/eina_test_rectangle.c14
2 files changed, 27 insertions, 9 deletions
diff --git a/src/lib/eina/eina_inline_rectangle.x b/src/lib/eina/eina_inline_rectangle.x
index fafe1394a6..5956291dd3 100644
--- a/src/lib/eina/eina_inline_rectangle.x
+++ b/src/lib/eina/eina_inline_rectangle.x
@@ -19,6 +19,14 @@
19#ifndef EINA_INLINE_RECTANGLE_H__ 19#ifndef EINA_INLINE_RECTANGLE_H__
20#define EINA_INLINE_RECTANGLE_H__ 20#define EINA_INLINE_RECTANGLE_H__
21 21
22static inline Eina_Bool
23eina_rectangle_is_valid(const Eina_Rectangle *r)
24{
25 if (r->w <= 0 || r->h <= 0)
26 return EINA_FALSE;
27 return EINA_TRUE;
28}
29
22static inline int 30static inline int
23eina_spans_intersect(int c1, int l1, int c2, int l2) 31eina_spans_intersect(int c1, int l1, int c2, int l2)
24{ 32{
@@ -90,6 +98,9 @@ eina_rectangle_union(Eina_Rectangle *dst, const Eina_Rectangle *src)
90static inline Eina_Bool 98static inline Eina_Bool
91eina_rectangle_intersection(Eina_Rectangle *dst, const Eina_Rectangle *src) 99eina_rectangle_intersection(Eina_Rectangle *dst, const Eina_Rectangle *src)
92{ 100{
101 if (!(eina_rectangle_is_valid(dst)) || !(eina_rectangle_is_valid(src)))
102 return EINA_FALSE;
103
93 if (!(eina_rectangles_intersect(dst, src))) 104 if (!(eina_rectangles_intersect(dst, src)))
94 return EINA_FALSE; 105 return EINA_FALSE;
95 106
@@ -116,6 +127,9 @@ eina_rectangle_intersection(Eina_Rectangle *dst, const Eina_Rectangle *src)
116 if ((dst->y + dst->h) > (src->y + src->h)) 127 if ((dst->y + dst->h) > (src->y + src->h))
117 dst->h = src->y + src->h - dst->y; 128 dst->h = src->y + src->h - dst->y;
118 129
130 if (dst->w == 0 || dst->h == 0)
131 return EINA_FALSE;
132
119 return EINA_TRUE; 133 return EINA_TRUE;
120} 134}
121 135
@@ -137,14 +151,6 @@ eina_rectangle_rescale_out(const Eina_Rectangle *out, const Eina_Rectangle *in,
137 res->h = out->h; 151 res->h = out->h;
138} 152}
139 153
140static inline Eina_Bool
141eina_rectangle_is_valid(const Eina_Rectangle *r)
142{
143 if (r->w <= 0 || r->h <= 0)
144 return EINA_FALSE;
145 return EINA_TRUE;
146}
147
148static inline int 154static inline int
149eina_rectangle_max_x(Eina_Rectangle *thiz) 155eina_rectangle_max_x(Eina_Rectangle *thiz)
150{ 156{
diff --git a/src/tests/eina/eina_test_rectangle.c b/src/tests/eina/eina_test_rectangle.c
index 089b68b1d7..08f8384dfa 100644
--- a/src/tests/eina/eina_test_rectangle.c
+++ b/src/tests/eina/eina_test_rectangle.c
@@ -74,7 +74,7 @@ END_TEST
74 74
75START_TEST(eina_rectangle_union_intersect) 75START_TEST(eina_rectangle_union_intersect)
76{ 76{
77 Eina_Rectangle r1, r2, r3, r4, r5, r6, rd; 77 Eina_Rectangle r1, r2, r3, r4, r5, r6, r7, r8, rd;
78 78
79 fail_if(!eina_init()); 79 fail_if(!eina_init());
80 80
@@ -84,6 +84,9 @@ START_TEST(eina_rectangle_union_intersect)
84 EINA_RECTANGLE_SET(&r4, 30, 30, 50, 50); 84 EINA_RECTANGLE_SET(&r4, 30, 30, 50, 50);
85 EINA_RECTANGLE_SET(&r5, 10, 10, 0, 0); 85 EINA_RECTANGLE_SET(&r5, 10, 10, 0, 0);
86 EINA_RECTANGLE_SET(&r6, 30, 30, 0, 0); 86 EINA_RECTANGLE_SET(&r6, 30, 30, 0, 0);
87 EINA_RECTANGLE_SET(&r7, 10, 10, 5, 0);
88 EINA_RECTANGLE_SET(&r8, 10, 10, 0, 5);
89
87 90
88 rd = r1; 91 rd = r1;
89 92
@@ -111,6 +114,15 @@ START_TEST(eina_rectangle_union_intersect)
111 || rd.w != r1.w 114 || rd.w != r1.w
112 || rd.h != r1.h); 115 || rd.h != r1.h);
113 116
117 rd = r6;
118 fail_if(eina_rectangle_intersection(&rd, &r5));
119
120 rd = r7;
121 fail_if(eina_rectangle_intersection(&rd, &r3));
122
123 rd = r8;
124 fail_if(eina_rectangle_intersection(&rd, &r3));
125
114 rd = r1; 126 rd = r1;
115 eina_rectangle_union(&rd, &r3); 127 eina_rectangle_union(&rd, &r3);
116 fail_if(rd.x != 0 128 fail_if(rd.x != 0