1 /** Aesalon, a tool to visualize program behaviour in real time.
2 Copyright (C) 2009-2011, Aesalon development team.
4 Aesalon is distributed under the terms of the GNU GPLv3. See
5 the included file LICENSE for more information.
7 @file src/artisan/gviewport/CoordinateMapper.cpp
10 #include "artisan/gviewport/CoordinateMapper.h"
12 #include "util/MessageSystem.h"
17 CoordinateMapper::CoordinateMapper(const Rect
&dataRect
, const Rect
&pixelRect
)
18 : m_dataRect(dataRect
), m_pixelRect(pixelRect
) {
22 CoordinateMapper::CoordinateMapper(const RenderedImage
&image
)
23 : m_dataRect(image
.dataRange()), m_pixelRect(image
.pixelSize()) {
26 Point
CoordinateMapper::dataToPixel(const Point
&dataPoint
) {
27 double xPercentage
= (dataPoint
.x() - m_dataRect
.left()) / m_dataRect
.width();
28 double yPercentage
= (dataPoint
.y() - m_dataRect
.top()) / m_dataRect
.height();
31 (xPercentage
* m_pixelRect
.width()) + m_pixelRect
.left(),
32 (yPercentage
* m_pixelRect
.height()) + m_pixelRect
.top());
35 Rect
CoordinateMapper::dataToPixel(const Rect
&dataRect
) {
36 return Rect(dataToPixel(dataRect
.topLeft()), dataToPixel(dataRect
.bottomRight()));
39 Point
CoordinateMapper::pixelToData(const Point
&pixelPoint
) {
40 double xPercentage
= (pixelPoint
.x() - m_pixelRect
.left()) / m_pixelRect
.width();
41 double yPercentage
= (pixelPoint
.y() - m_pixelRect
.top()) / m_pixelRect
.height();
44 (xPercentage
* m_dataRect
.width()) + m_dataRect
.left(),
45 (yPercentage
* m_dataRect
.height()) + m_dataRect
.top());
48 Rect
CoordinateMapper::pixelToData(const Rect
&pixelRect
) {
49 return Rect(pixelToData(pixelRect
.topLeft()), pixelToData(pixelRect
.bottomRight()));
52 Point
CoordinateMapper::pixelToDataOffset(const Point
&pixelPoint
) {
53 double xPercentage
= (pixelPoint
.x() - m_pixelRect
.left()) / m_pixelRect
.width();
54 double yPercentage
= (pixelPoint
.y() - m_pixelRect
.top()) / m_pixelRect
.height();
57 (xPercentage
* m_dataRect
.width()),
58 (yPercentage
* m_dataRect
.height()));
61 } // namespace GViewport
62 } // namespace Artisan