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

	if !(*stack)[0].ApproxEqual(mgl64.Ident4()) {
		t.Errorf("Cannot construct stack correctly")
	}
}
示例#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")
	}
}
示例#3
0
文件: matstack.go 项目: rexposadas/gx
// A shortcut for Load(mgl.Ident4())
func (ms *MatStack) LoadIdent() {
	(*ms)[len(*ms)-1] = mgl64.Ident4()
}
示例#4
0
文件: matstack.go 项目: rexposadas/gx
func NewMatStack() *MatStack {
	return &MatStack{mgl64.Ident4()}
}
示例#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
}