Skip to content

Commit 50bcff1

Browse files
committed
Adding translate() convenience methods to Path2d and Shape2d
1 parent d543c38 commit 50bcff1

File tree

4 files changed

+17
-1
lines changed

4 files changed

+17
-1
lines changed

include/cinder/Path2d.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ class CI_API Path2d {
7979
std::vector<vec2> subdivide( float approximationScale = 1.0f ) const;
8080
//! if \a resultTangents aren't null then un-normalized tangents corresponding to \a resultPositions are calculated.
8181
void subdivide( std::vector<vec2> *resultPositions, std::vector<vec2> *resultTangents, float approximationScale = 1.0f ) const;
82-
82+
83+
//! Translates the Path2d by \a offset
84+
void translate( const vec2 &offset );
8385
//! Scales the Path2d by \a amount.x on X and \a amount.y on Y around the center \a scaleCenter
8486
void scale( const vec2 &amount, vec2 scaleCenter = vec2() );
8587
//! Transforms the Path2d by \a matrix.

include/cinder/Shape2d.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ class CI_API Shape2d {
6363
void appendContour( const Path2d &contour ) { mContours.push_back( contour ); }
6464
void removeContour( size_t i ) { mContours.erase( mContours.begin() + i ); }
6565

66+
//! Translates the Shape2d by \a offset
67+
void translate( const vec2 &offset );
6668
//! Scales the Shape2d by \a amount.x on X and \a amount.y on Y around the center \a scaleCenter
6769
void scale( const vec2 &amount, vec2 scaleCenter = vec2() );
6870

src/cinder/Path2d.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,12 @@ void Path2d::subdivide( std::vector<vec2> *resultPositions, std::vector<vec2> *r
721721
}
722722
}
723723

724+
void Path2d::translate( const vec2 &offset )
725+
{
726+
for( vector<vec2>::iterator ptIt = mPoints.begin(); ptIt != mPoints.end(); ++ptIt )
727+
*ptIt += offset;
728+
}
729+
724730
void Path2d::scale( const vec2 &amount, vec2 scaleCenter )
725731
{
726732
for( vector<vec2>::iterator ptIt = mPoints.begin(); ptIt != mPoints.end(); ++ptIt )

src/cinder/Shape2d.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ void Shape2d::append( const Shape2d &shape )
7373
appendContour( *pathIt );
7474
}
7575

76+
void Shape2d::translate( const vec2 &offset )
77+
{
78+
for( vector<Path2d>::iterator contIt = mContours.begin(); contIt != mContours.end(); ++contIt )
79+
contIt->translate( offset );
80+
}
81+
7682
void Shape2d::scale( const vec2 &amount, vec2 scaleCenter )
7783
{
7884
for( vector<Path2d>::iterator contIt = mContours.begin(); contIt != mContours.end(); ++contIt )

0 commit comments

Comments
 (0)