Path: blob/main/unittest/src/utils/geom/BoundaryTest.cpp
169684 views
/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2001-2025 German Aerospace Center (DLR) and others.3// This program and the accompanying materials are made available under the4// terms of the Eclipse Public License 2.0 which is available at5// https://www.eclipse.org/legal/epl-2.0/6// This Source Code may also be made available under the following Secondary7// Licenses when the conditions for such availability set forth in the Eclipse8// Public License 2.0 are satisfied: GNU General Public License, version 29// or later which is available at10// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html11// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later12/****************************************************************************/13/// @file BoundaryTest.cpp14/// @author Matthias Heppner15/// @author Michael Behrisch16/// @date 2009-05-2717///18// Tests the class Boundary19/****************************************************************************/20#include <config.h>2122#include <gtest/gtest.h>23#include <utils/geom/Boundary.h>242526/* Test the method 'add'*/27TEST(Boundary, test_method_add) {28Boundary bound;29bound.add(1, 2); // Will work for bound.add(2,1) too30EXPECT_DOUBLE_EQ(bound.xmax(), 1);31EXPECT_DOUBLE_EQ(bound.xmin(), 1);32EXPECT_DOUBLE_EQ(bound.ymax(), 2);33EXPECT_DOUBLE_EQ(bound.ymin(), 2);34}3536/* Test the method 'add' with multiple calls*/37TEST(Boundary, test_method_add_multiple) {38Boundary bound;39bound.add(-1, -2);40bound.add(3, 5);41bound.add(5, 8);42EXPECT_DOUBLE_EQ(bound.xmax(), 5);43EXPECT_DOUBLE_EQ(bound.xmin(), -1);44EXPECT_DOUBLE_EQ(bound.ymax(), 8);45EXPECT_DOUBLE_EQ(bound.ymin(), -2);46}4748/* Test the method 'getCenter'*/49TEST(Boundary, test_method_getCenter) {50Boundary bound(-2, -4, 4, 8);51Position pos = bound.getCenter();52EXPECT_DOUBLE_EQ(pos.x(), 1);53EXPECT_DOUBLE_EQ(pos.y(), 2);54}5556/* Test the method 'getWidth' and getHeight*/57TEST(Boundary, test_method_getWidthHeight) {58Boundary bound(-2, -4, 4, 8);59EXPECT_DOUBLE_EQ(bound.getHeight(), 12);60EXPECT_DOUBLE_EQ(bound.getWidth(), 6);61}6263/* Test the method 'around'*/64TEST(Boundary, test_method_around) {65Boundary bound(1, 2, 3, 6);66EXPECT_TRUE(bound.around(Position(2, 4)));67EXPECT_FALSE(bound.around(Position(0, 4)));68EXPECT_FALSE(bound.around(Position(2, 7)));69EXPECT_TRUE(bound.around(Position(0, 7), 2));70}7172/* Test the method 'overlapsWith'*/73TEST(Boundary, test_method_overlapsWith) {74Boundary bound(1, 2, 3, 6);75EXPECT_FALSE(bound.overlapsWith(Boundary(10, 17, 13, 16)));76EXPECT_TRUE(bound.overlapsWith(Boundary(-1, -7, 2, 4)));77EXPECT_TRUE(bound.overlapsWith(Boundary(1, 2, 3, 6)));78EXPECT_TRUE(bound.overlapsWith(Boundary(0, 3, 4, 5)));79EXPECT_FALSE(bound.overlapsWith(Boundary(4, 2, 5, 7), 0));80EXPECT_TRUE(bound.overlapsWith(Boundary(4, 2, 5, 7), 1));81}8283/* Test the method 'crosses'*/84TEST(Boundary, test_method_crosses) {85Boundary bound(1, 2, 3, 6);86EXPECT_TRUE(bound.crosses(Position(3, 2), Position(4, 2)));87EXPECT_TRUE(bound.crosses(Position(2, 1), Position(0, 3)));88EXPECT_TRUE(bound.crosses(Position(1, 2), Position(3, 6)));89EXPECT_FALSE(bound.crosses(Position(0, 0), Position(0, 8)));90}9192/* Test the method 'partialWithin'*/93TEST(Boundary, test_method_partialWithin) {94Boundary bound(1, 2, 3, 6);95EXPECT_TRUE(bound.partialWithin(Boundary(1, 2, 1, 2)));96EXPECT_FALSE(bound.partialWithin(Boundary(10, 17, 13, 16)));97EXPECT_TRUE(bound.partialWithin(Boundary(1, 2, 3, 6)));98EXPECT_TRUE(bound.partialWithin(Boundary(4, 2, 5, 7), 1));99}100101/* Test the method 'flipY'*/102TEST(Boundary, test_method_flipY) {103Boundary bound(1, 2, 3, 6);104bound.flipY();105EXPECT_DOUBLE_EQ(bound.xmax(), 3);106EXPECT_DOUBLE_EQ(bound.xmin(), 1);107EXPECT_DOUBLE_EQ(bound.ymax(), -2);108EXPECT_DOUBLE_EQ(bound.ymin(), -6);109}110111/* Test the method 'moveby'*/112TEST(Boundary, test_method_moveby) {113Boundary bound(1, 2, 3, 6);114bound.moveby(2.5, -3.5);115EXPECT_DOUBLE_EQ(bound.xmax(), 5.5);116EXPECT_DOUBLE_EQ(bound.xmin(), 3.5);117EXPECT_DOUBLE_EQ(bound.ymax(), 2.5);118EXPECT_DOUBLE_EQ(bound.ymin(), -1.5);119}120121122123/* Test the method 'growWidth'*/124TEST(Boundary, test_method_growWidth) {125Boundary bound(1, 2, 3, 6);126bound.growWidth(0.5);127EXPECT_DOUBLE_EQ(bound.xmin(), 0.5);128EXPECT_DOUBLE_EQ(bound.xmax(), 3.5);129}130131/* Test the method 'growHeight'*/132TEST(Boundary, test_method_growHeight) {133Boundary bound(1, 2, 3, 6);134bound.growHeight(0.5);135EXPECT_DOUBLE_EQ(bound.ymin(), 1.5);136EXPECT_DOUBLE_EQ(bound.ymax(), 6.5);137}138139140