intersects.c (3050B)
1/* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 */ 19 20#include "common/rect.h" 21 22#include <CUnit/CUnit.h> 23 24/** 25 * Test which verifies intersection testing via guac_common_rect_intersects(). 26 */ 27void test_rect__intersects() { 28 29 int res; 30 31 guac_common_rect min; 32 guac_common_rect rect; 33 34 guac_common_rect_init(&min, 10, 10, 10, 10); 35 36 /* Rectangle intersection - empty 37 * rectangle is outside */ 38 guac_common_rect_init(&rect, 25, 25, 5, 5); 39 res = guac_common_rect_intersects(&rect, &min); 40 CU_ASSERT_EQUAL(0, res); 41 42 /* Rectangle intersection - complete 43 * rectangle is completely inside */ 44 guac_common_rect_init(&rect, 11, 11, 5, 5); 45 res = guac_common_rect_intersects(&rect, &min); 46 CU_ASSERT_EQUAL(2, res); 47 48 /* Rectangle intersection - partial 49 * rectangle intersects UL */ 50 guac_common_rect_init(&rect, 8, 8, 5, 5); 51 res = guac_common_rect_intersects(&rect, &min); 52 CU_ASSERT_EQUAL(1, res); 53 54 /* Rectangle intersection - partial 55 * rectangle intersects LR */ 56 guac_common_rect_init(&rect, 18, 18, 5, 5); 57 res = guac_common_rect_intersects(&rect, &min); 58 CU_ASSERT_EQUAL(1, res); 59 60 /* Rectangle intersection - complete 61 * rect intersects along UL but inside */ 62 guac_common_rect_init(&rect, 10, 10, 5, 5); 63 res = guac_common_rect_intersects(&rect, &min); 64 CU_ASSERT_EQUAL(2, res); 65 66 /* Rectangle intersection - partial 67 * rectangle intersects along L but outside */ 68 guac_common_rect_init(&rect, 5, 10, 5, 5); 69 res = guac_common_rect_intersects(&rect, &min); 70 CU_ASSERT_EQUAL(1, res); 71 72 /* Rectangle intersection - complete 73 * rectangle intersects along LR but rest is inside */ 74 guac_common_rect_init(&rect, 15, 15, 5, 5); 75 res = guac_common_rect_intersects(&rect, &min); 76 CU_ASSERT_EQUAL(2, res); 77 78 /* Rectangle intersection - partial 79 * rectangle intersects along R but rest is outside */ 80 guac_common_rect_init(&rect, 20, 10, 5, 5); 81 res = guac_common_rect_intersects(&rect, &min); 82 CU_ASSERT_EQUAL(1, res); 83 84 /* Rectangle intersection - partial 85 * rectangle encloses min; which is a partial intersection */ 86 guac_common_rect_init(&rect, 5, 5, 20, 20); 87 res = guac_common_rect_intersects(&rect, &min); 88 CU_ASSERT_EQUAL(1, res); 89 90} 91