-
Notifications
You must be signed in to change notification settings - Fork 2
/
sector.go
53 lines (50 loc) · 1.28 KB
/
sector.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package storage
import (
"github.com/elojah/game_01/pkg/geometry"
"github.com/elojah/game_01/pkg/sector"
"github.com/elojah/game_01/pkg/ulid"
)
// Domain converts a storage sector into a domain sector.
func (s *Sector) Domain() sector.S {
bps := make([]sector.BondPoint, len(s.BondPoints))
for i := range s.BondPoints {
bps[i] = sector.BondPoint{
ID: ulid.ID(s.BondPoints[i].ID),
SectorID: ulid.ID(s.BondPoints[i].SectorID),
Position: geometry.Vec3{
X: s.BondPoints[i].X,
Y: s.BondPoints[i].Y,
Z: s.BondPoints[i].Z,
},
}
}
return sector.S{
ID: ulid.ID(s.ID),
Size: geometry.Vec3{
X: s.X,
Y: s.Y,
Z: s.Z,
},
BondPoints: bps,
}
}
// NewSector converts a domain sector into a storage sector.
func NewSector(sector sector.S) *Sector {
bps := make([]BondPoint, len(sector.BondPoints))
for i := range sector.BondPoints {
bps[i] = BondPoint{
ID: [16]byte(sector.BondPoints[i].ID),
SectorID: [16]byte(sector.BondPoints[i].SectorID),
X: sector.BondPoints[i].Position.X,
Y: sector.BondPoints[i].Position.Y,
Z: sector.BondPoints[i].Position.Z,
}
}
return &Sector{
ID: [16]byte(sector.ID),
X: sector.Size.X,
Y: sector.Size.Y,
Z: sector.Size.Z,
BondPoints: bps,
}
}