Draw a circle sector.
(
self,
center: point_like,
point: point_like,
beta: float,
fullSector: bool = True,
)
| 3234 | return self.draw_bezier(p1, k1, k2, p3) |
| 3235 | |
| 3236 | def draw_sector( |
| 3237 | self, |
| 3238 | center: point_like, |
| 3239 | point: point_like, |
| 3240 | beta: float, |
| 3241 | fullSector: bool = True, |
| 3242 | ) -> Point: |
| 3243 | """Draw a circle sector.""" |
| 3244 | center = Point(center) |
| 3245 | point = Point(point) |
| 3246 | l3 = "%g %g m\n" |
| 3247 | l4 = "%g %g %g %g %g %g c\n" |
| 3248 | l5 = "%g %g l\n" |
| 3249 | betar = math.radians(-beta) |
| 3250 | w360 = math.radians(math.copysign(360, betar)) * (-1) |
| 3251 | w90 = math.radians(math.copysign(90, betar)) |
| 3252 | w45 = w90 / 2 |
| 3253 | while abs(betar) > 2 * math.pi: |
| 3254 | betar += w360 # bring angle below 360 degrees |
| 3255 | if not (self.lastPoint == point): |
| 3256 | self.draw_cont += l3 % JM_TUPLE(point * self.ipctm) |
| 3257 | self.lastPoint = point |
| 3258 | Q = Point(0, 0) # just make sure it exists |
| 3259 | C = center |
| 3260 | P = point |
| 3261 | S = P - C # vector 'center' -> 'point' |
| 3262 | rad = abs(S) # circle radius |
| 3263 | |
| 3264 | if not rad > EPSILON: |
| 3265 | raise ValueError("radius must be positive") |
| 3266 | |
| 3267 | alfa = self.horizontal_angle(center, point) |
| 3268 | while abs(betar) > abs(w90): # draw 90 degree arcs |
| 3269 | q1 = C.x + math.cos(alfa + w90) * rad |
| 3270 | q2 = C.y + math.sin(alfa + w90) * rad |
| 3271 | Q = Point(q1, q2) # the arc's end point |
| 3272 | r1 = C.x + math.cos(alfa + w45) * rad / math.cos(w45) |
| 3273 | r2 = C.y + math.sin(alfa + w45) * rad / math.cos(w45) |
| 3274 | R = Point(r1, r2) # crossing point of tangents |
| 3275 | kappah = (1 - math.cos(w45)) * 4 / 3 / abs(R - Q) |
| 3276 | kappa = kappah * abs(P - Q) |
| 3277 | cp1 = P + (R - P) * kappa # control point 1 |
| 3278 | cp2 = Q + (R - Q) * kappa # control point 2 |
| 3279 | self.draw_cont += l4 % JM_TUPLE( |
| 3280 | list(cp1 * self.ipctm) + list(cp2 * self.ipctm) + list(Q * self.ipctm) |
| 3281 | ) |
| 3282 | |
| 3283 | betar -= w90 # reduce parm angle by 90 deg |
| 3284 | alfa += w90 # advance start angle by 90 deg |
| 3285 | P = Q # advance to arc end point |
| 3286 | # draw (remaining) arc |
| 3287 | if abs(betar) > 1e-3: # significant degrees left? |
| 3288 | beta2 = betar / 2 |
| 3289 | q1 = C.x + math.cos(alfa + betar) * rad |
| 3290 | q2 = C.y + math.sin(alfa + betar) * rad |
| 3291 | Q = Point(q1, q2) # the arc's end point |
| 3292 | r1 = C.x + math.cos(alfa + beta2) * rad / math.cos(beta2) |
| 3293 | r2 = C.y + math.sin(alfa + beta2) * rad / math.cos(beta2) |
no test coverage detected