@@ -163,92 +163,97 @@ PathBuilder& PathBuilder::AddCircle(const Point& c, Scalar r) {
163
163
}
164
164
165
165
PathBuilder& PathBuilder::AddRoundedRect (Rect rect, Scalar radius) {
166
- return radius = = 0.0 ? AddRect (rect)
166
+ return radius < = 0.0 ? AddRect (rect)
167
167
: AddRoundedRect (rect, {radius, radius, radius, radius});
168
168
}
169
169
170
170
PathBuilder& PathBuilder::AddRoundedRect (Rect rect, RoundingRadii radii) {
171
- current_ = rect.origin + Point {radii.topLeft , 0.0 };
171
+ if (radii.AreAllZero ()) {
172
+ return AddRect (rect);
173
+ }
174
+
175
+ current_ = rect.origin + Point {radii.top_left .x , 0.0 };
172
176
173
- const Scalar magic_top_right = kArcApproximationMagic * radii. topRight ;
174
- const Scalar magic_bottom_right = kArcApproximationMagic * radii. bottomRight ;
175
- const Scalar magic_bottom_left = kArcApproximationMagic * radii. bottomLeft ;
176
- const Scalar magic_top_left = kArcApproximationMagic * radii. topLeft ;
177
+ const auto magic_top_right = radii. top_right * kArcApproximationMagic ;
178
+ const auto magic_bottom_right = radii. bottom_right * kArcApproximationMagic ;
179
+ const auto magic_bottom_left = radii. bottom_left * kArcApproximationMagic ;
180
+ const auto magic_top_left = radii. top_left * kArcApproximationMagic ;
177
181
178
182
// ----------------------------------------------------------------------------
179
- // / Top line.
180
- // /
183
+ // Top line.
184
+ //
181
185
prototype_.AddLinearComponent (
182
- {rect.origin .x + radii.topLeft , rect.origin .y },
183
- {rect.origin .x + rect.size .width - radii.topRight , rect.origin .y });
186
+ {rect.origin .x + radii.top_left . x , rect.origin .y },
187
+ {rect.origin .x + rect.size .width - radii.top_right . x , rect.origin .y });
184
188
185
189
// ----------------------------------------------------------------------------
186
- // / Top right arc.
187
- // /
190
+ // Top right arc.
191
+ //
188
192
prototype_.AddCubicComponent (
189
- {rect.origin .x + rect.size .width - radii.topRight , rect.origin .y },
190
- {rect.origin .x + rect.size .width - radii.topRight + magic_top_right,
193
+ {rect.origin .x + rect.size .width - radii.top_right . x , rect.origin .y },
194
+ {rect.origin .x + rect.size .width - radii.top_right . x + magic_top_right. x ,
191
195
rect.origin .y },
192
196
{rect.origin .x + rect.size .width ,
193
- rect.origin .y + radii.topRight - magic_top_right},
194
- {rect.origin .x + rect.size .width , rect.origin .y + radii.topRight });
197
+ rect.origin .y + radii.top_right . y - magic_top_right. y },
198
+ {rect.origin .x + rect.size .width , rect.origin .y + radii.top_right . y });
195
199
196
200
// ----------------------------------------------------------------------------
197
- // / Right line.
198
- // /
201
+ // Right line.
202
+ //
199
203
prototype_.AddLinearComponent (
200
- {rect.origin .x + rect.size .width , rect.origin .y + radii.topRight },
204
+ {rect.origin .x + rect.size .width , rect.origin .y + radii.top_right . y },
201
205
{rect.origin .x + rect.size .width ,
202
- rect.origin .y + rect.size .height - radii.bottomRight });
206
+ rect.origin .y + rect.size .height - radii.bottom_right . y });
203
207
204
208
// ----------------------------------------------------------------------------
205
- // / Bottom right arc.
206
- // /
209
+ // Bottom right arc.
210
+ //
207
211
prototype_.AddCubicComponent (
208
212
{rect.origin .x + rect.size .width ,
209
- rect.origin .y + rect.size .height - radii.bottomRight },
213
+ rect.origin .y + rect.size .height - radii.bottom_right . y },
210
214
{rect.origin .x + rect.size .width , rect.origin .y + rect.size .height -
211
- radii.bottomRight +
212
- magic_bottom_right},
213
- {rect.origin .x + rect.size .width - radii.bottomRight + magic_bottom_right,
215
+ radii.bottom_right .y +
216
+ magic_bottom_right.y },
217
+ {rect.origin .x + rect.size .width - radii.bottom_right .x +
218
+ magic_bottom_right.x ,
214
219
rect.origin .y + rect.size .height },
215
- {rect.origin .x + rect.size .width - radii.bottomRight ,
220
+ {rect.origin .x + rect.size .width - radii.bottom_right . x ,
216
221
rect.origin .y + rect.size .height });
217
222
218
223
// ----------------------------------------------------------------------------
219
- // / Bottom line.
220
- // /
224
+ // Bottom line.
225
+ //
221
226
prototype_.AddLinearComponent (
222
- {rect.origin .x + rect.size .width - radii.bottomRight ,
227
+ {rect.origin .x + rect.size .width - radii.bottom_right . x ,
223
228
rect.origin .y + rect.size .height },
224
- {rect.origin .x + radii.bottomLeft , rect.origin .y + rect.size .height });
229
+ {rect.origin .x + radii.bottom_left . x , rect.origin .y + rect.size .height });
225
230
226
231
// ----------------------------------------------------------------------------
227
- // / Bottom left arc.
228
- // /
232
+ // Bottom left arc.
233
+ //
229
234
prototype_.AddCubicComponent (
230
- {rect.origin .x + radii.bottomLeft , rect.origin .y + rect.size .height },
231
- {rect.origin .x + radii.bottomLeft - magic_bottom_left,
235
+ {rect.origin .x + radii.bottom_left . x , rect.origin .y + rect.size .height },
236
+ {rect.origin .x + radii.bottom_left . x - magic_bottom_left. x ,
232
237
rect.origin .y + rect.size .height },
233
- {rect.origin .x ,
234
- rect. origin . y + rect. size . height - radii. bottomLeft + magic_bottom_left},
235
- {rect.origin .x , rect.origin .y + rect.size .height - radii.bottomLeft });
238
+ {rect.origin .x , rect. origin . y + rect. size . height - radii. bottom_left . y +
239
+ magic_bottom_left. y },
240
+ {rect.origin .x , rect.origin .y + rect.size .height - radii.bottom_left . y });
236
241
237
242
// ----------------------------------------------------------------------------
238
- // / Left line.
239
- // /
243
+ // Left line.
244
+ //
240
245
prototype_.AddLinearComponent (
241
- {rect.origin .x , rect.origin .y + rect.size .height - radii.bottomLeft },
242
- {rect.origin .x , rect.origin .y + radii.topLeft });
246
+ {rect.origin .x , rect.origin .y + rect.size .height - radii.bottom_left . y },
247
+ {rect.origin .x , rect.origin .y + radii.top_left . y });
243
248
244
249
// ----------------------------------------------------------------------------
245
- // / Top left arc.
246
- // /
250
+ // Top left arc.
251
+ //
247
252
prototype_.AddCubicComponent (
248
- {rect.origin .x , rect.origin .y + radii.topLeft },
249
- {rect.origin .x , rect.origin .y + radii.topLeft - magic_top_left},
250
- {rect.origin .x + radii.topLeft - magic_top_left, rect.origin .y },
251
- {rect.origin .x + radii.topLeft , rect.origin .y });
253
+ {rect.origin .x , rect.origin .y + radii.top_left . y },
254
+ {rect.origin .x , rect.origin .y + radii.top_left . y - magic_top_left. y },
255
+ {rect.origin .x + radii.top_left . x - magic_top_left. x , rect.origin .y },
256
+ {rect.origin .x + radii.top_left . x , rect.origin .y });
252
257
253
258
return *this ;
254
259
}
@@ -260,35 +265,35 @@ PathBuilder& PathBuilder::AddOval(const Rect& container) {
260
265
const Point m = {kArcApproximationMagic * r.x , kArcApproximationMagic * r.y };
261
266
262
267
// ----------------------------------------------------------------------------
263
- // / Top right arc.
264
- // /
268
+ // Top right arc.
269
+ //
265
270
prototype_.AddCubicComponent ({c.x , c.y - r.y }, // p1
266
271
{c.x + m.x , c.y - r.y }, // cp1
267
272
{c.x + r.x , c.y - m.y }, // cp2
268
273
{c.x + r.x , c.y } // p2
269
274
);
270
275
271
276
// ----------------------------------------------------------------------------
272
- // / Bottom right arc.
273
- // /
277
+ // Bottom right arc.
278
+ //
274
279
prototype_.AddCubicComponent ({c.x + r.x , c.y }, // p1
275
280
{c.x + r.x , c.y + m.y }, // cp1
276
281
{c.x + m.x , c.y + r.y }, // cp2
277
282
{c.x , c.y + r.y } // p2
278
283
);
279
284
280
285
// ----------------------------------------------------------------------------
281
- // / Bottom left arc.
282
- // /
286
+ // Bottom left arc.
287
+ //
283
288
prototype_.AddCubicComponent ({c.x , c.y + r.y }, // p1
284
289
{c.x - m.x , c.y + r.y }, // cp1
285
290
{c.x - r.x , c.y + m.y }, // cp2
286
291
{c.x - r.x , c.y } // p2
287
292
);
288
293
289
294
// ----------------------------------------------------------------------------
290
- // / Top left arc.
291
- // /
295
+ // Top left arc.
296
+ //
292
297
prototype_.AddCubicComponent ({c.x - r.x , c.y }, // p1
293
298
{c.x - r.x , c.y - m.y }, // cp1
294
299
{c.x - m.x , c.y - r.y }, // cp2
0 commit comments