package engine

// Transform represents a geometric transformation
type Transform struct {
	x, y, size float64
	rotation   int // 0 = 0 rad, 1 = 0.5π rad, 2 = π rad, 3 = 1.5π rad
}

// NewTransform creates a new Transform
func NewTransform(x, y, size float64, rotation int) Transform {
	return Transform{
		x:        x,
		y:        y,
		size:     size,
		rotation: rotation,
	}
}

// TransformIconPoint transforms a point based on the translation and rotation specification
// w and h represent the width and height of the transformed rectangle for proper corner positioning
func (t Transform) TransformIconPoint(x, y, w, h float64) Point {
	right := t.x + t.size
	bottom := t.y + t.size
	rotation := t.rotation % 4

	switch rotation {
	case 1: // 90 degrees
		return Point{X: right - y - h, Y: t.y + x}
	case 2: // 180 degrees
		return Point{X: right - x - w, Y: bottom - y - h}
	case 3: // 270 degrees
		return Point{X: t.x + y, Y: bottom - x - w}
	default: // 0 degrees
		return Point{X: t.x + x, Y: t.y + y}
	}
}

// NoTransform represents an identity transformation
var NoTransform = NewTransform(0, 0, 0, 0)
