Skip to content

Commit

Permalink
added run time polymorphism test file
Browse files Browse the repository at this point in the history
  • Loading branch information
skramm committed Dec 16, 2023
1 parent fda8ebf commit 3d9d06f
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 2 deletions.
10 changes: 9 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ newtests: newtests_before

.PHONY: pretest test test2 nobuild

test: pretest test2 nobuild
test: pretest test2 nobuild test_rtp
@echo "-done target $@"

test2: test_SY test_SN test_single test_multiple
Expand Down Expand Up @@ -211,6 +211,14 @@ test_bg_1: BUILD/bg_test_1 buildf
BUILD/bg_test_1: misc/test_files/bg_test_1.cpp homog2d.hpp Makefile buildf
$(CXX) $(CXXFLAGS) -O2 -o $@ $< $(LDFLAGS)

test_rtp: BUILD/homog2d_test_rtp
@echo "-Running RTP test:"
@BUILD/homog2d_test_rtp


BUILD/homog2d_test_rtp: misc/homog2d_test_rtp.cpp homog2d.hpp buildf
$(CXX) $(CXXFLAGS) -O2 -o $@ $< $(LDFLAGS) 2>BUILD/homog2d_test_rtp.stderr

#=======================================================================
# speed test
speed_test: speed_test_b
Expand Down
2 changes: 1 addition & 1 deletion docs/homog2d_manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ Check [this section](#frect_union) about union and intersection area of two rect
<a id="p_circle"></a>

These are modeled by their center point and radius.
Creation is straightforward, whathever your needs:
Creation is straightforward, whatever your needs:
```C++
Circle c1; // at (0,0), radius = 1
Circle c2( center_point ); // radius = 1
Expand Down
52 changes: 52 additions & 0 deletions misc/homog2d_test_rtp.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**************************************************************************
This file is part of the C++ library "homog2d", dedicated to
handle 2D lines and points, see https://github.com/skramm/homog2d
Author & Copyright 2019-2023 Sebastien Kramm
Contact: [email protected]
Licence: MPL v2
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at https://mozilla.org/MPL/2.0/.
**************************************************************************/

/**
\file homog2d_test_rtp.cpp
\brief This program will test the RunTime Polymorphism capabilities
*/


#define CATCH_CONFIG_RUNNER // alternative: main provided here
#include "catch.hpp"

#define HOMOG2D_TEST_MODE
#define HOMOG2D_ENABLE_RTP
#include "../homog2d.hpp"

using namespace h2d;

int main( int, char*)
{
Segment seg;
CPolyline pol;
Circle cir;
FRect rect;
std::vector<std::shared_ptr<detail::Root>> vec;
vec.push_back( std::make_shared<Circle>(cir) );
vec.push_back( std::make_shared<CPolyline>(pol) );
vec.push_back( std::make_shared<Segment>(seg) );
vec.push_back( std::make_shared<FRect>(rect) );

for( auto& e: vec )
{
std::cout << getString(e->type()) << ": " << *e
<< "\n -area = " << e->area()
<< "\n -length = " << e->length()
<< '\n';
}
}
4 changes: 4 additions & 0 deletions misc/no_build/no_build_18.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Polyline: cannot create an open polyline as a RCP

OPolyline op(4,5);

7 changes: 7 additions & 0 deletions misc/no_build/no_build_19.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// make sure that translate() requires numeric values

Circle c1;
FRect r;
r.translate( c1, 3 );


0 comments on commit 3d9d06f

Please sign in to comment.