Skip to content

Commit

Permalink
Merge pull request #944 from troussil/DSLGetPointBug
Browse files Browse the repository at this point in the history
bug fixed in method getPoint of ArithmeticalDSL
  • Loading branch information
dcoeurjo committed Feb 10, 2015
2 parents 53cac2c + 0a5a8a3 commit b4f8b7b
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 11 deletions.
3 changes: 3 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@
(Tristan Roussillon, [#939](https:/DGtal-team/DGtal/pull/939))
- Fixing DSS based length estimator on open curves. (David
Coeurjolly, [#941](https:/DGtal-team/DGtal/pull/941))
- Fix bug of method ArithmeticalDSL::getPoint with negative values
of positions as input arguments.
(Tristan Roussillon, [#944](https:/DGtal-team/DGtal/pull/944))
- Fix Bezout Vector computation (Isabelle Sivignon, [#948](https:/DGtal-team/DGtal/pull/948))

# DGtal 0.8
Expand Down
2 changes: 2 additions & 0 deletions src/DGtal/geometry/curves/ArithmeticalDSL.h
Original file line number Diff line number Diff line change
Expand Up @@ -480,13 +480,15 @@ namespace DGtal
/**
* Returns the unique point of the DSL located at position zero
* in O(1).
* @pre the arithmetical thickness is not equal to zero
* @return the point of the DSL located at position zero
*/
Point getPoint() const;

/**
* Returns the unique point of the DSL located at position @a aPosition
* in O(1).
* @pre the arithmetical thickness is not equal to zero
* @param aPosition position of the returned point
* @return the point of the DSL located at position @a aPosition
*/
Expand Down
26 changes: 16 additions & 10 deletions src/DGtal/geometry/curves/ArithmeticalDSL.ih
Original file line number Diff line number Diff line change
Expand Up @@ -312,11 +312,14 @@ inline
typename DGtal::ArithmeticalDSL<TCoordinate, TInteger, adjacency>::Point
DGtal::ArithmeticalDSL<TCoordinate, TInteger, adjacency>::getPoint() const
{
ASSERT( omega() != NumberTraits<Integer>::ZERO );

Integer shiftRemainder = omega();
Integer q0 = myLowerBound / shiftRemainder;
if (myLowerBound > (q0 * shiftRemainder))
q0++;
Point origin = toCoordinate(q0) * myShift;
Integer q = ( myLowerBound / shiftRemainder );
if ( (myLowerBound >= NumberTraits<Integer>::ZERO)
&&(myLowerBound != (q * shiftRemainder)) )
q++;
Point origin = toCoordinate(q) * myShift;

ASSERT( position(origin) == NumberTraits<Position>::ZERO );
ASSERT( isInDSL(origin) );
Expand All @@ -330,13 +333,16 @@ inline
typename DGtal::ArithmeticalDSL<TCoordinate, TInteger, adjacency>::Point
DGtal::ArithmeticalDSL<TCoordinate, TInteger, adjacency>::getPoint(const Position& aPosition) const
{
//point of position 0 lying in the DSL
Point origin = getPoint();
ASSERT( omega() != NumberTraits<Integer>::ZERO );

//point of position aPosition
Integer q = ( (myLowerBound - (remainder(origin) + static_cast<Integer>(aPosition) * remainder( mySteps.first )))
/ omega() );
Point res = origin + ( aPosition * mySteps.first + toCoordinate(q) * myShift );
Integer shiftRemainder = omega();
Point startingPoint = static_cast<Coordinate>(aPosition) * mySteps.first;
Integer bound = (myLowerBound-remainder(startingPoint));
Integer q = ( bound / shiftRemainder );
if ( (bound >= NumberTraits<Integer>::ZERO)
&&(bound != (q * shiftRemainder)) )
q++;
Point res = startingPoint + (toCoordinate(q) * myShift);

ASSERT( position(res) == aPosition );
ASSERT( isInDSL(res) );
Expand Down
1 change: 1 addition & 0 deletions src/DGtal/geometry/doc/moduleArithDSSReco.dox
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ We list below the main methods of ArithmeticalDSL:
- ArithmeticalDSL::remainder()
- ArithmeticalDSL::isInDSL() (called in ArithmeticalDSL::operator())
- ArithmeticalDSL::position()
- ArithmeticalDSL::getPoint()
- ArithmeticalDSL::before()
- ArithmeticalDSL::beforeOrEqual()

Expand Down
18 changes: 17 additions & 1 deletion tests/geometry/curves/testArithmeticalDSL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,21 @@ bool mainTest()
nb++;
trace.info() << "(" << nbok << "/" << nb << ") "
<< std::endl;

if ( (dsl7.getPoint() == Point(0,0))
&&(DSL(5,8,dsl7.omega()-1).getPoint() == Point(0,0)+dsl.shift())
&&(DSL(5,8,dsl7.omega()).getPoint() == Point(0,0)+dsl.shift())
&&(DSL(5,8,dsl7.omega()+1).getPoint() == Point(0,0)+2*dsl.shift())
&&(DSL(5,8,-dsl7.omega()+1).getPoint() == Point(0,0))
&&(DSL(5,8,-dsl7.omega()).getPoint() == Point(0,0)-dsl.shift())
&&(DSL(5,8,-dsl7.omega()-1).getPoint() == Point(0,0)-dsl.shift())
)
nbok++;
nb++;

trace.info() << "(" << nbok << "/" << nb << ") "
<< std::endl;


trace.endBlock();

Expand All @@ -201,7 +216,8 @@ bool rangeTest(const DSL& dsl)
trace.beginBlock ( "Range/Iterator services..." );
trace.info() << dsl << std::endl;

Point first = dsl.getPoint();
Point origin = dsl.getPoint();
Point first = Point(origin[0]-dsl.b(), origin[1]-dsl.a());
Point last = Point(first[0]+dsl.b(), first[1]+dsl.a());
trace.info() << "from " << first << " to " << last << std::endl;

Expand Down

0 comments on commit b4f8b7b

Please sign in to comment.