浏览代码

libobs/graphics: Fix vec2 min/max functions

jpark37 4 年之前
父节点
当前提交
02d98b26a0
共有 1 个文件被更改,包括 8 次插入16 次删除
  1. 8 16
      libobs/graphics/vec2.h

+ 8 - 16
libobs/graphics/vec2.h

@@ -119,36 +119,28 @@ static inline float vec2_dist(const struct vec2 *v1, const struct vec2 *v2)
 
 static inline void vec2_minf(struct vec2 *dst, const struct vec2 *v, float val)
 {
-	if (v->x < val)
-		dst->x = val;
-	if (v->y < val)
-		dst->y = val;
+	dst->x = (v->x < val) ? v->x : val;
+	dst->y = (v->y < val) ? v->y : val;
 }
 
 static inline void vec2_min(struct vec2 *dst, const struct vec2 *v,
 			    const struct vec2 *min_v)
 {
-	if (v->x < min_v->x)
-		dst->x = min_v->x;
-	if (v->y < min_v->y)
-		dst->y = min_v->y;
+	dst->x = (v->x < min_v->x) ? v->x : min_v->x;
+	dst->y = (v->y < min_v->y) ? v->y : min_v->y;
 }
 
 static inline void vec2_maxf(struct vec2 *dst, const struct vec2 *v, float val)
 {
-	if (v->x > val)
-		dst->x = val;
-	if (v->y > val)
-		dst->y = val;
+	dst->x = (v->x > val) ? v->x : val;
+	dst->y = (v->y > val) ? v->y : val;
 }
 
 static inline void vec2_max(struct vec2 *dst, const struct vec2 *v,
 			    const struct vec2 *max_v)
 {
-	if (v->x > max_v->x)
-		dst->x = max_v->x;
-	if (v->y > max_v->y)
-		dst->y = max_v->y;
+	dst->x = (v->x > max_v->x) ? v->x : max_v->x;
+	dst->y = (v->y > max_v->y) ? v->y : max_v->y;
 }
 
 EXPORT void vec2_abs(struct vec2 *dst, const struct vec2 *v);