1
1
/**
2
2
* @author mr.doob / http://mrdoob.com/
3
3
* @author philogb / http://blog.thejit.org/
4
+ * @author egraether / http://egraether.com/
4
5
*/
5
6
6
7
THREE . Vector2 = function ( x , y ) {
@@ -27,100 +28,98 @@ THREE.Vector2.prototype = {
27
28
28
29
copy : function ( v ) {
29
30
30
- this . set (
31
-
32
- v . x ,
33
- v . y
34
-
35
- ) ;
31
+ this . x = v . x ;
32
+ this . y = v . y ;
36
33
37
34
return this ;
38
35
39
36
} ,
40
37
41
- addSelf : function ( v ) {
38
+ clone : function ( ) {
42
39
43
- this . set (
40
+ return new THREE . Vector2 ( this . x , this . y ) ;
44
41
45
- this . x + v . x ,
46
- this . y + v . y
42
+ } ,
47
43
48
- ) ;
44
+
45
+ add : function ( v1 , v2 ) {
46
+
47
+ this . x = v1 . x + v2 . x ;
48
+ this . y = v1 . y + v2 . y ;
49
49
50
50
return this ;
51
51
52
52
} ,
53
53
54
- add : function ( v1 , v2 ) {
54
+ addSelf : function ( v ) {
55
55
56
- this . set (
56
+ this . x += v . x ;
57
+ this . y += v . y ;
57
58
58
- v1 . x + v2 . x ,
59
- v1 . y + v2 . y
59
+ return this ;
60
+
61
+ } ,
60
62
61
- ) ;
63
+ sub : function ( v1 , v2 ) {
64
+
65
+ this . x = v1 . x - v2 . x ;
66
+ this . y = v1 . y - v2 . y ;
62
67
63
68
return this ;
64
69
65
70
} ,
66
71
67
72
subSelf : function ( v ) {
68
73
69
- this . set (
70
-
71
- this . x - v . x ,
72
- this . y - v . y
73
-
74
- ) ;
74
+ this . x -= v . x ;
75
+ this . y -= v . y ;
75
76
76
77
return this ;
77
78
78
79
} ,
79
80
80
- sub : function ( v1 , v2 ) {
81
-
82
- this . set (
83
-
84
- v1 . x - v2 . x ,
85
- v1 . y - v2 . y
81
+ multiplyScalar : function ( s ) {
86
82
87
- ) ;
83
+ this . x *= s ;
84
+ this . y *= s ;
88
85
89
86
return this ;
90
87
91
88
} ,
92
89
93
- multiplyScalar : function ( s ) {
90
+ divideScalar : function ( s ) {
91
+
92
+ if ( s ) {
93
+
94
+ this . x /= s ;
95
+ this . y /= s ;
94
96
95
- this . set (
97
+ } else {
96
98
97
- this . x * s ,
98
- this . y * s
99
+ this . set ( 0 , 0 ) ;
99
100
100
- ) ;
101
+ }
101
102
102
103
return this ;
103
104
104
105
} ,
105
106
107
+
106
108
negate : function ( ) {
107
109
108
- this . set (
110
+ return this . multiplyScalar ( - 1 ) ;
109
111
110
- - this . x ,
111
- - this . y
112
+ } ,
112
113
113
- ) ;
114
+ dot : function ( v ) {
114
115
115
- return this ;
116
+ return this . x * v . x + this . y * v . y ;
116
117
117
118
} ,
118
119
119
- unit : function ( ) {
120
-
121
- this . multiplyScalar ( 1 / this . length ( ) ) ;
120
+ lengthSq : function ( ) {
122
121
123
- return this ;
122
+ return this . x * this . x + this . y * this . y ;
124
123
125
124
} ,
126
125
@@ -130,15 +129,25 @@ THREE.Vector2.prototype = {
130
129
131
130
} ,
132
131
133
- lengthSq : function ( ) {
132
+ normalize : function ( ) {
134
133
135
- return this . x * this . x + this . y * this . y ;
134
+ return this . divideScalar ( this . length ( ) ) ;
136
135
137
136
} ,
138
137
139
- clone : function ( ) {
138
+ setLength : function ( l ) {
140
139
141
- return new THREE . Vector2 ( this . x , this . y ) ;
140
+ return this . normalize ( ) . multiplyScalar ( l ) ;
141
+
142
+ } ,
143
+
144
+ // deprecated: same as normalize
145
+ unit : function ( ) {
146
+
147
+ return this . normalize ( ) ;
148
+
149
+ // this.multiplyScalar( 1 / this.length() );
150
+ // return this;
142
151
143
152
}
144
153
0 commit comments