Skip to content

Commit

Permalink
Fix sorting by sorting regions before merging
Browse files Browse the repository at this point in the history
  • Loading branch information
vegarsti committed Aug 14, 2024
1 parent 987b1dc commit c469105
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion box/box.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ func YRegions(boxes []Box) [][]float64 {
// Remove duplicates
func mergeRegions(regions [][]float64) [][]float64 {
newRegions := make([][]float64, 0)
// sort regions
sort.Slice(regions, func(i, j int) bool {
return regions[i][0] < regions[j][0]
})
for _, r := range regions {
overlap := false
for i, n := range newRegions {
Expand Down Expand Up @@ -151,7 +155,7 @@ func max(f1, f2 float64) float64 {
return f1
}

// Given non-overlapping regions in x direction and y direction, create
// CartesianProduct of sorted non-overlapping regions in x direction and y direction
func CartesianProduct(xRegions [][]float64, yRegions [][]float64) [][]Box {
rows := make([][]Box, len(yRegions))
for i, yRegion := range yRegions {
Expand Down

0 comments on commit c469105

Please sign in to comment.