@@ -61,16 +61,16 @@ struct GetLineDist : public DistanceFunc {
61
61
GetLineDist (float ax, float ay, float bx, float by, float size)
62
62
: ax(ax), ay(ay), bx(bx), by(by), size(size) {}
63
63
64
- float Get (float px, float py) const {
64
+ float Get (float px, float py) const override {
65
65
float num = (px - ax) * (bx - ax) + (py - ay) * (by - ay);
66
66
float den = (bx - ax) * (bx - ax) + (by - ay) * (by - ay);
67
67
float rdn = 1 / den, r = num * rdn;
68
68
float s = ((ay - py) * (bx - ax) - (ax - px) * (by - ay)) * rdn;
69
- if (r >= 0 && r <= 1 ) return ( float ) fabs (s * sqrt (den)) - size;
69
+ if (r >= 0 && r <= 1 ) return fabs (s * sqrt (den)) - size;
70
70
71
71
float d1sq = (px - ax) * (px - ax) + (py - ay) * (py - ay);
72
72
float d2sq = (px - bx) * (px - bx) + (py - by) * (py - by);
73
- return ( float ) sqrt (d1sq < d2sq ? d1sq : d2sq) - size;
73
+ return sqrt (d1sq < d2sq ? d1sq : d2sq) - size;
74
74
}
75
75
};
76
76
@@ -80,9 +80,9 @@ struct GetCircleDist : public DistanceFunc {
80
80
81
81
GetCircleDist (float x, float y, float r) : x(x), y(y), r(r) {}
82
82
83
- float Get (float px, float py) const {
83
+ float Get (float px, float py) const override {
84
84
float dx = px - x, dy = py - y;
85
- return ( float ) sqrt (dx * dx + dy * dy) - r;
85
+ return sqrt (dx * dx + dy * dy) - r;
86
86
}
87
87
};
88
88
@@ -93,7 +93,7 @@ struct GetRoundRectDist : public DistanceFunc {
93
93
GetRoundRectDist (float x1, float y1, float x2, float y2, float r)
94
94
: x1(x1), y1(y1), x2(x2), y2(y2), r(r) {}
95
95
96
- float Get (float px, float py) const {
96
+ float Get (float px, float py) const override {
97
97
float x = min (max (px, x1 + r), x2 - r);
98
98
float y = min (max (py, y1 + r), y2 - r);
99
99
if (x == px && y == py) {
@@ -102,7 +102,7 @@ struct GetRoundRectDist : public DistanceFunc {
102
102
return -min (dx, dy);
103
103
} else {
104
104
float dx = px - x, dy = py - y;
105
- return ( float ) sqrt (dx * dx + dy * dy) - r;
105
+ return sqrt (dx * dx + dy * dy) - r;
106
106
}
107
107
}
108
108
};
@@ -124,7 +124,7 @@ struct GetPolyDist : public DistanceFunc {
124
124
return (numIntersects & 1 );
125
125
}
126
126
127
- float Get (float px, float py) const {
127
+ float Get (float px, float py) const override {
128
128
float d = 1e10 ;
129
129
for (int i = 0 , j = count - 1 ; i < count; j = i, ++i) {
130
130
GetLineDist ld (x[i], y[i], x[j], y[j], 0 );
@@ -163,28 +163,28 @@ void Canvas::Data::draw(float* buf, int w, int h, const areaf& area,
163
163
if (blendMode == Canvas::BM_ALPHA) blendfunc = BlendAlpha;
164
164
if (blendMode == Canvas::BM_ADD) blendfunc = BlendAdd;
165
165
166
- int x1 = max (mask.l , ( int ) (area.l - outerGlow - 1 + 0 .5f ));
167
- int y1 = max (mask.t , ( int ) (area.t - outerGlow - 1 + 0 .5f ));
168
- int x2 = min (mask.r , ( int ) (area.r + outerGlow + 1 + 0 .5f ));
169
- int y2 = min (mask.b , ( int ) (area.b + outerGlow + 1 + 0 .5f ));
166
+ int x1 = max (mask.l , static_cast < int > (area.l - outerGlow - 1 + 0 .5f ));
167
+ int y1 = max (mask.t , static_cast < int > (area.t - outerGlow - 1 + 0 .5f ));
168
+ int x2 = min (mask.r , static_cast < int > (area.r + outerGlow + 1 + 0 .5f ));
169
+ int y2 = min (mask.b , static_cast < int > (area.b + outerGlow + 1 + 0 .5f ));
170
170
171
171
float rh = 1 .f / max (1 , y2 - y1);
172
172
float rw = 1 .f / max (1 , x2 - x1);
173
173
float ig = 1 .f / (innerGlow + 1 );
174
174
float og = 1 .f / (outerGlow + 1 );
175
175
176
- float yf = ( float )y1 + 0 .5f ;
176
+ float yf = static_cast < float >(y1) + 0 .5f ;
177
177
for (int y = y1; y < y2; ++y, yf += 1 ) {
178
178
RGBA l = tl;
179
179
BlendLinear (l, bl, yf * rh);
180
180
RGBA r = tr;
181
181
BlendLinear (r, br, yf * rh);
182
182
183
- float xf = ( float )x1 + 0 .5f ;
183
+ float xf = static_cast < float >(x1) + 0 .5f ;
184
184
for (int x = x1; x < x2; ++x, xf += 1 ) {
185
185
float dist = func->Get (xf, yf);
186
186
if (dist >= outerGlow + 1 ) continue ;
187
- RGBA* dst = ( RGBA*) (buf + ((y * w + x) * 4 ));
187
+ RGBA* dst = reinterpret_cast < RGBA*> (buf + ((y * w + x) * 4 ));
188
188
RGBA src = l;
189
189
BlendLinear (src, r, xf * rw);
190
190
if (outline && dist < -0 .5f ) {
@@ -219,7 +219,7 @@ Canvas::Canvas(int w, int h, float lum)
219
219
canvas_width_(w),
220
220
canvas_height_(h),
221
221
data_(new Canvas::Data) {
222
- canvas_data_ = ( float *) malloc (w * h * 4 * sizeof (float ));
222
+ canvas_data_ = static_cast < float *>( malloc (w * h * 4 * sizeof (float ) ));
223
223
data_->mask = {0 , 0 , canvas_width_, canvas_height_};
224
224
clear (lum);
225
225
}
@@ -303,21 +303,24 @@ void Canvas::box(float x1, float y1, float x2, float y2, float radius) {
303
303
}
304
304
305
305
void Canvas::box (int x1, int y1, int x2, int y2, float radius) {
306
- box ((float )x1, (float )y1, (float )x2, (float )y2, radius);
306
+ box (static_cast <float >(x1), static_cast <float >(y1), static_cast <float >(x2),
307
+ static_cast <float >(y2), radius);
307
308
}
308
309
309
310
void Canvas::polygon (const float * x, const float * y, int vertexCount) {
310
311
if (vertexCount < 3 ) return ;
311
312
GetPolyDist func (x, y, vertexCount);
312
313
data_->draw (canvas_data_, canvas_width_, canvas_height_,
313
- {0 , 0 , (float )canvas_width_, (float )canvas_height_}, &func);
314
+ {0 , 0 , static_cast <float >(canvas_width_),
315
+ static_cast <float >(canvas_height_)},
316
+ &func);
314
317
}
315
318
316
319
Texture Canvas::createTexture (bool mipmap) const {
317
- uint8_t * dst =
318
- ( uint8_t *) malloc (canvas_width_ * canvas_height_ * 4 * sizeof (uint8_t ));
320
+ uint8_t * dst = static_cast < uint8_t *>(
321
+ malloc (canvas_width_ * canvas_height_ * 4 * sizeof (uint8_t ) ));
319
322
for (int i = 0 ; i < canvas_width_ * canvas_height_ * 4 ; ++i) {
320
- int v = ( int ) (canvas_data_[i] * 255 .f + 0 .5f );
323
+ int v = static_cast < int > (canvas_data_[i] * 255 .f + 0 .5f );
321
324
dst[i] = min (max (v, 0 ), 255 );
322
325
}
323
326
Texture result (canvas_width_, canvas_height_, dst, mipmap);
@@ -331,8 +334,8 @@ Canvas& Canvas::operator=(const Canvas& other) {
331
334
canvas_width_ = other.canvas_width_ , canvas_height_ = other.canvas_height_ ,
332
335
canvas_data_ = nullptr ;
333
336
if (other.canvas_data_ )
334
- canvas_data_ =
335
- ( float *) malloc (canvas_width_ * canvas_height_ * 4 * sizeof (float ));
337
+ canvas_data_ = static_cast < float *>(
338
+ malloc (canvas_width_ * canvas_height_ * 4 * sizeof (float ) ));
336
339
memcpy (canvas_data_, other.canvas_data_ ,
337
340
canvas_width_ * canvas_height_ * 4 * sizeof (float ));
338
341
return *this ;
0 commit comments