本文整理匯總了Golang中github.com/runningwild/linear.Vec2.Mag方法的典型用法代碼示例。如果您正苦於以下問題:Golang Vec2.Mag方法的具體用法?Golang Vec2.Mag怎麽用?Golang Vec2.Mag使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/runningwild/linear.Vec2
的用法示例。
在下文中一共展示了Vec2.Mag方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: BasicOperationsSpec
func BasicOperationsSpec(c gospec.Context) {
a := linear.Vec2{3, 4}
b := linear.Vec2{5, 6}
c.Specify("Make sure adding vectors works.", func() {
VecExpect(c, a.Add(b), Equals, linear.Vec2{8, 10})
})
c.Specify("Make sure subtracting vectors works.", func() {
VecExpect(c, a.Sub(b), Equals, linear.Vec2{-2, -2})
})
c.Specify("Make sure dotting vectors works.", func() {
c.Expect(a.Dot(b), IsWithin(1e-9), 39.0)
})
c.Specify("Make sure crossing vectors works.", func() {
VecExpect(c, a.Cross(), Equals, linear.Vec2{-4, 3})
})
c.Specify("Make sure taking the magnitude of vectors works.", func() {
c.Expect(a.Mag(), IsWithin(1e-9), 5.0)
c.Expect(a.Mag2(), IsWithin(1e-9), 25.0)
})
c.Specify("Make sure scaling vectors works.", func() {
VecExpect(c, a.Scale(3), Equals, linear.Vec2{9, 12})
})
}
示例2: BasicPropertiesSpec
func BasicPropertiesSpec(c gospec.Context) {
a := linear.Vec2{3, 4}
b := linear.Vec2{5, 6}
c.Specify("Check that (cross a) dot a == 0.", func() {
c.Expect(a.Cross().Dot(a), Equals, 0.0)
})
c.Specify("Check that a normalize vector's magnitude is 1.", func() {
c.Expect(a.Norm().Mag(), IsWithin(1e-9), 1.0)
})
c.Specify("Check that v.Mag2() == v.Mag()*v.Mag()", func() {
c.Expect(a.Mag2(), IsWithin(1e-9), a.Mag()*a.Mag())
})
c.Specify("Check that a scaled vector's magnitude is appropriately scaled.", func() {
c.Expect(a.Scale(3.5).Mag(), IsWithin(1e-9), a.Mag()*3.5)
})
c.Specify("Check that a-(a-b) == b.", func() {
VecExpect(c, a.Sub(a.Sub(b)), IsWithin(1e-9), b)
})
}