Add TPoint operators +=, -=, *=, /=

This commit is contained in:
Fabien Freling 2014-07-24 00:40:27 +02:00
parent e7802e30fd
commit e804d9b5ca
2 changed files with 31 additions and 6 deletions

28
image.h
View file

@ -29,6 +29,34 @@ struct TPoint {
: x(a) : x(a)
, y(b) , y(b)
{} {}
TPoint& operator+=(TPoint const& rhs)
{
x += rhs.x;
y += rhs.y;
return *this;
}
TPoint& operator-=(TPoint const& rhs)
{
x -= rhs.x;
y -= rhs.y;
return *this;
}
TPoint& operator*=(TPoint const& rhs)
{
x *= rhs.x;
y *= rhs.y;
return *this;
}
TPoint& operator/=(TPoint const& rhs)
{
x /= rhs.x;
y /= rhs.y;
return *this;
}
}; };
typedef TPoint<int> Point; typedef TPoint<int> Point;

View file

@ -234,10 +234,8 @@ Image* rotate(Image const& src, double angle)
DPoint const src_origin = get_mapped_point(*rotated, Point(0, 0), -rotation); DPoint const src_origin = get_mapped_point(*rotated, Point(0, 0), -rotation);
DPoint src_delta_x = get_mapped_point(*rotated, Point(src.width - 1, 0), -rotation); DPoint src_delta_x = get_mapped_point(*rotated, Point(src.width - 1, 0), -rotation);
DPoint src_delta_y = get_mapped_point(*rotated, Point(0, src.height - 1), -rotation); DPoint src_delta_y = get_mapped_point(*rotated, Point(0, src.height - 1), -rotation);
src_delta_x.x = src_delta_x.x - src_origin.x; src_delta_x -= src_origin;
src_delta_x.y = src_delta_x.y - src_origin.y; src_delta_y -= src_origin;
src_delta_y.x = src_delta_y.x - src_origin.x;
src_delta_y.y = src_delta_y.y - src_origin.y;
// Quantized delta // Quantized delta
unsigned int const q_pow = 4; unsigned int const q_pow = 4;
@ -273,8 +271,7 @@ Image* rotate(Image const& src, double angle)
q_pow, q); q_pow, q);
} }
src_rotated_point.x += qdx.x; src_rotated_point += qdx;
src_rotated_point.y += qdx.y;
buffer_index += rotated->pixel_size; buffer_index += rotated->pixel_size;
} }