@@ -163,92 +163,97 @@ PathBuilder& PathBuilder::AddCircle(const Point& c, Scalar r) {
163163}
164164
165165PathBuilder& PathBuilder::AddRoundedRect (Rect rect, Scalar radius) {
166- return radius = = 0.0 ? AddRect (rect)
166+ return radius < = 0.0 ? AddRect (rect)
167167 : AddRoundedRect (rect, {radius, radius, radius, radius});
168168}
169169
170170PathBuilder& 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 };
172176
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 ;
177181
178182 // ----------------------------------------------------------------------------
179- // / Top line.
180- // /
183+ // Top line.
184+ //
181185 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 });
184188
185189 // ----------------------------------------------------------------------------
186- // / Top right arc.
187- // /
190+ // Top right arc.
191+ //
188192 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 ,
191195 rect.origin .y },
192196 {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 });
195199
196200 // ----------------------------------------------------------------------------
197- // / Right line.
198- // /
201+ // Right line.
202+ //
199203 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 },
201205 {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 });
203207
204208 // ----------------------------------------------------------------------------
205- // / Bottom right arc.
206- // /
209+ // Bottom right arc.
210+ //
207211 prototype_.AddCubicComponent (
208212 {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 },
210214 {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 ,
214219 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 ,
216221 rect.origin .y + rect.size .height });
217222
218223 // ----------------------------------------------------------------------------
219- // / Bottom line.
220- // /
224+ // Bottom line.
225+ //
221226 prototype_.AddLinearComponent (
222- {rect.origin .x + rect.size .width - radii.bottomRight ,
227+ {rect.origin .x + rect.size .width - radii.bottom_right . x ,
223228 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 });
225230
226231 // ----------------------------------------------------------------------------
227- // / Bottom left arc.
228- // /
232+ // Bottom left arc.
233+ //
229234 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 ,
232237 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 });
236241
237242 // ----------------------------------------------------------------------------
238- // / Left line.
239- // /
243+ // Left line.
244+ //
240245 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 });
243248
244249 // ----------------------------------------------------------------------------
245- // / Top left arc.
246- // /
250+ // Top left arc.
251+ //
247252 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 });
252257
253258 return *this ;
254259}
@@ -260,35 +265,35 @@ PathBuilder& PathBuilder::AddOval(const Rect& container) {
260265 const Point m = {kArcApproximationMagic * r.x , kArcApproximationMagic * r.y };
261266
262267 // ----------------------------------------------------------------------------
263- // / Top right arc.
264- // /
268+ // Top right arc.
269+ //
265270 prototype_.AddCubicComponent ({c.x , c.y - r.y }, // p1
266271 {c.x + m.x , c.y - r.y }, // cp1
267272 {c.x + r.x , c.y - m.y }, // cp2
268273 {c.x + r.x , c.y } // p2
269274 );
270275
271276 // ----------------------------------------------------------------------------
272- // / Bottom right arc.
273- // /
277+ // Bottom right arc.
278+ //
274279 prototype_.AddCubicComponent ({c.x + r.x , c.y }, // p1
275280 {c.x + r.x , c.y + m.y }, // cp1
276281 {c.x + m.x , c.y + r.y }, // cp2
277282 {c.x , c.y + r.y } // p2
278283 );
279284
280285 // ----------------------------------------------------------------------------
281- // / Bottom left arc.
282- // /
286+ // Bottom left arc.
287+ //
283288 prototype_.AddCubicComponent ({c.x , c.y + r.y }, // p1
284289 {c.x - m.x , c.y + r.y }, // cp1
285290 {c.x - r.x , c.y + m.y }, // cp2
286291 {c.x - r.x , c.y } // p2
287292 );
288293
289294 // ----------------------------------------------------------------------------
290- // / Top left arc.
291- // /
295+ // Top left arc.
296+ //
292297 prototype_.AddCubicComponent ({c.x - r.x , c.y }, // p1
293298 {c.x - r.x , c.y - m.y }, // cp1
294299 {c.x - m.x , c.y - r.y }, // cp2
0 commit comments