Ver Fonte

Fix olivec_normalize_rect() on zero rectangle

rexim há 3 anos atrás
pai
commit
4668dbe1c0
4 ficheiros alterados com 16 adições e 0 exclusões
  1. 1 0
      build.sh
  2. 4 0
      olive.c
  3. 11 0
      test.c
  4. BIN
      test/empty_rect_expected.png

+ 1 - 0
build.sh

@@ -22,6 +22,7 @@ mkdir -p ./build/assets/
 
 # Build tests
 clang $COMMON_CFLAGS -fsanitize=memory -o ./build/test -Ithirdparty test.c -lm
+exit 0
 
 # Build VC demos
 build_vc_demo triangle &

+ 4 - 0
olive.c

@@ -334,6 +334,10 @@ OLIVECDEF bool olivec_normalize_rect(int x, int y, int w, int h,
                                      size_t pixels_width, size_t pixels_height,
                                      int *x1, int *x2, int *y1, int *y2)
 {
+    // No need to render empty rectangle
+    if (w == 0) return false;
+    if (h == 0) return false;
+
     *x1 = x;
     *y1 = y;
 

+ 11 - 0
test.c

@@ -513,6 +513,16 @@ Olivec_Canvas test_copy_flip_cut(void)
     return dst;
 }
 
+Olivec_Canvas test_empty_rect(void)
+{
+    size_t w = 8;
+    size_t h = 8;
+    Olivec_Canvas dst = canvas_alloc(w, h);
+    olivec_fill(dst, BACKGROUND_COLOR);
+    olivec_rect(dst, w/2, h/2, 0, 0, FOREGROUND_COLOR);
+    return dst;
+}
+
 Test_Case test_cases[] = {
     DEFINE_TEST_CASE(fill_rect),
     DEFINE_TEST_CASE(fill_circle),
@@ -530,6 +540,7 @@ Test_Case test_cases[] = {
     DEFINE_TEST_CASE(copy_out_of_bounds_cut),
     DEFINE_TEST_CASE(copy_flip),
     DEFINE_TEST_CASE(copy_flip_cut),
+    DEFINE_TEST_CASE(empty_rect),
 };
 #define TEST_CASES_COUNT (sizeof(test_cases)/sizeof(test_cases[0]))
 

BIN
test/empty_rect_expected.png