@@ -52,7 +52,12 @@ impl Transform3d {
5252
5353 /// Construct a transform from its four columns.
5454 ///
55- /// Each column is `[x, y, z, w]`.
55+ /// Each column contains the contribution of one input coordinate to the
56+ /// output `[x, y, z, w]`. When transforming a column vector
57+ /// `[x, y, z, w]`, `col0` is multiplied by the input `x`, `col1` by the
58+ /// input `y`, `col2` by the input `z`, and `col3` by the input `w`; the
59+ /// scaled columns are then added. For points with `w == 1`, `col3` is the
60+ /// translation column.
5661 #[ inline]
5762 #[ must_use]
5863 pub const fn from_cols ( col0 : [ f64 ; 4 ] , col1 : [ f64 ; 4 ] , col2 : [ f64 ; 4 ] , col3 : [ f64 ; 4 ] ) -> Self {
@@ -104,7 +109,27 @@ impl Transform3d {
104109 self . 0 [ i]
105110 }
106111
107- /// Construct the 3D transform with the same effect as a 2D [`Affine`].
112+ /// Return row `i` in conventional matrix notation.
113+ ///
114+ /// This gathers the `i`th coefficient from each stored column. Row 0 holds
115+ /// the coefficients used to compute the output x coordinate, row 1 the
116+ /// output y coordinate, and so on.
117+ ///
118+ /// # Panics
119+ ///
120+ /// Panics if `i >= 4`.
121+ #[ inline]
122+ #[ must_use]
123+ pub const fn row ( self , i : usize ) -> [ f64 ; 4 ] {
124+ let c = self . 0 ;
125+ [ c[ 0 ] [ i] , c[ 1 ] [ i] , c[ 2 ] [ i] , c[ 3 ] [ i] ]
126+ }
127+
128+ /// Construct the 3D transform with the same effect as a 2D [`Affine`] in
129+ /// the xy plane.
130+ ///
131+ /// Points are embedded as `[x, y, 0, 1]`; the resulting transform applies
132+ /// the affine transform to x and y and leaves z unchanged.
108133 #[ inline]
109134 #[ must_use]
110135 pub const fn from_affine ( affine : Affine ) -> Self {
@@ -546,6 +571,8 @@ mod tests {
546571 assert_eq ! ( transform. as_coeffs( ) , coeffs) ;
547572 assert_eq ! ( transform. col( 0 ) , [ 1.0 , 2.0 , 3.0 , 4.0 ] ) ;
548573 assert_eq ! ( transform. col( 3 ) , [ 13.0 , 14.0 , 15.0 , 16.0 ] ) ;
574+ assert_eq ! ( transform. row( 0 ) , [ 1.0 , 5.0 , 9.0 , 13.0 ] ) ;
575+ assert_eq ! ( transform. row( 3 ) , [ 4.0 , 8.0 , 12.0 , 16.0 ] ) ;
549576 }
550577
551578 #[ test]
0 commit comments