Skip to content

Commit e7f53d0

Browse files
Steditorad-si
authored andcommitted
Move classes to subfolders
1 parent 2f9567f commit e7f53d0

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

source/primitives/Vector.coffee

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
class Vector
2+
constructor: (@x, @y, @z) ->
3+
return
4+
5+
@fromObject: (object) ->
6+
return new Vector object.x, object.y, object.z
7+
8+
@fromArray: (array) ->
9+
return new Vector array[0], array[1], array[2]
10+
11+
minus: (vec) ->
12+
return new Vector(@x - vec.x, @y - vec.y, @z - vec.z)
13+
14+
add: (vec) ->
15+
return new Vector(@x + vec.x, @y + vec.y, @z + vec.z)
16+
17+
crossProduct: (vec) ->
18+
return new Vector(@y * vec.z - @z * vec.y,
19+
@z * vec.x - @x * vec.z,
20+
@x * vec.y - @y * vec.x)
21+
22+
length: () ->
23+
return Math.sqrt(@x * @x + @y * @y + @z * @z)
24+
25+
euclideanDistanceTo: (vec) ->
26+
return (@minus vec).length()
27+
28+
multiplyScalar: (scalar) ->
29+
return new Vector(@x * scalar, @y * scalar, @z * scalar)
30+
31+
normalized: () ->
32+
return @multiplyScalar (1.0 / @length())
33+
34+
module.exports = Vector

0 commit comments

Comments
 (0)