feat(shape): add RotateCW() and RotateCCW()
This commit is contained in:
parent
ab1c774a26
commit
6131b751e5
1 changed files with 26 additions and 0 deletions
|
|
@ -56,3 +56,29 @@ func (s Shape) Coordinates() [4]core.Vec2i8 {
|
|||
s.coordinates[2],
|
||||
}
|
||||
}
|
||||
|
||||
func (s Shape) RotateCW() Shape {
|
||||
rotated := [3]core.Vec2i8{}
|
||||
|
||||
for i, block := range s.coordinates {
|
||||
block.X, block.Y = -1*block.Y, block.X
|
||||
rotated[i] = block
|
||||
}
|
||||
return Shape{
|
||||
typ: s.typ,
|
||||
coordinates: rotated,
|
||||
}
|
||||
}
|
||||
|
||||
func (s Shape) RotateCCW() Shape {
|
||||
rotated := [3]core.Vec2i8{}
|
||||
|
||||
for i, block := range s.coordinates {
|
||||
block.X, block.Y = block.Y, -1*block.X
|
||||
rotated[i] = block
|
||||
}
|
||||
return Shape{
|
||||
typ: s.typ,
|
||||
coordinates: rotated,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue