Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions source/MRMesh/MRImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,23 @@ namespace MR

Color Image::sampleDiscrete( const UVCoord & pos ) const
{
if ( resolution.x <= 0 || resolution.y <= 0 )
{
assert( false );
return {};
}
const float x = std::clamp( pos.x, 0.0f, 1.0f ) * ( resolution.x - 1 );
const float y = std::clamp( pos.y, 0.0f, 1.0f ) * ( resolution.y - 1 );
return operator[]( { (int)std::lround( x ), (int)std::lround( y ) } );
}

Color Image::sampleBilinear( const UVCoord & pos ) const
{
if ( resolution.x <= 0 || resolution.y <= 0 )
{
assert( false );
return {};
}
const float x = std::clamp( pos.x, 0.0f, 1.0f ) * ( resolution.x - 1 );
const float y = std::clamp( pos.y, 0.0f, 1.0f ) * ( resolution.y - 1 );

Expand Down
Loading