Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
bobgroup-go-utils
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Bob Public Utils
bobgroup-go-utils
Commits
691f3295
Commit
691f3295
authored
1 year ago
by
Jano Hendriks
Browse files
Options
Downloads
Patches
Plain Diff
Add packing functions for Bob Box
parent
1139ae37
Branches
Branches containing commit
Tags
v1.125.0
Tags containing commit
Loading
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
bob_box_utils/bob_box_utils.go
+39
-0
39 additions, 0 deletions
bob_box_utils/bob_box_utils.go
with
39 additions
and
0 deletions
bob_box_utils/bob_box_utils.go
0 → 100644
+
39
−
0
View file @
691f3295
package
bob_box_utils
import
"sort"
type
ParcelDimensions
struct
{
Height
float64
`json:"height"`
Width
float64
`json:"width"`
Length
float64
`json:"length"`
}
// GetStackedParcelDimensions sorts the parcels so and stacks them
func
GetStackedParcelDimensions
(
parcels
[]
ParcelDimensions
)
ParcelDimensions
{
var
totalParcelHeight
,
maxParcelWidth
,
maxParcelLength
float64
// Stack the parcels
for
_
,
parcel
:=
range
parcels
{
parcelHeight
,
parcelWidth
,
parcelLength
:=
SortDimensionsInIncreasingOrder
(
parcel
.
Height
,
parcel
.
Width
,
parcel
.
Length
)
// To stack, sum all the heights
totalParcelHeight
+=
parcelHeight
// Get the max width
if
parcelWidth
>
maxParcelWidth
{
maxParcelWidth
=
parcelWidth
}
//Get the max length
if
parcelLength
>
maxParcelLength
{
maxParcelLength
=
parcelLength
}
}
return
ParcelDimensions
{
totalParcelHeight
,
maxParcelWidth
,
maxParcelLength
}
}
// SortDimensionsInIncreasingOrder sorts the given dimensions in increasing order
func
SortDimensionsInIncreasingOrder
(
dim1
,
dim2
,
dim3
float64
)
(
float64
,
float64
,
float64
)
{
dims
:=
[]
float64
{
dim1
,
dim2
,
dim3
}
sort
.
Float64s
(
dims
)
return
dims
[
0
],
dims
[
1
],
dims
[
2
]
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment