File tree Expand file tree Collapse file tree 6 files changed +102
-0
lines changed Expand file tree Collapse file tree 6 files changed +102
-0
lines changed Original file line number Diff line number Diff line change @@ -103,6 +103,27 @@ class Vec2 {
103
103
return this ;
104
104
}
105
105
106
+ /**
107
+ * Adds a 2-dimensional vector scaled by scalar value. Does not modify the vector being added.
108
+ *
109
+ * @param {Vec2 } rhs - The vector to add to the specified vector.
110
+ * @param {number } scalar - The number to multiply the added vector with.
111
+ * @returns {Vec2 } Self for chaining.
112
+ * @example
113
+ * const vec = new pc.Vec2(1, 2);
114
+ *
115
+ * vec.addScaled(pc.Vec2.UP, 2);
116
+ *
117
+ * // Outputs [1, 4]
118
+ * console.log("The result of the addition is: " + vec.toString());
119
+ */
120
+ addScaled ( rhs , scalar ) {
121
+ this . x += rhs . x * scalar ;
122
+ this . y += rhs . y * scalar ;
123
+
124
+ return this ;
125
+ }
126
+
106
127
/**
107
128
* Returns an identical copy of the specified 2-dimensional vector.
108
129
*
Original file line number Diff line number Diff line change @@ -114,6 +114,28 @@ class Vec3 {
114
114
return this ;
115
115
}
116
116
117
+ /**
118
+ * Adds a 3-dimensional vector scaled by scalar value. Does not modify the vector being added.
119
+ *
120
+ * @param {Vec3 } rhs - The vector to add to the specified vector.
121
+ * @param {number } scalar - The number to multiply the added vector with.
122
+ * @returns {Vec3 } Self for chaining.
123
+ * @example
124
+ * const vec = new pc.Vec3(1, 2, 3);
125
+ *
126
+ * vec.addScaled(pc.Vec3.UP, 2);
127
+ *
128
+ * // Outputs [1, 4, 3]
129
+ * console.log("The result of the addition is: " + vec.toString());
130
+ */
131
+ addScaled ( rhs , scalar ) {
132
+ this . x += rhs . x * scalar ;
133
+ this . y += rhs . y * scalar ;
134
+ this . z += rhs . z * scalar ;
135
+
136
+ return this ;
137
+ }
138
+
117
139
/**
118
140
* Returns an identical copy of the specified 3-dimensional vector.
119
141
*
Original file line number Diff line number Diff line change @@ -127,6 +127,29 @@ class Vec4 {
127
127
return this ;
128
128
}
129
129
130
+ /**
131
+ * Adds a 4-dimensional vector scaled by scalar value. Does not modify the vector being added.
132
+ *
133
+ * @param {Vec4 } rhs - The vector to add to the specified vector.
134
+ * @param {number } scalar - The number to multiply the added vector with.
135
+ * @returns {Vec4 } Self for chaining.
136
+ * @example
137
+ * const vec = new pc.Vec4(1, 2, 3, 4);
138
+ *
139
+ * vec.addScaled(pc.Vec4.ONE, 2);
140
+ *
141
+ * // Outputs [3, 4, 5, 6]
142
+ * console.log("The result of the addition is: " + vec.toString());
143
+ */
144
+ addScaled ( rhs , scalar ) {
145
+ this . x += rhs . x * scalar ;
146
+ this . y += rhs . y * scalar ;
147
+ this . z += rhs . z * scalar ;
148
+ this . w += rhs . w * scalar ;
149
+
150
+ return this ;
151
+ }
152
+
130
153
/**
131
154
* Returns an identical copy of the specified 4-dimensional vector.
132
155
*
Original file line number Diff line number Diff line change @@ -76,6 +76,17 @@ describe('Vec2', function () {
76
76
77
77
} ) ;
78
78
79
+ describe ( '#addScaled' , function ( ) {
80
+
81
+ it ( 'adds a scaled vector' , function ( ) {
82
+ const v = new Vec2 ( 1 , 2 ) ;
83
+ v . addScaled ( Vec2 . UP , 2 ) ;
84
+ expect ( v . x ) . to . equal ( 1 ) ;
85
+ expect ( v . y ) . to . equal ( 4 ) ;
86
+ } ) ;
87
+
88
+ } ) ;
89
+
79
90
describe ( '#ceil' , function ( ) {
80
91
81
92
it ( 'leaves integers unchanged' , function ( ) {
Original file line number Diff line number Diff line change @@ -84,6 +84,18 @@ describe('Vec3', function () {
84
84
85
85
} ) ;
86
86
87
+ describe ( '#addScaled' , function ( ) {
88
+
89
+ it ( 'adds a scaled vector' , function ( ) {
90
+ const v = new Vec3 ( 1 , 2 , 3 ) ;
91
+ v . addScaled ( Vec3 . UP , 2 ) ;
92
+ expect ( v . x ) . to . equal ( 1 ) ;
93
+ expect ( v . y ) . to . equal ( 4 ) ;
94
+ expect ( v . z ) . to . equal ( 3 ) ;
95
+ } ) ;
96
+
97
+ } ) ;
98
+
87
99
describe ( '#ceil' , function ( ) {
88
100
89
101
it ( 'leaves integers unchanged' , function ( ) {
Original file line number Diff line number Diff line change @@ -92,6 +92,19 @@ describe('Vec4', function () {
92
92
93
93
} ) ;
94
94
95
+ describe ( '#addScaled' , function ( ) {
96
+
97
+ it ( 'adds a scaled vector' , function ( ) {
98
+ const v = new Vec4 ( 1 , 2 , 3 , 4 ) ;
99
+ v . addScaled ( Vec4 . ONE , 2 ) ;
100
+ expect ( v . x ) . to . equal ( 3 ) ;
101
+ expect ( v . y ) . to . equal ( 4 ) ;
102
+ expect ( v . z ) . to . equal ( 5 ) ;
103
+ expect ( v . w ) . to . equal ( 6 ) ;
104
+ } ) ;
105
+
106
+ } ) ;
107
+
95
108
describe ( '#ceil' , function ( ) {
96
109
97
110
it ( 'leaves integers unchanged' , function ( ) {
You can’t perform that action at this time.
0 commit comments