Skip to content

Commit a61883a

Browse files
authored
Merge pull request DGtal-team#1180 from isivigno/issue1099
check and correct implicit rounding issue 1099 + modify example file
2 parents 640bd86 + 2ea541a commit a61883a

File tree

3 files changed

+26
-15
lines changed

3 files changed

+26
-15
lines changed

ChangeLog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@
8484
when displaying a small segment. Fix a non initialized attribute with
8585
some improvements on bounding box computation with orientation check.
8686
(B. Kerautret, [#1123](https://github.com/DGtal-team/DGtal/pull/1123))
87+
- Frechet Shortcut: fix implicit rounding.
88+
(I. Sivignon, [#1180](https://github.com/DGtal-team/DGtal/pull/1180))
8789

8890
- *Image Package*
8991
- Fixing issue [#779](https://github.com/DGtal-team/DGtal/issues/779) by

examples/geometry/curves/exampleFrechetShortcut.cpp

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,19 +55,30 @@ int main( int argc, char** argv )
5555
trace.info() << " " << argv[ i ];
5656
trace.info() << endl;
5757

58-
std::string filename = examplesPath + "samples/plant-frechet.dat";
59-
ifstream instream; // input stream
60-
instream.open (filename.c_str(), ifstream::in);
61-
58+
std::string filename;
6259
double error;
63-
if(argc < 3)
60+
61+
if(argc == 1)
6462
{
65-
trace.info() << "Maximum error not specified. Use default value (3).\n";
63+
trace.info() << "Use default file and error value\n";
64+
filename = examplesPath + "samples/plant-frechet.dat";
6665
error = 3;
6766
}
6867
else
69-
error = atof(argv[1]);
70-
trace.info() << error << endl;
68+
if(argc != 3)
69+
{
70+
trace.info() << "Please enter a filename and error value.\n";
71+
return 0;
72+
}
73+
else
74+
{
75+
filename = argv[1];
76+
error = atof(argv[2]);
77+
}
78+
ifstream instream; // input stream
79+
instream.open (filename.c_str(), ifstream::in);
80+
81+
7182

7283
Curve c; //grid curve
7384
c.initFromVectorStream(instream);

src/DGtal/geometry/curves/FrechetShortcut.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -356,20 +356,18 @@ namespace DGtal
356356
*/
357357
static bool isBetween(double i, double a, double b, double n)
358358
{
359-
// if a<=b, a simple comparison enables to conclude
360359
if(a<=b)
361360
if(i>=a && i<=b)
362361
return true;
363362
else
364363
return false;
365364
else
366365
{
367-
//otherwise, translate the points such that a->0
368-
int tmp = a;
369-
a = fmod(a+n-tmp,n);
370-
b = fmod(b+n-tmp,n);
371-
i = fmod(i+n-tmp,n);
372-
return isBetween(i,a,b,n);
366+
if((i>=a && i<=n) || (i>=0 && i<=b))
367+
return true;
368+
else
369+
return false;
370+
373371
}
374372
}
375373

0 commit comments

Comments
 (0)