Draw a rectangle. Args: radius: if not None, the rectangle will have rounded corners. This is the radius of the curvature, given as percentage of the rectangle width or height. Valid are values 0 < v <= 0.5. For a sequence of two v
(self, rect: rect_like, *, radius=None)
| 3308 | return self.lastPoint |
| 3309 | |
| 3310 | def draw_rect(self, rect: rect_like, *, radius=None) -> Point: |
| 3311 | """Draw a rectangle. |
| 3312 | |
| 3313 | Args: |
| 3314 | radius: if not None, the rectangle will have rounded corners. |
| 3315 | This is the radius of the curvature, given as percentage of |
| 3316 | the rectangle width or height. Valid are values 0 < v <= 0.5. |
| 3317 | For a sequence of two values, the corners will have different |
| 3318 | radii. Otherwise, the percentage will be computed from the |
| 3319 | shorter side. A value of (0.5, 0.5) will draw an ellipse. |
| 3320 | """ |
| 3321 | r = Rect(rect) |
| 3322 | if radius == None: # standard rectangle |
| 3323 | self.draw_cont += "%g %g %g %g re\n" % JM_TUPLE( |
| 3324 | list(r.bl * self.ipctm) + [r.width, r.height] |
| 3325 | ) |
| 3326 | self.updateRect(r) |
| 3327 | self.lastPoint = r.tl |
| 3328 | return self.lastPoint |
| 3329 | # rounded corners requested. This requires 1 or 2 values, each |
| 3330 | # with 0 < value <= 0.5 |
| 3331 | if hasattr(radius, "__float__"): |
| 3332 | if radius <= 0 or radius > 0.5: |
| 3333 | raise ValueError(f"bad radius value {radius}.") |
| 3334 | d = min(r.width, r.height) * radius |
| 3335 | px = (d, 0) |
| 3336 | py = (0, d) |
| 3337 | elif hasattr(radius, "__len__") and len(radius) == 2: |
| 3338 | rx, ry = radius |
| 3339 | px = (rx * r.width, 0) |
| 3340 | py = (0, ry * r.height) |
| 3341 | if min(rx, ry) <= 0 or max(rx, ry) > 0.5: |
| 3342 | raise ValueError(f"bad radius value {radius}.") |
| 3343 | else: |
| 3344 | raise ValueError(f"bad radius value {radius}.") |
| 3345 | |
| 3346 | lp = self.draw_line(r.tl + py, r.bl - py) |
| 3347 | lp = self.draw_curve(lp, r.bl, r.bl + px) |
| 3348 | |
| 3349 | lp = self.draw_line(lp, r.br - px) |
| 3350 | lp = self.draw_curve(lp, r.br, r.br - py) |
| 3351 | |
| 3352 | lp = self.draw_line(lp, r.tr + py) |
| 3353 | lp = self.draw_curve(lp, r.tr, r.tr - px) |
| 3354 | |
| 3355 | lp = self.draw_line(lp, r.tl + px) |
| 3356 | self.lastPoint = self.draw_curve(lp, r.tl, r.tl + py) |
| 3357 | |
| 3358 | self.updateRect(r) |
| 3359 | return self.lastPoint |
| 3360 | |
| 3361 | def draw_quad(self, quad: quad_like) -> Point: |
| 3362 | """Draw a Quad.""" |
no test coverage detected