zntg/ui/orientation.go
Sander Schobers 19daffd110 Added UI elements.
Reversed order of operands when comparing with nil/0 .
2019-03-05 21:52:18 +01:00

77 lines
1.6 KiB
Go

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"
}