added ruff for code review
This commit is contained in:
@@ -41,7 +41,12 @@ def clip_halfspace(points, distance):
|
||||
|
||||
def clip_rect(points, x0, x1, y0, y1):
|
||||
for axis, bound, sign in ((0, x0, 1), (0, x1, -1), (1, y0, 1), (1, y1, -1)):
|
||||
points = clip_halfspace(points, lambda p: sign * (p[axis] - bound))
|
||||
# Bind the loop variables as defaults: the callback must clip against the
|
||||
# plane of *this* iteration, not whatever the loop left behind.
|
||||
points = clip_halfspace(
|
||||
points,
|
||||
lambda p, axis=axis, bound=bound, sign=sign: sign * (p[axis] - bound),
|
||||
)
|
||||
return points
|
||||
|
||||
|
||||
@@ -56,7 +61,12 @@ def project_triangle(clip_vertices):
|
||||
for i, v in enumerate(clip_vertices)]
|
||||
for axis in range(3):
|
||||
for sign in (-1, 1):
|
||||
points = clip_halfspace(points, lambda p: p[3] + sign * p[axis])
|
||||
# Same late-binding hazard as clip_rect: bind axis/sign per iteration so
|
||||
# the clip plane cannot be read from a later loop state.
|
||||
points = clip_halfspace(
|
||||
points,
|
||||
lambda p, axis=axis, sign=sign: p[3] + sign * p[axis],
|
||||
)
|
||||
return [((p[0] / p[3] + 1) / 2, (p[1] / p[3] + 1) / 2,
|
||||
1 / p[3], *(b / p[3] for b in p[4:]))
|
||||
for p in points if p[3] > 1e-15]
|
||||
|
||||
Reference in New Issue
Block a user