Path: blob/main/unittest/src/utils/geom/GeomHelperTest.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 GeomHelperTest.cpp14/// @author Jakob Erdmann15/// @author Laura Bieker16/// @author Michael Behrisch17/// @date 2011-12-1218///19// Tests the class GeomHelper20/****************************************************************************/21#include <config.h>2223#include <gtest/gtest.h>24#include <utils/geom/Position.h>25#include <utils/geom/GeomHelper.h>2627using namespace std;2829/*30TEST(GeomHelper, test_method_intersects) {31// on the same line but non-overlapping segments32EXPECT_FALSE(GeomHelper::intersects(33Position(0,0), Position(1,0),34Position(2,0), Position(3,0)));3536// overlapping line segments37EXPECT_TRUE(GeomHelper::intersects(38Position(0,0), Position(2,0),39Position(1,0), Position(3,0)));4041// identical line segments42EXPECT_TRUE(GeomHelper::intersects(43Position(1,0), Position(3,0),44Position(1,0), Position(3,0)));4546// parallel line segments47EXPECT_FALSE(GeomHelper::intersects(48Position(0,0), Position(1,0),49Position(0,1), Position(1,1)));5051// intersection outside of segments52EXPECT_FALSE(GeomHelper::intersects(53Position(0,0), Position(2,0),54Position(1,3), Position(1,1)));5556// intersection at (1,0)57EXPECT_TRUE(GeomHelper::intersects(58Position(0,0), Position(2,0),59Position(1,3), Position(1,-1)));60}616263TEST(GeomHelper, test_method_intersection_position2D) {64Position expected(1,0);65Position pos = GeomHelper::intersection_position2D(66Position(0,0), Position(2,0),67Position(1,3), Position(1,-1));68EXPECT_FLOAT_EQ(expected.x(), pos.x());69EXPECT_FLOAT_EQ(expected.y(), pos.y());70// overlapping line segments71Position expected2(1.5,0);72Position pos2 = GeomHelper::intersection_position2D(73Position(0,0), Position(2,0),74Position(1,0), Position(3,0));75EXPECT_FLOAT_EQ(expected2.x(), pos2.x());76EXPECT_FLOAT_EQ(expected2.y(), pos2.y());77// identical line segments78Position expected3(1,0);79Position pos3 = GeomHelper::intersection_position2D(80Position(0,0), Position(2,0),81Position(0,0), Position(2,0));82EXPECT_FLOAT_EQ(expected3.x(), pos3.x());83EXPECT_FLOAT_EQ(expected3.y(), pos3.y());84}858687TEST(GeomHelper, test_method_closestDistancePointLine_basic) {88Position expected(1,0);89double expectedDistance = 1;90Position point(1,1);91Position start(0,0);92Position end(2,0);93Position closestPoint;94double result = GeomHelper::closestDistancePointLine2D(point, start, end, closestPoint);95EXPECT_FLOAT_EQ(expected.x(), closestPoint.x());96EXPECT_FLOAT_EQ(expected.y(), closestPoint.y());97EXPECT_FLOAT_EQ(expected.z(), closestPoint.z());98EXPECT_FLOAT_EQ(expectedDistance, result);99}100TEST(GeomHelper, test_method_closestDistancePointLine_onLine) {101Position expected(1,0);102double expectedDistance = 0;103Position point(1,0);104Position start(0,0);105Position end(2,0);106Position closestPoint;107double result = GeomHelper::closestDistancePointLine2D(point, start, end, closestPoint);108EXPECT_FLOAT_EQ(expected.x(), closestPoint.x());109EXPECT_FLOAT_EQ(expected.y(), closestPoint.y());110EXPECT_FLOAT_EQ(expected.z(), closestPoint.z());111EXPECT_FLOAT_EQ(expectedDistance, result);112}113TEST(GeomHelper, test_method_closestDistancePointLine_outside_after) {114Position expected(2,0);115double expectedDistance = 5;116Position point(5,4);117Position start(0,0);118Position end(2,0);119Position closestPoint;120double result = GeomHelper::closestDistancePointLine2D(point, start, end, closestPoint);121EXPECT_FLOAT_EQ(expected.x(), closestPoint.x());122EXPECT_FLOAT_EQ(expected.y(), closestPoint.y());123EXPECT_FLOAT_EQ(expected.z(), closestPoint.z());124EXPECT_FLOAT_EQ(expectedDistance, result);125}126TEST(GeomHelper, test_method_closestDistancePointLine_outside_before) {127Position expected(0,0);128double expectedDistance = 5;129Position point(-3,4);130Position start(0,0);131Position end(2,0);132Position closestPoint;133double result = GeomHelper::closestDistancePointLine2D(point, start, end, closestPoint);134EXPECT_FLOAT_EQ(expected.x(), closestPoint.x());135EXPECT_FLOAT_EQ(expected.y(), closestPoint.y());136EXPECT_FLOAT_EQ(expected.z(), closestPoint.z());137EXPECT_FLOAT_EQ(expectedDistance, result);138}*/139140141