29 #ifndef Pt_Gfx_Scaling_h
30 #define Pt_Gfx_Scaling_h
32 #include <Pt/Gfx/Api.h>
33 #include <Pt/Gfx/Point.h>
34 #include <Pt/Gfx/Size.h>
35 #include <Pt/Gfx/Rect.h>
49 Scaling(
double scaleFactor = 1.0)
50 : _scaleFactor(scaleFactor)
53 double scaleFactor()
const
58 void setScaleFactor(
double scaleFactor)
60 _scaleFactor = scaleFactor;
64 double toPhysical(
double n)
const
66 return n * scaleFactor();
71 return p * scaleFactor();
76 return s * scaleFactor();
86 double toLogical(
double n)
const
88 return n / scaleFactor();
93 return p / scaleFactor();
98 return s / scaleFactor();
109 double align(
double n)
const
113 double p = toPhysical(n);
118 double alignPixel(
double n)
const
120 double p = toPhysical(n);
121 p =
lround(p + 0.5) - 0.5;
125 double alignContour(
size_t n)
const
128 if (_scaleFactor < 1.0)
129 return toLogical( static_cast<double>(n) );
131 double p = toPhysical( static_cast<double>(n) );
132 size_t s =
static_cast<size_t>(p);
133 return toLogical( static_cast<double>(s) );
139 pos.setX(
lround(pos.x()));
140 pos.setY(
lround(pos.y()));
141 return toLogical(pos);
147 size.setWidth(
lround(size.width()));
148 size.setHeight(
lround(size.height()));
149 return toLogical(size);
155 pos.setX(
lround(pos.x()));
156 pos.setY(
lround(pos.y()));
159 size.setWidth(
lround(size.width()));
160 size.setHeight(
lround(size.height()));
172 return a._scaleFactor == b._scaleFactor;
176 inline bool operator != (
const Scaling& a,
const Scaling& b)
182 inline bool operator < (
const Scaling& a,
const Scaling& b)
184 return a._scaleFactor < b._scaleFactor;
Rect with floating-point coordinates.
Definition: Rect.h:44
Pt::int32_t lround(float x)
Rounds to nearest integer value.
Definition: Math.h:289
Size with floating-point width and height.
Definition: Size.h:44
Surface scaling.
Definition: Scaling.h:43
Point with floating-point X and Y coordinates.
Definition: Point.h:44