package itype

type Direction int

const (
	XPlus  Direction = iota // X+
	XMinus                  // X-
	YPlus                   // Y+
	YMinus                  // Y-
	ZPlus                   // Z+
	ZMinus                  // Z-
)

var DirectionVeci = [6]Vec3i{
	XPlus:  {1, 0, 0},
	XMinus: {-1, 0, 0},
	YPlus:  {0, 1, 0},
	YMinus: {0, -1, 0},
	ZPlus:  {0, 0, 1},
	ZMinus: {0, 0, -1},
}
var DirectionVecf = [6]Vec3f{
	XPlus:  {1, 0, 0},
	XMinus: {-1, 0, 0},
	YPlus:  {0, 1, 0},
	YMinus: {0, -1, 0},
	ZPlus:  {0, 0, 1},
	ZMinus: {0, 0, -1},
}
var DirectionVecd = [6]Vec3d{
	XPlus:  {1, 0, 0},
	XMinus: {-1, 0, 0},
	YPlus:  {0, 1, 0},
	YMinus: {0, -1, 0},
	ZPlus:  {0, 0, 1},
	ZMinus: {0, 0, -1},
}
var DirectionName = [6]string{
	"X+",
	"X-",
	"Y+",
	"Y-",
	"Z+",
	"Z-",
}

func (d Direction) Opposite() Direction {
	switch d {
	case XPlus:
		return XMinus
	case XMinus:
		return XPlus
	case YPlus:
		return YMinus
	case YMinus:
		return YPlus
	case ZPlus:
		return ZMinus
	case ZMinus:
		return ZPlus
	}
	return 0
}

func (d Direction) String() string {
	return DirectionName[d]
}

// DirectionIs returns X/Y/Z for 0/1/2, and +/- for #pos/neg.
func DirectionIs(index int, positive bool) Direction {
	switch index {
	case 0:
		if positive {
			return XPlus
		} else {
			return XMinus
		}
	case 1:
		if positive {
			return YPlus
		} else {
			return YMinus
		}
	case 2:
		if positive {
			return ZPlus
		} else {
			return ZMinus
		}
	}
	return 0
}
