當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Vec2.Cross方法代碼示例

本文整理匯總了Golang中github.com/runningwild/linear.Vec2.Cross方法的典型用法代碼示例。如果您正苦於以下問題:Golang Vec2.Cross方法的具體用法?Golang Vec2.Cross怎麽用?Golang Vec2.Cross使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/runningwild/linear.Vec2的用法示例。


在下文中一共展示了Vec2.Cross方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: 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)
	})
}
開發者ID:runningwild,項目名稱:linear,代碼行數:19,代碼來源:linear_test.go

示例2: 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})
	})
}
開發者ID:runningwild,項目名稱:linear,代碼行數:23,代碼來源:linear_test.go


注:本文中的github.com/runningwild/linear.Vec2.Cross方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。