def finalize_islands(self, is_landscape=False, title_height=0):
for island in self.islands:
if title_height:
island.title = "[{}] {}".format(island.abbreviation, island.label)
points = list(vertex.co for vertex in island.verts) + island.fake_verts
angle = M.geometry.box_fit_2d(points)
rot = M.Matrix.Rotation(angle, 2)
# ensure that the island matches page orientation (portrait/landscape)
dimensions = M.Vector(max(r * v for v in points) - min(r * v for v in points) for r in rot)
if dimensions.x > dimensions.y != is_landscape:
rot = M.Matrix.Rotation(angle + pi / 2, 2)
for point in points:
# note: we need an in-place operation, and Vector.rotate() seems to work for 3d vectors only
point[:] = rot * point
for marker in island.markers:
marker.rot = rot * marker.rot
bottom_left = M.Vector((min(v.x for v in points), min(v.y for v in points) - title_height))
for point in points:
point -= bottom_left
island.bounding_box = M.Vector((max(v.x for v in points), max(v.y for v in points)))
评论列表
文章目录