@@ -792,7 +792,7 @@ const rotateZ = rotate;
792
792
793
793
/**
794
794
* Creates a 3-by-3 matrix which scales in each dimension by an amount given by
795
- * the corresponding entry in the given vector; assumes the vector has three
795
+ * the corresponding entry in the given vector; assumes the vector has two
796
796
* entries.
797
797
* @param v - A vector of
798
798
* 2 entries specifying the factor by which to scale in each dimension.
@@ -812,7 +812,7 @@ function scaling<T extends Mat3Arg = MatType>(v: Vec2Arg, dst?: T) {
812
812
/**
813
813
* Scales the given 3-by-3 matrix in each dimension by an amount
814
814
* given by the corresponding entry in the given vector; assumes the vector has
815
- * three entries.
815
+ * two entries.
816
816
* @param m - The matrix to be modified.
817
817
* @param v - A vector of 2 entries specifying the
818
818
* factor by which to scale in each dimension.
@@ -843,7 +843,58 @@ function scale<T extends Mat3Arg = MatType>(m: Mat3Arg, v: Vec2Arg, dst?: T) {
843
843
}
844
844
845
845
/**
846
- * Creates a 3-by-3 matrix which scales uniformly in each dimension
846
+ * Creates a 3-by-3 matrix which scales in each dimension by an amount given by
847
+ * the corresponding entry in the given vector; assumes the vector has three
848
+ * entries.
849
+ * @param v - A vector of
850
+ * 3 entries specifying the factor by which to scale in each dimension.
851
+ * @param dst - matrix to hold result. If not passed a new one is created.
852
+ * @returns The scaling matrix.
853
+ */
854
+ function scaling3D < T extends Mat3Arg = MatType > ( v : Vec3Arg , dst ?: T ) {
855
+ const newDst = ( dst ?? new Ctor ( 12 ) ) as T ;
856
+
857
+ newDst [ 0 ] = v [ 0 ] ; newDst [ 1 ] = 0 ; newDst [ 2 ] = 0 ;
858
+ newDst [ 4 ] = 0 ; newDst [ 5 ] = v [ 1 ] ; newDst [ 6 ] = 0 ;
859
+ newDst [ 8 ] = 0 ; newDst [ 9 ] = 0 ; newDst [ 10 ] = v [ 2 ] ;
860
+
861
+ return newDst ;
862
+ }
863
+
864
+ /**
865
+ * Scales the given 3-by-3 matrix in each dimension by an amount
866
+ * given by the corresponding entry in the given vector; assumes the vector has
867
+ * three entries.
868
+ * @param m - The matrix to be modified.
869
+ * @param v - A vector of 3 entries specifying the
870
+ * factor by which to scale in each dimension.
871
+ * @param dst - matrix to hold result. If not passed a new one is created.
872
+ * @returns The scaled matrix.
873
+ */
874
+ function scale3D < T extends Mat3Arg = MatType > ( m : Mat3Arg , v : Vec3Arg , dst ?: T ) {
875
+ const newDst = ( dst ?? new Ctor ( 12 ) ) as T ;
876
+
877
+ const v0 = v [ 0 ] ;
878
+ const v1 = v [ 1 ] ;
879
+ const v2 = v [ 2 ] ;
880
+
881
+ newDst [ 0 ] = v0 * m [ 0 * 4 + 0 ] ;
882
+ newDst [ 1 ] = v0 * m [ 0 * 4 + 1 ] ;
883
+ newDst [ 2 ] = v0 * m [ 0 * 4 + 2 ] ;
884
+
885
+ newDst [ 4 ] = v1 * m [ 1 * 4 + 0 ] ;
886
+ newDst [ 5 ] = v1 * m [ 1 * 4 + 1 ] ;
887
+ newDst [ 6 ] = v1 * m [ 1 * 4 + 2 ] ;
888
+
889
+ newDst [ 8 ] = v2 * m [ 2 * 4 + 0 ] ;
890
+ newDst [ 9 ] = v2 * m [ 2 * 4 + 1 ] ;
891
+ newDst [ 10 ] = v2 * m [ 2 * 4 + 2 ] ;
892
+
893
+ return newDst ;
894
+ }
895
+
896
+ /**
897
+ * Creates a 3-by-3 matrix which scales uniformly in the X and Y dimensions
847
898
* @param s - Amount to scale
848
899
* @param dst - matrix to hold result. If not passed a new one is created.
849
900
* @returns The scaling matrix.
@@ -859,7 +910,7 @@ function uniformScaling<T extends Mat3Arg = MatType>(s: number, dst?: T) {
859
910
}
860
911
861
912
/**
862
- * Scales the given 3-by-3 matrix in each dimension by an amount
913
+ * Scales the given 3-by-3 matrix in the X and Y dimension by an amount
863
914
* given.
864
915
* @param m - The matrix to be modified.
865
916
* @param s - Amount to scale.
@@ -886,6 +937,48 @@ function uniformScale<T extends Mat3Arg = MatType>(m: Mat3Arg, s: number, dst?:
886
937
return newDst ;
887
938
}
888
939
940
+ /**
941
+ * Creates a 3-by-3 matrix which scales uniformly in each dimension
942
+ * @param s - Amount to scale
943
+ * @param dst - matrix to hold result. If not passed a new one is created.
944
+ * @returns The scaling matrix.
945
+ */
946
+ function uniformScaling3D < T extends Mat3Arg = MatType > ( s : number , dst ?: T ) {
947
+ const newDst = ( dst ?? new Ctor ( 12 ) ) as T ;
948
+
949
+ newDst [ 0 ] = s ; newDst [ 1 ] = 0 ; newDst [ 2 ] = 0 ;
950
+ newDst [ 4 ] = 0 ; newDst [ 5 ] = s ; newDst [ 6 ] = 0 ;
951
+ newDst [ 8 ] = 0 ; newDst [ 9 ] = 0 ; newDst [ 10 ] = s ;
952
+
953
+ return newDst ;
954
+ }
955
+
956
+ /**
957
+ * Scales the given 3-by-3 matrix in each dimension by an amount
958
+ * given.
959
+ * @param m - The matrix to be modified.
960
+ * @param s - Amount to scale.
961
+ * @param dst - matrix to hold result. If not passed a new one is created.
962
+ * @returns The scaled matrix.
963
+ */
964
+ function uniformScale3D < T extends Mat3Arg = MatType > ( m : Mat3Arg , s : number , dst ?: T ) {
965
+ const newDst = ( dst ?? new Ctor ( 12 ) ) as T ;
966
+
967
+ newDst [ 0 ] = s * m [ 0 * 4 + 0 ] ;
968
+ newDst [ 1 ] = s * m [ 0 * 4 + 1 ] ;
969
+ newDst [ 2 ] = s * m [ 0 * 4 + 2 ] ;
970
+
971
+ newDst [ 4 ] = s * m [ 1 * 4 + 0 ] ;
972
+ newDst [ 5 ] = s * m [ 1 * 4 + 1 ] ;
973
+ newDst [ 6 ] = s * m [ 1 * 4 + 2 ] ;
974
+
975
+ newDst [ 8 ] = s * m [ 2 * 4 + 0 ] ;
976
+ newDst [ 9 ] = s * m [ 2 * 4 + 1 ] ;
977
+ newDst [ 10 ] = s * m [ 2 * 4 + 2 ] ;
978
+
979
+ return newDst ;
980
+ }
981
+
889
982
return {
890
983
clone,
891
984
create,
@@ -923,6 +1016,10 @@ return {
923
1016
scale,
924
1017
uniformScaling,
925
1018
uniformScale,
1019
+ scaling3D,
1020
+ scale3D,
1021
+ uniformScaling3D,
1022
+ uniformScale3D,
926
1023
} ;
927
1024
928
1025
}
0 commit comments