Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(2488)

Delta Between Two Patch Sets: f32/vec4.go

Issue 141440043: code review 141440043: go.mobile/f32: float32 math library (Closed)
Left Patch Set: Created 9 years, 6 months ago
Right Patch Set: diff -r 547bbce45af3444f8b5d9a209501de569c9fd460 https://code.google.com/p/go.mobile Created 9 years, 6 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « f32/vec3.go ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 // Copyright 2014 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 package f32
6
7 import "fmt"
8
9 type Vec4 [4]float32
10
11 func (v *Vec4) Normalize() {
12 sq := v.Dot(v)
13 inv := 1 / Sqrt(sq)
14 v[0] *= inv
15 v[1] *= inv
16 v[2] *= inv
17 v[3] *= inv
18 }
19
20 func (v *Vec4) Sub(v0, v1 *Vec4) {
21 v[0] = v0[0] - v1[0]
22 v[1] = v0[1] - v1[1]
23 v[2] = v0[2] - v1[2]
24 v[3] = v0[3] - v1[3]
25 }
26
27 func (v *Vec4) Add(v0, v1 *Vec4) {
28 v[0] = v0[0] + v1[0]
29 v[1] = v0[1] + v1[1]
30 v[2] = v0[2] + v1[2]
31 v[3] = v0[3] + v1[3]
32 }
33
34 func (v *Vec4) Mul(v0, v1 *Vec4) {
35 v[0] = v0[0] * v1[0]
36 v[1] = v0[1] * v1[1]
37 v[2] = v0[2] * v1[2]
38 v[3] = v0[3] * v1[3]
39 }
40
41 func (v *Vec4) Dot(v1 *Vec4) float32 {
42 return v[0]*v1[0] + v[1]*v1[1] + v[2]*v1[2] + v[3]*v1[3]
43 }
44
45 func (v Vec4) String() string {
46 return fmt.Sprintf("Vec4[% 0.3f, % 0.3f, % 0.3f, % 0.3f]", v[0], v[1], v [2], v[3])
47 }
LEFTRIGHT
« f32/vec3.go ('k') | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b