From 6131b751e568c7a48500428b639457d2cd426eb3 Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Mon, 15 Sep 2025 06:54:20 +0200 Subject: [PATCH] feat(shape): add RotateCW() and RotateCCW() --- game/shape.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/game/shape.go b/game/shape.go index cf0df6f..7543e39 100644 --- a/game/shape.go +++ b/game/shape.go @@ -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, + } +}