// // This source code is property of the Computer Graphics and Visualization // chair of the TU Dresden. Do not distribute in modified or unmodified form! // Copyright (C) 2016 CGV TU Dresden - All Rights Reserved // #include "dda_line_tool.h" #include "util.h" #include #include // Initialize the tool and store a reference of a canvas_buffer dda_line_tool::dda_line_tool(canvas_buffer &canvas) : tool_base(canvas) { shape = TS_LINE; } // Draw a line from (x0, y0) to (x1, y1) void dda_line_tool::draw(int x0, int y0, int x1, int y1) { Transformation transformation = transformation_to_standard_case(x0, y0, x1, y1); transform_mut(transformation, x0, y0); transform_mut(transformation, x1, y1); float m = slope(x0, y0, x1, y1); float y = y0; for (int x = x0; x <= x1; x++) { int tx, ty; std::tie(tx, ty) = transform_inv(transformation, x, round(y)); canvas.set_pixel(tx, ty); y += m; } } // Put debug output into the stream "stream" to be displayed in the // main window void dda_line_tool::set_text(std::stringstream &stream) { stream << "Tool: DDA-Line (click and drag mouse to draw)"; }