Skip to content

Commit 9dc98e1

Browse files
committed
type PointPair fixes + minor
1 parent 7b5d495 commit 9dc98e1

File tree

6 files changed

+59
-35
lines changed

6 files changed

+59
-35
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Try the above snippet
4646
[online here](https://godbolt.org/z/d9oqYs34f),
4747
or on your own Debian-style Linux box:
4848
```
49-
$ sudo apt install build-essentials
49+
$ sudo apt install build-essential
5050
$ wget https://raw.githubusercontent.com/skramm/homog2d/master/homog2d.hpp
5151
$ wget https://raw.githubusercontent.com/skramm/homog2d/master/misc/tryme.cpp
5252
$ g++ tryme.cpp

docs/homog2d_qa.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ It can be used to statically make sure that a call to a function meets some requ
2929
so it can be used to get the nature of an object, either with the free function
3030
(`auto t = type(obj);`)
3131
or with the corresponding member function.
32-
(`auto t = obj.type();`).
32+
(`auto t = obj.type();`).
3333
You can get is as text with the free function `getString(Type)`.
3434
* `Dtype` is an enum that is used to identify the numerical datatype of an object,
3535
[see manual here](homog2d_manual.md#numtype).
@@ -114,7 +114,6 @@ Thus, the need for the class `rtp::Root`
114114
</dd>
115115

116116

117-
118117
<dt>
119118
Q: `Circle_::center()` and `FRect_::getCenter()`?
120119
Why not the same identifier?
@@ -126,7 +125,16 @@ Thus, the intent is clearer.
126125
</dd>
127126

128127

129-
128+
<dt>
129+
Q: What is the difference between types `PointPair` and `Segment`?
130+
Don't these two types just hold two points?
131+
</dt>
132+
<dd>
133+
A: They both indeed hold two points, but they dont have the same semantic.
134+
The latter represents a real geometrical object, thus cannot have a null length
135+
(two identical points).
136+
The first one just hold two arbitrary points.
137+
</dd>
130138

131139

132140
<dt>

homog2d.hpp

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -384,11 +384,11 @@ using Segment_ = base::SegVec<typ::IsSegment,T>;
384384
template<typename T>
385385
using OSegment_ = base::SegVec<typ::IsOSeg,T>;
386386

387-
/// \todo 20250127: remove the first one and replace with `PointPair_`
388-
template<typename T>
389-
using PointPair1_ = std::pair<Point2d_<T>,Point2d_<T>>;
387+
390388
template<typename T1,typename T2>
391389
using PointPair2_ = std::pair<Point2d_<T1>,Point2d_<T2>>;
390+
template<typename T>
391+
using PointPair_ = std::pair<Point2d_<T>,Point2d_<T>>;
392392

393393
template<typename T>
394394
using CPolyline_ = base::PolylineBase<typ::IsClosed,T>;
@@ -1281,7 +1281,7 @@ shareCommonCoord( const std::pair<Point2d_<FPT1>,Point2d_<FPT2>>& ppts )
12811281
/// Private free function, get top-left and bottom-right points from two arbitrary points
12821282
/** Throws if one of the coordinates is equal to the other (x1=x2 or y1=y2)*/
12831283
template<typename FPT>
1284-
PointPair1_<FPT>
1284+
PointPair_<FPT>
12851285
getCorrectPoints( const Point2d_<FPT>& p0, const Point2d_<FPT>& p1 )
12861286
{
12871287
#ifndef HOMOG2D_NOCHECKS
@@ -2487,7 +2487,7 @@ class Intersect<Inters_2,FPT>: public IntersectCommon
24872487
}
24882488
size_t size() const { return _doesIntersect?2:0; }
24892489

2490-
PointPair1_<FPT>
2490+
PointPair_<FPT>
24912491
get() const
24922492
{
24932493
if( !_doesIntersect )
@@ -2629,7 +2629,7 @@ class FRect_: public detail::Common<FPT>
26292629

26302630
/// Constructor from pair of points
26312631
template<typename FPT2>
2632-
FRect_( const PointPair1_<FPT2>& ppts )
2632+
FRect_( const PointPair_<FPT2>& ppts )
26332633
{
26342634
set( ppts.first, ppts.second );
26352635
}
@@ -2730,7 +2730,7 @@ class FRect_: public detail::Common<FPT>
27302730

27312731
/// Returns the 2 major points of the rectangle
27322732
/// \sa getPts( const FRect_<FPT>& )
2733-
PointPair1_<FPT>
2733+
PointPair_<FPT>
27342734
getPts() const
27352735
{
27362736
return std::make_pair( _ptR1, _ptR2 );
@@ -3445,7 +3445,7 @@ Use of Sfinae so it can be selected only for arithmetic types
34453445

34463446
private:
34473447
template<typename FPT2>
3448-
bool implC_isInside( const PointPair1_<FPT2>& ppts ) const
3448+
bool implC_isInside( const PointPair_<FPT2>& ppts ) const
34493449
{
34503450
const auto& p1 = ppts.first;
34513451
const auto& p2 = ppts.second;
@@ -4098,15 +4098,15 @@ Thus, we need the second one.
40984098

40994099
/// Returns a pair of points that are lying on line at distance \c dist from a point defined by one of its coordinates.
41004100
template<typename FPT2>
4101-
PointPair1_<FPT>
4101+
PointPair_<FPT>
41024102
getPoints( GivenCoord gc, FPT coord, FPT2 dist ) const
41034103
{
41044104
return impl_getPoints_A( gc, coord, dist, detail::BaseHelper<LP>() );
41054105
}
41064106

41074107
/// Returns a pair of points that are lying on line at distance \c dist from point \c pt, assuming that one is lying on the line.
41084108
template<typename FPT2>
4109-
PointPair1_<FPT>
4109+
PointPair_<FPT>
41104110
getPoints( const Point2d_<FPT>& pt, FPT2 dist ) const
41114111
{
41124112
return impl_getPoints_B( pt, dist, detail::BaseHelper<LP>() );
@@ -4384,13 +4384,13 @@ Please check out warning described in impl_getAngle()
43844384
constexpr Point2d_<FPT> impl_getPoint( GivenCoord gc, FPT other, const detail::BaseHelper<typename typ::IsPoint>& ) const;
43854385

43864386
template<typename FPT2>
4387-
PointPair2_<FPT,FPT> impl_getPoints_A( GivenCoord, FPT, FPT2, const detail::BaseHelper<typename typ::IsLine>& ) const;
4387+
PointPair_<FPT> impl_getPoints_A( GivenCoord, FPT, FPT2, const detail::BaseHelper<typename typ::IsLine>& ) const;
43884388
template<typename FPT2>
4389-
constexpr PointPair2_<FPT,FPT> impl_getPoints_A( GivenCoord, FPT, FPT2, const detail::BaseHelper<typename typ::IsPoint>& ) const;
4389+
constexpr PointPair_<FPT> impl_getPoints_A( GivenCoord, FPT, FPT2, const detail::BaseHelper<typename typ::IsPoint>& ) const;
43904390
template<typename FPT2>
4391-
PointPair2_<FPT,FPT> impl_getPoints_B( const Point2d_<FPT>&, FPT2, const detail::BaseHelper<typename typ::IsLine>& ) const;
4391+
PointPair_<FPT> impl_getPoints_B( const Point2d_<FPT>&, FPT2, const detail::BaseHelper<typename typ::IsLine>& ) const;
43924392
template<typename FPT2>
4393-
constexpr PointPair2_<FPT,FPT> impl_getPoints_B( const Point2d_<FPT>&, FPT2, const detail::BaseHelper<typename typ::IsPoint>& ) const;
4393+
constexpr PointPair_<FPT> impl_getPoints_B( const Point2d_<FPT>&, FPT2, const detail::BaseHelper<typename typ::IsPoint>& ) const;
43944394

43954395
void impl_op_stream( std::ostream&, const Point2d_<FPT>& ) const;
43964396
void impl_op_stream( std::ostream&, const Line2d_<FPT>& ) const;
@@ -5270,7 +5270,7 @@ Requires both points inside AND no intersections
52705270
If x-coordinate are equal, then
52715271
the one with smallest y-coordinate will be returned first
52725272
*/
5273-
PointPair1_<FPT>
5273+
PointPair_<FPT>
52745274
getPts() const
52755275
{
52765276
return std::make_pair( _ptS1, _ptS2 );
@@ -5879,7 +5879,7 @@ template<
58795879
T
58805880
>::type* = nullptr
58815881
>
5882-
PointPair1_<typename T::value_type::FType>
5882+
PointPair_<typename T::value_type::FType>
58835883
getBB_Points( const T& vpts )
58845884
{
58855885
HOMOG2D_START;
@@ -8843,14 +8843,14 @@ LPBase<LP,FPT>::impl_getPoint( GivenCoord gc, FPT other, const detail::BaseHelpe
88438843
/// ILLEGAL INSTANCIATION
88448844
template<typename LP,typename FPT>
88458845
template<typename FPT2>
8846-
constexpr PointPair1_<FPT>
8846+
constexpr PointPair_<FPT>
88478847
LPBase<LP,FPT>::impl_getPoints_A( GivenCoord, FPT, FPT2, const detail::BaseHelper<typename typ::IsPoint>& ) const
88488848
{
88498849
static_assert( detail::AlwaysFalse<LP>::value, "Invalid: you cannot call getPoints() on a point" );
88508850
}
88518851
template<typename LP,typename FPT>
88528852
template<typename FPT2>
8853-
constexpr PointPair1_<FPT>
8853+
constexpr PointPair_<FPT>
88548854
LPBase<LP,FPT>::impl_getPoints_B( const Point2d_<FPT>&, FPT2, const detail::BaseHelper<typename typ::IsPoint>& ) const
88558855
{
88568856
static_assert( detail::AlwaysFalse<LP>::value, "Invalid: you cannot call getPoints() on a point" );
@@ -8859,7 +8859,7 @@ LPBase<LP,FPT>::impl_getPoints_B( const Point2d_<FPT>&, FPT2, const detail::Base
88598859
/// Returns pair of points on line at distance \c dist from point on line at coord \c coord. Implementation for lines
88608860
template<typename LP,typename FPT>
88618861
template<typename FPT2>
8862-
PointPair2_<FPT,FPT>
8862+
PointPair_<FPT>
88638863
LPBase<LP,FPT>::impl_getPoints_A( GivenCoord gc, FPT coord, FPT2 dist, const detail::BaseHelper<typename typ::IsLine>& ) const
88648864
{
88658865
const auto pt = impl_getPoint( gc, coord, detail::BaseHelper<typ::IsLine>() );
@@ -8869,7 +8869,7 @@ LPBase<LP,FPT>::impl_getPoints_A( GivenCoord gc, FPT coord, FPT2 dist, const det
88698869
/// Returns pair of points on line at distance \c dist from point on line at coord \c coord. Implementation for lines
88708870
template<typename LP,typename FPT>
88718871
template<typename FPT2>
8872-
PointPair2_<FPT,FPT>
8872+
PointPair_<FPT>
88738873
LPBase<LP,FPT>::impl_getPoints_B( const Point2d_<FPT>& pt, FPT2 dist, const detail::BaseHelper<typename typ::IsLine>& ) const
88748874
{
88758875
#ifndef HOMOG2D_NOCHECKS
@@ -10135,7 +10135,7 @@ getPointPair( const T& elem )
1013510135

1013610136
/// Needed because of variant
1013710137
template<typename FPT>
10138-
PointPair2_<FPT,FPT>
10138+
PointPair_<FPT>
1013910139
getPointPair( const Line2d_<FPT>& )
1014010140
{
1014110141
HOMOG2D_START;
@@ -10160,7 +10160,7 @@ namespace fct {
1016010160
struct PtPairFunct
1016110161
{
1016210162
template<typename T>
10163-
PointPair1_<typename T::FType>
10163+
PointPair_<typename T::FType>
1016410164
operator ()(const T& a)
1016510165
{
1016610166
return ppair::getPointPair(a);
@@ -10285,7 +10285,7 @@ getBB_CommonType( const std::vector<CommonType_<FPT>>& v_var )
1028510285

1028610286
std::vector<Point2d_<FPT>> vpts;
1028710287
vpts.reserve( v_var.size()*2 );
10288-
PointPair2_<FPT,FPT> ppair;
10288+
PointPair_<FPT> ppair;
1028910289
for( const auto& elem: v_var )
1029010290
{
1029110291
try
@@ -10594,7 +10594,7 @@ class ClosestPoints
1059410594
}
1059510595

1059610596
public:
10597-
PointPair1_<HOMOG2D_INUMTYPE>
10597+
PointPair_<HOMOG2D_INUMTYPE>
1059810598
getPoints() const
1059910599
{
1060010600
return std::make_pair(
@@ -11822,7 +11822,7 @@ Used both in the SVG and the Opencv backends
1182211822
namespace priv {
1182311823

1182411824
template<typename FPT>
11825-
std::array<PointPair1_<double>,3>
11825+
std::array<PointPair_<double>,3>
1182611826
getArrowSegments(
1182711827
const base::SegVec<typ::IsOSeg,FPT>& vec
1182811828
)
@@ -12419,6 +12419,11 @@ using OPolylineF = OPolyline_<float>;
1241912419
using OPolylineD = OPolyline_<double>;
1242012420
using OPolylineL = OPolyline_<long double>;
1242112421

12422+
using PointPairF = PointPair_<float>;
12423+
using PointPairD = PointPair_<double>;
12424+
using PointPairL = PointPair_<long double>;
12425+
using PointPair = PointPair_<double>;
12426+
1242212427
#ifdef HOMOG2D_ENABLE_VRTP
1242312428
// variant type
1242412429
using CommonType = CommonType_<HOMOG2D_INUMTYPE>;

misc/demo_opencv.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1729,8 +1729,6 @@ void demo_orthSeg( int demidx )
17291729
}
17301730

17311731
//------------------------------------------------------------------
1732-
using PointPair = PointPair2_<double,double>;
1733-
17341732
/// Parameters for points Bounding Box demo
17351733
struct Param_BB : Data
17361734
{

misc/test_files/demo_svg_import.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ or
2525
`$ BUILD/demo_svg_import misc/test_files/France_Normandie.svg`
2626
2727
This will generate a svg file in current folder that is a copy of what was read in the file.
28-
29-
\todo 20240326: once we have a function able to get the min/max points of a container holding
30-
primitives (see \c getBB()), automatically adjust the size of output image.
3128
*/
3229

3330
//#define HOMOG2D_DEBUGMODE
@@ -77,7 +74,7 @@ int main( int argc, const char** argv )
7774
img::Image<img::SvgImage> out( imSize.first, imSize.second );
7875
fct::DrawFunct<img::SvgImage> dfunc( out );
7976

80-
PointPair2_<double,double> pp_all;
77+
PointPair pp_all;
8178
size_t c = 0;
8279
for( const auto& e: data )
8380
{

misc/tryme2.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/**************************************************************************
2+
3+
This file is part of the C++ library "homog2d", dedicated to
4+
handle 2D lines and points, see https://github.com/skramm/homog2d
5+
6+
Author & Copyright 2019-2025 Sebastien Kramm
7+
8+
Contact: firstname.lastname@univ-rouen.fr
9+
10+
Licence: MPL v2
11+
12+
This Source Code Form is subject to the terms of the Mozilla Public
13+
License, v. 2.0. If a copy of the MPL was not distributed with this
14+
file, You can obtain one at https://mozilla.org/MPL/2.0/.
15+
16+
**************************************************************************/
117

218
#include "homog2d.hpp"
319
using namespace h2d;

0 commit comments

Comments
 (0)