BlinkenArea - GitList
Repositories
Blog
Wiki
libetherpix
Code
Commits
Branches
Tags
Search
Tree:
5bca604
Branches
Tags
master
libetherpix
simulator
transform.cpp
implement drawing pixels
Stefan Schuermans
commited
5bca604
at 2017-06-10 23:09:20
transform.cpp
Blame
History
Raw
/* * EtherPix simulator * * Copyright 2017 Stefan Schuermans <stefan schuermans info> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, version 3 of the License. * * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "bbox.h" #include "transform.h" /** * @brief constructor * @param[in] bb boundig box of input coordinates * @param[in] width width of output coordinate speace (left to right) * @param[in] height height of output coordinate space (top to bottom) */ Transform::Transform(BBox const &bb, double width, double height): m_init(false), m_zoom(1.0), m_shift_x(0.0), m_shift_y(0.0) { double bb_x_min, bb_x_max, bb_y_min, bb_y_max; if (! bb.get(bb_x_min, bb_x_max, bb_y_min, bb_y_max)) return; double delta_x = bb_x_max - bb_x_min; double delta_y = bb_y_max - bb_y_min; if (delta_x <= 0.0 || delta_y <= 0.0) return; // compute zoom factor (keep aspect ration, fit into window) double zoom_x = (double)width / delta_x; double zoom_y = (double)height / delta_y; m_zoom = zoom_x < zoom_y ? zoom_x : zoom_y; // compute shift (center of pixels should be center of window) m_shift_x = 0.5 * (double)width - 0.5 * (bb_x_min + bb_x_max) * m_zoom; m_shift_y = 0.5 * (double)height - 0.5 * (bb_y_min + bb_y_max) * -m_zoom; // initialized m_init = true; }; /** * @brief apply transformation * @param[in] in_x input x coordinate * @param[in] in_y input y coordinate * @param[out] out_x output x coordinate * @param[out] out_y output y coordinate */ void Transform::apply(double in_x, double in_y, double &out_x, double &out_y) const { out_x = in_x * m_zoom + m_shift_x; out_y = in_y * -m_zoom + m_shift_y; } /** * @brief apply zoom * @param[in] in_r input radius * @param[out] out_r output radius */ void Transform::applyZoom(double in_r, double &out_r) const { out_r = in_r * m_zoom; }