From 8811d7023e3297021882b0edcaa03866a7329ee7 Mon Sep 17 00:00:00 2001 From: Fabien Freling Date: Thu, 3 Jul 2014 23:54:06 +0200 Subject: [PATCH] Factorize rotated point computation --- rotation.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/rotation.cpp b/rotation.cpp index 26a3b9e..f854934 100644 --- a/rotation.cpp +++ b/rotation.cpp @@ -627,8 +627,6 @@ Image* rotate(Image const& src, double angle) src_delta_y.y = src_delta_y.y - src_origin.y; round_if_very_small(src_delta_y.x); round_if_very_small(src_delta_y.y); - // cout << "src delta x = " << src_delta_x << endl; - // cout << "src delta y = " << src_delta_y << endl; // // steps for first column in source image (y) @@ -637,10 +635,10 @@ Image* rotate(Image const& src, double angle) int line_nb_steps = max(abs(tr.x - tl.x), abs(tr.y - tl.y)); // steps for first column in rotated image (y) - DPoint rotated_step((bl.x - tl.x) / (float) origin_nb_steps, (bl.y - tl.y) / (float) origin_nb_steps); + DPoint const rotated_step((bl.x - tl.x) / (float) origin_nb_steps, (bl.y - tl.y) / (float) origin_nb_steps); // steps for line in rotated image (x) - DPoint bresenham((tr.x - tl.x) / (float) line_nb_steps, (tr.y - tl.y) / (float) line_nb_steps); + DPoint const bresenham((tr.x - tl.x) / (float) line_nb_steps, (tr.y - tl.y) / (float) line_nb_steps); unsigned int const src_limit = src.width * src.height * 3; unsigned int const rot_limit = rotated->width * rotated->height * 3; @@ -649,12 +647,13 @@ Image* rotate(Image const& src, double angle) { // first column origin Point const rot_origin(tl.x + y_i * rotated_step.x, tl.y + y_i * rotated_step.y); + Point rot_point(rot_origin.x, rot_origin.y); + DPoint rot_delta(0.0, 0.0); Point previous = rot_origin; for (int x_i = 0; x_i <= (int) line_nb_steps; ++x_i) { - Point rot_point(rot_origin.x + x_i * bresenham.x, rot_origin.y + x_i * bresenham.y); Point const delta(rot_point.x - tl.x, rot_point.y - tl.y); DPoint src_rotated_point(src_tl.x + delta.x * src_delta_x.x + delta.y * src_delta_y.x, @@ -677,6 +676,12 @@ Image* rotate(Image const& src, double angle) } previous = rot_point; + + rot_delta.x += bresenham.x; + rot_point.x = rot_origin.x + (int) rot_delta.x; + + rot_delta.y += bresenham.y; + rot_point.y = rot_origin.y + (int) rot_delta.y; } }