Example #1
0
func TestStackNew(t *testing.T) {
	stack := NewTransformStack()

	if !(*stack)[0].ApproxEqual(mgl64.Ident4()) {
		t.Errorf("Cannot construct stack correctly")
	}
}
Example #2
0
func TestStackPushPopPeek(t *testing.T) {
	stack := NewTransformStack()

	if !stack.Peek().ApproxEqual(mgl64.Ident4()) {
		t.Errorf("Peek not working")
	}

	stack.Push(mgl64.HomogRotate3DY(mgl64.DegToRad(90)))

	if !stack.Peek().ApproxEqual(mgl64.HomogRotate3DY(mgl64.DegToRad(90))) {
		t.Errorf("Peek not working")
	}

	if stack.Len() != 2 {
		t.Errorf("Peek alters stack length")
	}

	pop, err := stack.Pop()
	if err != nil || !pop.ApproxEqual(mgl64.HomogRotate3DY(mgl64.DegToRad(90))) {
		t.Errorf("Pop is unsuccessful")
	}

	if stack.Len() != 1 {
		t.Errorf("Pop does not actually shorten stack")
	}

	_, err = stack.Pop()

	if err == nil {
		t.Errorf("Popping stack with 1 element does not return error as expected")
	}
}
Example #3
0
// A shortcut for Load(mgl.Ident4())
func (ms *MatStack) LoadIdent() {
	(*ms)[len(*ms)-1] = mgl64.Ident4()
}
Example #4
0
func NewMatStack() *MatStack {
	return &MatStack{mgl64.Ident4()}
}
Example #5
0
// Returns a matrix stack where the top element is the identity.
func NewTransformStack() *TransformStack {
	ms := make(TransformStack, 1)
	ms[0] = mgl64.Ident4()

	return &ms
}