Skip to content

Commit

Permalink
update doc fig polyline RCP
Browse files Browse the repository at this point in the history
  • Loading branch information
skramm committed Dec 23, 2023
2 parents 85c2f62 + 78d0cae commit 636764b
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 24 deletions.
2 changes: 1 addition & 1 deletion docs/homog2d_manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -1018,7 +1018,7 @@ see [the related constructor](#build_RCP).
This function returns a `std::pair` holding two numerical values:
the distance between two consecutive points as "first", and "second" the radius of the inscribed circle.
The minimum value for `dist` is 3, will throw if less.
The minimum value for `nb` is 3, the function will throw if less.
![polyline_rcp_1](img/polyline_rcp_1.svg)
Expand Down
32 changes: 23 additions & 9 deletions docs/img/polyline_rcp_1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 15 additions & 3 deletions homog2d.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2452,6 +2452,9 @@ class FRect_: public detail::Common<FPT>
template<typename TX, typename TY>
void moveTo( TX x, TY y )
{
HOMOG2D_CHECK_IS_NUMBER( TX );
HOMOG2D_CHECK_IS_NUMBER( TY );

auto s = size();
_ptR1.set(x,y);
_ptR2.set( _ptR1.getX() + s.first, _ptR1.getY() + s.second );
Expand Down Expand Up @@ -3007,6 +3010,8 @@ Use of Sfinae so it can be selected only for arithmetic types
template<typename TX, typename TY>
void moveTo( TX x, TY y )
{
HOMOG2D_CHECK_IS_NUMBER( TX );
HOMOG2D_CHECK_IS_NUMBER( TY );
set( Point2d_<FPT>(x, y) );
}

Expand Down Expand Up @@ -4664,6 +4669,8 @@ class Segment_: public detail::Common<FPT>
template<typename TX, typename TY>
void moveTo( TX x, TY y )
{
HOMOG2D_CHECK_IS_NUMBER( TX );
HOMOG2D_CHECK_IS_NUMBER( TY );
moveTo( Point2d_<FPT>(x,y) );
}

Expand Down Expand Up @@ -5637,11 +5644,11 @@ this should work !!! (but doesn't...)
private:
template<typename FPT2>
std::pair<HOMOG2D_INUMTYPE,HOMOG2D_INUMTYPE>
impl_set_RCP( FPT2 rad, size_t n, const detail::PlHelper<type::IsClosed>& );
impl_set_RCP( FPT2 rad, size_t n, const typename detail::PlHelper<type::IsClosed>& );

template<typename FPT2>
constexpr std::pair<HOMOG2D_INUMTYPE,HOMOG2D_INUMTYPE>
impl_set_RCP( FPT2, size_t, const detail::PlHelper<type::IsOpen>& )
impl_set_RCP( FPT2, size_t, const typename detail::PlHelper<type::IsOpen>& )
{
static_assert( detail::AlwaysFalse<PLT>::value, "cannot build an regular convex polygon for a OPolyline object" );
return std::make_pair(0.,0.); // to avoid a compiler warning
Expand Down Expand Up @@ -5898,10 +5905,15 @@ at 180° of the previous one.
template<typename TX,typename TY>
void moveTo( TX x, TY y )
{
HOMOG2D_CHECK_IS_NUMBER( TX );
HOMOG2D_CHECK_IS_NUMBER( TY );
moveTo( Point2d_<FPT>(x,y) );
}

/// Move Polyline to new origin, given by \c new_org
/**
\warning The polygon origin is NOT its center but the point No 0!
*/
template<typename T1>
void moveTo( const Point2d_<T1>& new_org )
{
Expand Down Expand Up @@ -6244,7 +6256,7 @@ Two tasks:
template<typename PLT,typename FPT>
template<typename FPT2>
std::pair<HOMOG2D_INUMTYPE,HOMOG2D_INUMTYPE>
PolylineBase<PLT,FPT>::impl_set_RCP( FPT2 rad, size_t n, const detail::PlHelper<type::IsClosed>& )
PolylineBase<PLT,FPT>::impl_set_RCP( FPT2 rad, size_t n, const typename detail::PlHelper<type::IsClosed>& )
{
if( n < 3 )
HOMOG2D_THROW_ERROR_1( "unable, nb of points must be > 2" );
Expand Down
7 changes: 3 additions & 4 deletions misc/demo_opencv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1687,7 +1687,9 @@ void action_RCP( void* param )
CPolyline pol;
auto values = pol.set( data.radius, data.nbPts );
std::cout << " -Building Regular Convex Polygon with " << data.nbPts << " points\n";
pol.translate(data.trans_x,data.trans_y);

pol.moveTo( Point2d(data.trans_x+data.radius,data.trans_y) );

pol.draw( data.img );
drawText( data.img, "NbPts=" +std::to_string(data.nbPts), Point2d(20,40) );
drawText( data.img, "segment dist=" +std::to_string(values.first), Point2d(20,60) );
Expand All @@ -1710,10 +1712,7 @@ void demo_RCP( int demidx )

kbloop.addCommonAction( action_RCP );
action_RCP( &data );
// data.setMouseCB( action_ORS );

kbloop.start( data );

}

//------------------------------------------------------------------
Expand Down
60 changes: 53 additions & 7 deletions misc/figures_src/src/polyline_rcp_1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@

int main()
{
img::Image<img::SvgImage> im( 450,200 );
img::Image<img::SvgImage> im( 550,250 );

Point2d p1(100,100);
Point2d p2(280,100 );
float radius = 100;
Point2d p1(110,radius+20);
Point2d p2(360,radius+20 );
p1.draw( im );
p2.draw( im );
CPolyline pol1, pol2;
auto values1 = pol1.set(80,5);
auto values2 = pol2.set(100,7);
pol1.moveTo( p1 );
pol2.moveTo( p2 );
auto values1 = pol1.set( radius, 5 );
auto values2 = pol2.set( radius, 7 );
pol1.translate( p1.getX(), p1.getY() );
pol2.translate( p2.getX(), p2.getY() );

Circle c1( p1, values1.second );
Circle c2( p2, values2.second );

Expand All @@ -26,5 +28,49 @@ int main()
pol1.draw( im, img::DrawParams().setColor(250,0,0) );
pol2.draw( im, img::DrawParams().setColor(250,0,0) );

draw( im, pol1.getPts().front(), img::DrawParams().setPointStyle( img::PtStyle::Dot ).setColor(0,0,200) );
draw( im, pol2.getPts().front(), img::DrawParams().setPointStyle( img::PtStyle::Dot ).setColor(0,0,200) );

{
Segment s1( p1, pol1.getPts().front() );
Segment s2( p2, pol2.getPts().front() );
s1.draw( im ) ;
s2.draw( im ) ;

drawText( im, std::to_string(int(radius)), s1.getCenter() );
drawText( im, std::to_string(int(radius)), s2.getCenter() );
}
{
auto s1 = pol1.getSegs().at(0);
auto s2 = pol2.getSegs().at(0);
auto spara1 = s1.getParallelSegs(25).second;
auto spara2 = s2.getParallelSegs(25).second;
spara1.draw( im );
spara2.draw( im );

std::ostringstream oss1, oss2;
oss1 << std::fixed << std::setprecision(1) << values1.first;
oss2 << std::fixed << std::setprecision(1) << values2.first;
drawText( im, oss1.str(), spara1.getCenter() );
drawText( im, oss2.str(), spara2.getCenter() );
}
{
Segment s1( p1, pol1.getPts().at(3) );
Segment s2( p2, pol2.getPts().at(3) );

auto it1 = c1.intersects(s1);
auto it2 = c2.intersects(s2);

Segment ss1( p1, it1.get()[0] );
Segment ss2( p2, it2.get()[0] );
ss1.draw( im ) ;
ss2.draw( im ) ;

std::ostringstream oss1, oss2;
oss1 << std::fixed << std::setprecision(1) << values1.second;
oss2 << std::fixed << std::setprecision(1) << values2.second;
drawText( im, oss1.str(), ss1.getCenter() );
drawText( im, oss2.str(), ss2.getCenter() );
}
im.write( "polyline_rcp_1.svg" );
}
1 change: 1 addition & 0 deletions misc/scripts/plot_tags_linecount.plt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ set style fill solid
set style data histogram
set grid
set logscale y
set yrange [0.5:30]
set key on inside left top
set title "KLOC per release"
plot "/tmp/homog2d/tags_linecount.csv" using (column(2)/1000):xtic(1) with histogram ti "Library file", \
Expand Down

0 comments on commit 636764b

Please sign in to comment.