Fix major bugs in presort
This commit is contained in:
parent
1a823a54f3
commit
8f2f672137
@ -26,7 +26,7 @@ def maxrects_bssf(
|
|||||||
rejected_inds = set()
|
rejected_inds = set()
|
||||||
|
|
||||||
if presort:
|
if presort:
|
||||||
rotated_sizes = numpy.sort(rect_sizes, axis=0) # shortest side first
|
rotated_sizes = numpy.sort(rect_sizes, axis=1) # shortest side first
|
||||||
rect_order = numpy.lexsort(rotated_sizes.T)[::-1] # Descending shortest side
|
rect_order = numpy.lexsort(rotated_sizes.T)[::-1] # Descending shortest side
|
||||||
rect_sizes = rect_sizes[rect_order]
|
rect_sizes = rect_sizes[rect_order]
|
||||||
|
|
||||||
@ -80,26 +80,34 @@ def maxrects_bssf(
|
|||||||
r_top[:, 1] = loc[1] + rect_size[1]
|
r_top[:, 1] = loc[1] + rect_size[1]
|
||||||
|
|
||||||
regions = numpy.vstack((regions[~intersects], r_lft, r_bot, r_rgt, r_top))
|
regions = numpy.vstack((regions[~intersects], r_lft, r_bot, r_rgt, r_top))
|
||||||
|
|
||||||
|
if presort:
|
||||||
|
unsort_order = rect_order.argsort()
|
||||||
|
rect_locs = rect_locs[unsort_order]
|
||||||
|
rejected_inds = set(unsort_order[list(rejected_inds)])
|
||||||
|
|
||||||
return rect_locs, rejected_inds
|
return rect_locs, rejected_inds
|
||||||
|
|
||||||
|
|
||||||
def guillotine_bssf_sas(rect_sizes: numpy.ndarray,
|
def guillotine_bssf_sas(
|
||||||
regions: numpy.ndarray,
|
rects: ArrayLike,
|
||||||
|
containers: ArrayLike,
|
||||||
presort: bool = True,
|
presort: bool = True,
|
||||||
allow_rejects: bool = True,
|
allow_rejects: bool = True,
|
||||||
) -> tuple[numpy.ndarray, set[int]]:
|
) -> tuple[NDArray[numpy.float64], set[int]]:
|
||||||
"""
|
"""
|
||||||
sizes should be Nx2
|
sizes should be Nx2
|
||||||
regions should be Mx4 (xmin, ymin, xmax, ymax)
|
regions should be Mx4 (xmin, ymin, xmax, ymax)
|
||||||
#TODO: test me!
|
#TODO: test me!
|
||||||
# TODO add rectangle-merge?
|
# TODO add rectangle-merge?
|
||||||
"""
|
"""
|
||||||
rect_sizes = numpy.array(rect_sizes)
|
regions = numpy.array(containers, copy=False, dtype=float)
|
||||||
|
rect_sizes = numpy.array(rects, copy=False, dtype=float)
|
||||||
rect_locs = numpy.zeros_like(rect_sizes)
|
rect_locs = numpy.zeros_like(rect_sizes)
|
||||||
rejected_inds = set()
|
rejected_inds = set()
|
||||||
|
|
||||||
if presort:
|
if presort:
|
||||||
rotated_sizes = numpy.sort(rect_sizes, axis=0) # shortest side first
|
rotated_sizes = numpy.sort(rect_sizes, axis=1) # shortest side first
|
||||||
rect_order = numpy.lexsort(rotated_sizes.T)[::-1] # Descending shortest side
|
rect_order = numpy.lexsort(rotated_sizes.T)[::-1] # Descending shortest side
|
||||||
rect_sizes = rect_sizes[rect_order]
|
rect_sizes = rect_sizes[rect_order]
|
||||||
|
|
||||||
@ -138,6 +146,11 @@ def guillotine_bssf_sas(rect_sizes: numpy.ndarray,
|
|||||||
regions = numpy.vstack((regions[:rr], regions[rr + 1:],
|
regions = numpy.vstack((regions[:rr], regions[rr + 1:],
|
||||||
new_region0, new_region1))
|
new_region0, new_region1))
|
||||||
|
|
||||||
|
if presort:
|
||||||
|
unsort_order = rect_order.argsort()
|
||||||
|
rect_locs = rect_locs[unsort_order]
|
||||||
|
rejected_inds = set(unsort_order[list(rejected_inds)])
|
||||||
|
|
||||||
return rect_locs, rejected_inds
|
return rect_locs, rejected_inds
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user