package ui

import "opslag.de/schobers/geom"

type Orientation int

const (
	OrientationVertical Orientation = iota
	OrientationHorizontal
)

func (o Orientation) FlipPt(p geom.PointF32) geom.PointF32 {
	if o == OrientationHorizontal {
		return geom.PtF32(p.Y, p.X)
	}
	return p
}

func (o Orientation) FlipRect(r geom.RectangleF32) geom.RectangleF32 {
	if o == OrientationHorizontal {
		return geom.RectF32(r.Min.Y, r.Min.X, r.Max.Y, r.Max.X)
	}
	return r
}

func (o Orientation) LengthParallel(pt geom.PointF32) float32 {
	if o == OrientationVertical {
		return pt.Y
	}
	return pt.X
}

func (o Orientation) LengthPerpendicular(pt geom.PointF32) float32 {
	if o == OrientationVertical {
		return pt.X
	}
	return pt.Y
}

func (o Orientation) Pt(parallel, perpendicular float32) geom.PointF32 {
	if o == OrientationVertical {
		return geom.PtF32(perpendicular, parallel)
	}
	return geom.PtF32(parallel, perpendicular)
}

func (o Orientation) Rect(min geom.PointF32, parallel, perpendicular float32) geom.RectangleF32 {
	if o == OrientationVertical {
		return geom.RectF32(min.X, min.Y, min.X+perpendicular, min.Y+parallel)
	}
	return geom.RectF32(min.X, min.Y, min.X+parallel, min.Y+perpendicular)
}

func (o Orientation) SizeParallel(r geom.RectangleF32) float32 {
	if o == OrientationVertical {
		return r.Dy()
	}
	return r.Dx()
}

func (o Orientation) SizePerpendicular(r geom.RectangleF32) float32 {
	if o == OrientationVertical {
		return r.Dx()
	}
	return r.Dy()
}

func (o Orientation) String() string {
	switch o {
	case OrientationVertical:
		return "vertical"
	case OrientationHorizontal:
		return "horizontal"
	}
	return "undefined"
}