From 4f124a2896551cd5c61c4fac47b015a8bc89297e Mon Sep 17 00:00:00 2001 From: Fabien Freling Date: Thu, 3 Jul 2014 23:48:11 +0200 Subject: [PATCH] Remove deprecated functions (draw). --- rotation.cpp | 102 ++++----------------------------------------------- 1 file changed, 7 insertions(+), 95 deletions(-) diff --git a/rotation.cpp b/rotation.cpp index a3255b1..24194df 100644 --- a/rotation.cpp +++ b/rotation.cpp @@ -421,12 +421,6 @@ double compute_ratio(Image const& img) return 1.0f / trigo_length; } -inline -bool fequal(float a, float b, float sigma) -{ - return abs(a - b) < sigma; -} - void compute_output_size(Image const& src, double const rotation, unsigned int& width, unsigned int& height) { double const ratio = compute_ratio(src); @@ -473,95 +467,6 @@ void compute_output_size(Image const& src, double const rotation, unsigned int& -// -// -// Point rotation -// - -Point rotate(Image const& src, Point const& p, double const ratio, double const rotation, Image const& rotated) -{ - double angle = convert_radian(src, p, ratio); - DPoint a_point = convert_abs_coord(angle + rotation, ratio); - return convert_img_coord(rotated, a_point); -} - - - -// -// -// Drawing -// - -void draw_line(Image& img, unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2) -{ - int x_inc = x1 <= x2 ? 1 : -1; - - unsigned int const y_min = min(y1, y2); - unsigned int const y_max = max(y1, y2); - double slope = (double) y2 - y1; - if (x1 != x2) - slope = ((double) y2 - y1) / abs((double) x2 - x1); - int y_inc = slope > 0 ? 1 : -1; - - if (x1 == x2) - { - for (unsigned int runner = y1; runner != y2; runner+= y_inc) - img.set_pixel(x1, runner, 255, 0, 0); // set line to red - return; - } - - if (y1 == y2) - { - for (unsigned int runner = x1; runner != x2; runner+= x_inc) - img.set_pixel(runner, y1, 255, 0, 0); // set line to red - return; - } - - unsigned int previous_y = y1; - for (unsigned int i = x1, steps = 0; i != x2; i += x_inc, ++steps) - { - unsigned int y = slope * steps + y1; - y = min(y, y_max); - y = max(y, y_min); - for (unsigned int runner = previous_y; runner != y; runner+= y_inc) - img.set_pixel(i, runner, 255, 0, 0); // set line to red - previous_y = y; - } -} - -void draw_line(Image& img, Point const& p1, Point const& p2) -{ - draw_line(img, p1.x, p1.y, p2.x, p2.y); -} - -void draw_outline(Image const& input, unsigned int degrees, string const& name) -{ - double const rotation = (degrees / 180.0f) * M_PI; - unsigned int w = 0; - unsigned int h = 0; - compute_output_size(input, rotation, w, h); - cout << "rotation(" << degrees << ") -> " << w << " x " << h << endl; - Image rotated(w, h); - - double const ratio = compute_ratio(input); - Point tl = rotate(input, Point(0, 0), ratio, rotation, rotated); - Point tr = rotate(input, Point(input.width - 1, 0), ratio, rotation, rotated); - Point bl = rotate(input, Point(0, input.height - 1), ratio, rotation, rotated); - Point br = rotate(input, Point(input.width - 1, input.height - 1), ratio, rotation, rotated); - cout << tl << " " << tr << " " << bl << " " << br << endl; - - draw_line(rotated, tl, tr); - draw_line(rotated, tr, br); - draw_line(rotated, br, bl); - draw_line(rotated, bl, tl); - - stringstream ss; - ss << "check_lines_" << name << "_" << degrees << ".ppm"; - rotated.save(ss.str()); -} - - - // // // Math approximation @@ -576,6 +481,13 @@ void round_if_very_small(double& d) d = 1.0; } +inline +bool fequal(float a, float b, float sigma) +{ + return abs(a - b) < sigma; +} + + // //