5 template <
typename PixelOp>
19 template <
typename PixelOp>
21 thickness = newThickness;
24 template <
typename PixelOp>
26 fontSize = newFontSize;
29 template <
typename PixelOp>
34 template <
typename PixelOp>
40 const int x1 = int(
floor(p1.
x));
41 const int x2 = int(
ceil(p2.
x));
42 const float y1 = p1.
y;
43 const float y2 = p2.
y;
44 for (
int x = x1; x <= x2; ++x) {
45 int y = int(y1 + (x - x1) * (y2 - y1) / (x2 - x1));
46 drawSafe(
Pixel(x, y), colors.line);
52 const int y1 = int(
floor(p1.
y));
53 const int y2 = int(
ceil(p2.
y));
54 const float x1 = p1.
x;
55 const float x2 = p2.
x;
56 for (
int y = y1; y <= y2; ++y) {
57 int x = int(x1 + (y - y1) * (x2 - x1) / (y2 - y1));
58 drawSafe(
Pixel(x, y), colors.line);
63 template <
typename PixelOp>
66 center.
y > bitmap.size().y +
radius) {
69 const Pixel p(center);
70 const int intRadius =
min(
int(
radius), bitmap.size().x);
71 if (p.
x >= intRadius && p.
x < bitmap.size().x - intRadius - 1 && p.
y >= intRadius &&
72 p.
y < bitmap.size().y - intRadius - 1) {
74 for (
int y = -intRadius; y <= intRadius; ++y) {
75 for (
int x = -intRadius; x <= intRadius; ++x) {
76 const int rSqr =
sqr(x) +
sqr(y);
78 draw(p +
Pixel(x, y), colors.fill);
80 draw(p +
Pixel(x, y), colors.line);
85 for (
int y = -intRadius; y <= intRadius; ++y) {
86 for (
int x = -intRadius; x <= intRadius; ++x) {
87 const int rSqr =
sqr(x) +
sqr(y);
89 drawSafe(p +
Pixel(x, y), colors.fill);
91 drawSafe(p +
Pixel(x, y), colors.line);
98 template <
typename PixelOp>
103 std::sort(p.begin(), p.end(), [](
Coords p1,
Coords p2) { return p1.y < p2.y; });
112 if (p2.
y - p1.
y > 0) {
113 return float(p2.
x - p1.
x) / (p2.
y - p1.
y);
118 const float dx1 = getDx(a, b);
119 const float dx2 = getDx(a, c);
120 const float dx3 = getDx(b, c);
122 auto doLine = [
this](
float x1,
float x2,
float y) {
126 for (
int x =
int(
floor(x1)); x <= int(
ceil(x2)); ++x) {
127 drawSafe(
Pixel(x,
int(y)), colors.fill);
132 for (; s.
y <= b.
y; s.
y++, e.y++, s.
x += dx2, e.x += dx1) {
133 doLine(s.
x, e.x, s.
y);
136 for (; s.
y <= c.
y; s.
y++, e.y++, s.
x += dx2, e.x += dx3) {
137 doLine(s.
x, e.x, s.
y);
141 template <
typename PixelOp>
143 for (
int y = 0; y < subBitmap.
size().y; ++y) {
144 for (
int x = 0; x < subBitmap.
size().x; ++x) {
150 template <
typename PixelOp>
153 const std::string& s) {
154 std::wstring ws(s.begin(), s.end());
155 this->drawText(p, align, ws);
158 template <
typename PixelOp>
161 const std::wstring& s) {
173 const Pixel p(center);
180 for (
int y = p.
y - r; y <= p.
y + r; ++y) {
181 for (
int x = p.
x - r; x <= p.
x + r; ++x) {
182 const float distSqr =
sqr(x - center.
x) +
sqr(y - center.
y);
196 const Pixel p(center);
197 const float maxRadius =
radius * float(kernel.
radius());
198 const float normalization = 1.f / float(kernel.
valueImpl(0));
199 const int r = int(
std::ceil(maxRadius)) + 1;
200 for (
int y = p.
y - r; y <= p.
y + r; ++y) {
201 for (
int x = p.
x - r; x <= p.
x + r; ++x) {
202 const float distSqr =
sqr(x - center.
x) +
sqr(y - center.
y);
203 if (distSqr <=
sqr(maxRadius + 1)) {
207 color.
a() =
clamp(alpha, 0.f, 1.f);
#define SPH_ASSERT(x,...)
constexpr INLINE T clamp(const T &f, const T &f1, const T &f2)
NAMESPACE_SPH_BEGIN constexpr INLINE T min(const T &f1, const T &f2)
Minimum & Maximum value.
constexpr INLINE T sqr(const T &f) noexcept
Return a squared value.
INLINE auto floor(const T &f)
INLINE T sqrt(const T f)
Return a squared root of a value.
INLINE auto ceil(const T &f)
INLINE auto abs(const T &f)
#define NAMESPACE_SPH_END
void drawSafe(const Pixel p, const Rgba c)
virtual void drawCircle(const Coords center, const float radius) override
Draws a circle, given its center and a radius.
Wrapper of an integral value providing functions for reading and modifying individual bits.
constexpr INLINE bool has(const TEnum flag) const
Checks if the object has a given flag.
INLINE Float valueImpl(const Float qSqr) const noexcept
INLINE Float radius() const noexcept
virtual void drawCircle(const Coords center, const float radius) override
Draws a circle, given its center and a radius.
virtual void setColor(const Rgba &color, const Flags< ColorFlag > flags) override
Selects the color for one or more drawing modes.
virtual void setThickness(const float newThickness) override
Modifies the thickness of the lines.
virtual void drawTriangle(const Coords p1, const Coords p2, const Coords p3) override
Draws a triangle given three points.
virtual void drawBitmap(const Coords p, const Bitmap< Rgba > &subBitmap) override
Draws a bitmap, given the position of its left-top corner.
virtual void drawText(const Coords p, const Flags< TextAlign > align, const std::string &s) override
virtual void setFontSize(const int newFontSize) override
struct PreviewRenderContext::@28 colors
virtual void drawLine(const Coords p1, const Coords p2) override
Draws a line connecting two points.
virtual void drawCircle(const Coords center, const float radius) override
Draws a circle, given its center and a radius.
Array with fixed number of allocated elements.
void swap(Sph::Array< T, TCounter > &ar1, Sph::Array< T, TCounter > &ar2)