Skip to content

Commit

Permalink
post merge dev_variant
Browse files Browse the repository at this point in the history
  • Loading branch information
skramm committed Apr 20, 2024
2 parents df007e2 + fd4f03a commit 67e7253
Show file tree
Hide file tree
Showing 21 changed files with 1,397 additions and 779 deletions.
16 changes: 10 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ ifeq ($(USE_BOOSTGEOM),Y)
endif

ifeq ($(USE_RTP),Y)
CXXFLAGS += -DHOMOG2D_ENABLE_RTP
CXXFLAGS += -DHOMOG2D_ENABLE_PRTP
endif

ifeq ($(DEBUG),Y)
Expand Down Expand Up @@ -173,10 +173,10 @@ BUILD/test_single: misc/test_files/single_file.cpp homog2d.hpp Makefile buildf
$(CXX) $(CXXFLAGS) -O2 -o $@ $< $(LDFLAGS)

BUILD/%.o: misc/test_files/%.cpp homog2d.hpp Makefile buildf
$(CXX) -c $< -o $@
$(CXX) $(CXXFLAGS) -c $< -o $@

BUILD/test_multiple: BUILD/test_multiple.o BUILD/mylib.o buildf
$(CXX) -o BUILD/test_multiple BUILD/test_multiple.o BUILD/mylib.o
$(CXX) $(CXXFLAGS) -o BUILD/test_multiple BUILD/test_multiple.o BUILD/mylib.o $(LDFLAGS)


# temporarly removed from target testall: speed_test_b
Expand Down Expand Up @@ -213,13 +213,17 @@ 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:"
test_rtp: BUILD/homog2d_test_rtp BUILD/homog2d_test_rtp_2
@echo "-Running RTP test 1:"
@BUILD/homog2d_test_rtp
@echo "-Running RTP test 2:"
@BUILD/homog2d_test_rtp_2


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

#=======================================================================
# speed test
Expand Down
4 changes: 2 additions & 2 deletions docs/homog2d_Polyline.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
The two classes, open and closed type, are actually the same class and are defined as:
```
template<typename T>
using CPolyline_ = base::PolylineBase<type::IsClosed,T>;
using CPolyline_ = base::PolylineBase<typ::IsClosed,T>;
template<typename T>
using OPolyline_ = base::PolylineBase<type::IsOpen,T>;
using OPolyline_ = base::PolylineBase<typ::IsOpen,T>;
```

### Difference between these two types:
Expand Down
19 changes: 11 additions & 8 deletions docs/homog2d_devinfo.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,15 @@ the implementation of that type only holds a `static_assert`, so that can be cat

With C++, polymorphism can be achieved in two ways:

- classical run-time polymorphism, achieved with virtual functions.
- classical runtime polymorphism, achieved with virtual functions.
This is particularly useful when the need is to have a container holding objects of different types, and then calling a virtual member function on each object.
- static Compile-time polymorphism, using function overloading.

The general design here is to use compile-time polymorphism.
However, in some situations, run-time polymorphism is required.
However, in some situations, runtime polymorphism is required.
For example when one wants to import an SVG file, because we can't determine the types of objects that will be read.

When inheriting concrete classes from a class template, we face a problem if we need to achieve run-time polymorphism,
When inheriting concrete classes from a class template, we face a problem if we need to achieve runtime polymorphism,
Consider this inheritance:
```
template<typename T>
Expand Down Expand Up @@ -144,10 +144,13 @@ Here, the member function `Dtype dtype()` enables us to fetch the underlying num
This is why we have here a double inheritance pattern, on all concrete types (geometric primitives):

- The class template `Common<T>`, provides common stuff for all types, and holds a default implementation for member functions not defined in the concrete types.
- The non-templated class `Root`, provides real-time polymorphism.
This latter inheritance is only enabled if symbol `HOMOG2D_ENABLE_RTP` is defined
- The non-templated class `Root`, provides real-time polymorphism through pointers.
This latter inheritance is only enabled if symbol `HOMOG2D_ENABLE_PRTP` is defined
(see [build options](homog2d_manual.md#build_options)).

However, the pointer-based technique is error prone: no type safety, and bad casting will lead to segfaults.
So we have also another way of handling runtime polymorphism, by switching to C++17 and using `std::variant`.
[See here](homog2d_manual.md#section_rtp) for details.

### 4.3 - Bounding Boxes

Expand Down Expand Up @@ -178,11 +181,11 @@ The table below summarizes what happens when attempt to call `getBB()` on an obj
| `CPolyline` | may throw |
| `Ellipse` | never throws |

**Bounding box of two objects**
for `OPolyline` and `CPolyline`, the function will throw either if those primitives are empty, or if the points they hold do not define an area.

This library provides a free function `getBB( t1, t1 )` that will return the bounding boxes holding `t1` and `t2`.
**Bounding box of two objects**

However, when computing the common bounding box of two arbitrary elements, things are not exactly the same.
This library provides a free function `getBB( t1, t2 )` that will return the bounding boxes holding `t1` and `t2`, whatever the types involved.

* if one of the two objects is a line, no bounding box can be computed, so a call to `getBB()` with two lines will not compile.
* if both of the arguments have an area, then there is no problem
Expand Down
12 changes: 7 additions & 5 deletions docs/homog2d_history.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ See [Release page](https://github.com/skramm/homog2d/releases).
- Ellipse/line, ellipse/ellipse intersection (hard task...)
- add polygon union and intersection
- add non-convex polyline splitting into polygons
- extend run-time polymorphism capabilities
- extend runtime polymorphism capabilities
- add list-initialization with points to `PolylineBase_` class
- cleanout the `Intersect()` family of functions, so that they always return the same type
- add some feature to be able to print coordinates with desired precision at runtime
Expand All @@ -22,9 +22,11 @@ It will also enable run-time polymorphism without pointers, with the help of `st
- polygon minimization

- current master branch
- generalisation of bounding box of pair of objects
- Opencv Demo now requires C++17 (use of `std::variant`)
- added SVG import of `path` element, [see manual](homog2d_manual.md#svg_import_example).
- **heavy architectural change**: runtime polymorphism is now achieved in a more modern way, using `std::variant`, [see here](homog2d_manual.md#section_rtp).
This was possible by moving to C++17.
- removed requirement to pointer-based runtime polymorphism to import SVG file, by using `std::variant`.
- generalization of bounding box of pair of objects
- added SVG import of `path` element, [see manual](homog2d_manual.md#svg_import_example)
- bugfixes:
- https://github.com/skramm/homog2d/issues/11
- https://github.com/skramm/homog2d/issues/10
Expand Down Expand Up @@ -73,7 +75,7 @@ It will also enable run-time polymorphism without pointers, with the help of `st
- [v2.9](https://github.com/skramm/homog2d/releases/tag/v2.9), released on 2022-11-23
- added SVG drawing
- added SVG import, see [related manual section](homog2d_manual.md#svg_import).
- enable run-time polymorphism (wip), through class `detail::Common`
- enable runtime polymorphism (wip), through class `detail::Common`
- added variable frame rate for showcase demos, see `misc/showcase/gif_duration.data`
- added constructor for horizontal or vertical line using a point
- added bounding box for a container holding any primitive (see [manual/misc. section](homog2d_manual.md#misc))
Expand Down
Loading

0 comments on commit 67e7253

Please sign in to comment.