test_intersection.cpp
Go to the documentation of this file.
00001 // *****************************************************************************
00002 //
00003 // Copyright (c) 2017, Southwest Research Institute® (SwRI®)
00004 // All rights reserved.
00005 //
00006 // Redistribution and use in source and binary forms, with or without
00007 // modification, are permitted provided that the following conditions are met:
00008 //     * Redistributions of source code must retain the above copyright
00009 //       notice, this list of conditions and the following disclaimer.
00010 //     * Redistributions in binary form must reproduce the above copyright
00011 //       notice, this list of conditions and the following disclaimer in the
00012 //       documentation and/or other materials provided with the distribution.
00013 //     * Neither the name of Southwest Research Institute® (SwRI®) nor the
00014 //       names of its contributors may be used to endorse or promote products
00015 //       derived from this software without specific prior written permission.
00016 //
00017 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020 // ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
00021 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00022 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00023 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00024 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00026 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027 //
00028 // *****************************************************************************
00029 
00030 #include <gtest/gtest.h>
00031 
00032 #include <swri_geometry_util/intersection.h>
00033 
00034 TEST(IntersectionTests, Intersects)
00035 {
00036   cv::Vec2d c;
00037   ASSERT_TRUE(swri_geometry_util::LineIntersection(
00038       cv::Vec2d(0, 5),
00039       cv::Vec2d(10, 5),
00040       cv::Vec2d(5, 0),
00041       cv::Vec2d(5, 10),
00042       c));
00043 
00044   EXPECT_FLOAT_EQ(5.0, c[0]);
00045   EXPECT_FLOAT_EQ(5.0, c[1]);
00046 
00047   ASSERT_TRUE(swri_geometry_util::LineIntersection(
00048       cv::Vec2d(0, 6),
00049       cv::Vec2d(10, 6),
00050       cv::Vec2d(5, 0),
00051       cv::Vec2d(5, 10),
00052       c));
00053 
00054   EXPECT_FLOAT_EQ(5.0, c[0]);
00055   EXPECT_FLOAT_EQ(6.0, c[1]);
00056 
00057   ASSERT_TRUE(swri_geometry_util::LineIntersection(
00058       cv::Vec2d(10, 6),
00059       cv::Vec2d(0, 6),
00060       cv::Vec2d(5, 10),
00061       cv::Vec2d(5, 0),
00062       c));
00063 
00064   EXPECT_FLOAT_EQ(5.0, c[0]);
00065   EXPECT_FLOAT_EQ(6.0, c[1]);
00066 
00067   ASSERT_TRUE(swri_geometry_util::LineIntersection(
00068       cv::Vec2d(5, 10),
00069       cv::Vec2d(5, 0),
00070       cv::Vec2d(10, 6),
00071       cv::Vec2d(0, 6),
00072       c));
00073 
00074   EXPECT_FLOAT_EQ(5.0, c[0]);
00075   EXPECT_FLOAT_EQ(6.0, c[1]);
00076 
00077   ASSERT_TRUE(swri_geometry_util::LineIntersection(
00078       cv::Vec2d(10, 10),
00079       cv::Vec2d(0, 0),
00080       cv::Vec2d(0, 10),
00081       cv::Vec2d(10, 0),
00082       c));
00083 
00084   EXPECT_FLOAT_EQ(5.0, c[0]);
00085   EXPECT_FLOAT_EQ(5.0, c[1]);
00086 
00087   ASSERT_TRUE(swri_geometry_util::LineIntersection(
00088       cv::Vec2d(-10, -10),
00089       cv::Vec2d(0, 0),
00090       cv::Vec2d(0, -10),
00091       cv::Vec2d(-10, 0),
00092       c));
00093 
00094   EXPECT_FLOAT_EQ(-5.0, c[0]);
00095   EXPECT_FLOAT_EQ(-5.0, c[1]);
00096 }
00097 
00098 TEST(IntersectionTests, Parallel)
00099 {
00100   cv::Vec2d c;
00101   EXPECT_FALSE(swri_geometry_util::LineIntersection(
00102       cv::Vec2d(0, 0),
00103       cv::Vec2d(0, 0),
00104       cv::Vec2d(0, 0),
00105       cv::Vec2d(0, 0),
00106       c));
00107 
00108   EXPECT_FALSE(swri_geometry_util::LineIntersection(
00109       cv::Vec2d(0, 0),
00110       cv::Vec2d(10, 0),
00111       cv::Vec2d(0, 0),
00112       cv::Vec2d(10, 0),
00113       c));
00114 
00115   EXPECT_FALSE(swri_geometry_util::LineIntersection(
00116       cv::Vec2d(0, 0),
00117       cv::Vec2d(10, 0),
00118       cv::Vec2d(25, 0),
00119       cv::Vec2d(15, 0),
00120       c));
00121 
00122   EXPECT_FALSE(swri_geometry_util::LineIntersection(
00123       cv::Vec2d(0, 0),
00124       cv::Vec2d(10, 0),
00125       cv::Vec2d(0, -1),
00126       cv::Vec2d(10, -1),
00127       c));
00128 }
00129 
00130 // Run all the tests that were declared with TEST()
00131 int main(int argc, char **argv)
00132 {
00133   testing::InitGoogleTest(&argc, argv);
00134 
00135   return RUN_ALL_TESTS();
00136 }


swri_geometry_util
Author(s): Marc Alban
autogenerated on Tue Oct 3 2017 03:19:17