@@ -578,6 +578,54 @@ pub enum ProjectionEye {
578
578
Right = 2 ,
579
579
}
580
580
581
+ impl std:: fmt:: Display for Projection {
582
+ /// Formats `Projection` to match Godot's string representation.
583
+ ///
584
+ /// Example:
585
+ /// ```
586
+ /// use godot::prelude::*;
587
+ /// let proj = Projection::new([
588
+ /// Vector4::new(1.0, 2.5, 1.0, 0.5),
589
+ /// Vector4::new(0.0, 1.5, 2.0, 0.5),
590
+ /// Vector4::new(0.0, 0.0, 3.0, 2.5),
591
+ /// Vector4::new(3.0, 1.0, 4.0, 1.5),
592
+ /// ]);
593
+ /// const FMT_RESULT: &str = r"
594
+ /// 1, 0, 0, 3
595
+ /// 2.5, 1.5, 0, 1
596
+ /// 1, 2, 3, 4
597
+ /// 0.5, 0.5, 2.5, 1.5
598
+ /// ";
599
+ /// assert_eq!(format!("{}", proj), FMT_RESULT);
600
+ /// ```
601
+ fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
602
+ write ! (
603
+ f,
604
+ "\n {}, {}, {}, {}\n {}, {}, {}, {}\n {}, {}, {}, {}\n {}, {}, {}, {}\n " ,
605
+ // first row
606
+ self . cols[ 0 ] [ Vector4Axis :: X ] ,
607
+ self . cols[ 1 ] [ Vector4Axis :: X ] ,
608
+ self . cols[ 2 ] [ Vector4Axis :: X ] ,
609
+ self . cols[ 3 ] [ Vector4Axis :: X ] ,
610
+ // second row
611
+ self . cols[ 0 ] [ Vector4Axis :: Y ] ,
612
+ self . cols[ 1 ] [ Vector4Axis :: Y ] ,
613
+ self . cols[ 2 ] [ Vector4Axis :: Y ] ,
614
+ self . cols[ 3 ] [ Vector4Axis :: Y ] ,
615
+ // third row
616
+ self . cols[ 0 ] [ Vector4Axis :: Z ] ,
617
+ self . cols[ 1 ] [ Vector4Axis :: Z ] ,
618
+ self . cols[ 2 ] [ Vector4Axis :: Z ] ,
619
+ self . cols[ 3 ] [ Vector4Axis :: Z ] ,
620
+ // forth row
621
+ self . cols[ 0 ] [ Vector4Axis :: W ] ,
622
+ self . cols[ 1 ] [ Vector4Axis :: W ] ,
623
+ self . cols[ 2 ] [ Vector4Axis :: W ] ,
624
+ self . cols[ 3 ] [ Vector4Axis :: W ] ,
625
+ )
626
+ }
627
+ }
628
+
581
629
#[ cfg( test) ]
582
630
mod test {
583
631
// TODO(bromeon): reduce code duplication
@@ -1033,51 +1081,3 @@ mod test {
1033
1081
crate :: builtin:: test_utils:: roundtrip ( & projection, expected_json) ;
1034
1082
}
1035
1083
}
1036
-
1037
- impl std:: fmt:: Display for Projection {
1038
- /// Formats `Projection` to match Godot's string representation.
1039
- ///
1040
- /// Example:
1041
- /// ```
1042
- /// use godot::prelude::*;
1043
- /// let proj = Projection::new([
1044
- /// Vector4::new(1.0, 2.5, 1.0, 0.5),
1045
- /// Vector4::new(0.0, 1.5, 2.0, 0.5),
1046
- /// Vector4::new(0.0, 0.0, 3.0, 2.5),
1047
- /// Vector4::new(3.0, 1.0, 4.0, 1.5),
1048
- /// ]);
1049
- /// const FMT_RESULT: &str = r"
1050
- /// 1, 0, 0, 3
1051
- /// 2.5, 1.5, 0, 1
1052
- /// 1, 2, 3, 4
1053
- /// 0.5, 0.5, 2.5, 1.5
1054
- /// ";
1055
- /// assert_eq!(format!("{}", proj), FMT_RESULT);
1056
- /// ```
1057
- fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
1058
- write ! (
1059
- f,
1060
- "\n {}, {}, {}, {}\n {}, {}, {}, {}\n {}, {}, {}, {}\n {}, {}, {}, {}\n " ,
1061
- // first row
1062
- self . cols[ 0 ] [ Vector4Axis :: X ] ,
1063
- self . cols[ 1 ] [ Vector4Axis :: X ] ,
1064
- self . cols[ 2 ] [ Vector4Axis :: X ] ,
1065
- self . cols[ 3 ] [ Vector4Axis :: X ] ,
1066
- // second row
1067
- self . cols[ 0 ] [ Vector4Axis :: Y ] ,
1068
- self . cols[ 1 ] [ Vector4Axis :: Y ] ,
1069
- self . cols[ 2 ] [ Vector4Axis :: Y ] ,
1070
- self . cols[ 3 ] [ Vector4Axis :: Y ] ,
1071
- // third row
1072
- self . cols[ 0 ] [ Vector4Axis :: Z ] ,
1073
- self . cols[ 1 ] [ Vector4Axis :: Z ] ,
1074
- self . cols[ 2 ] [ Vector4Axis :: Z ] ,
1075
- self . cols[ 3 ] [ Vector4Axis :: Z ] ,
1076
- // forth row
1077
- self . cols[ 0 ] [ Vector4Axis :: W ] ,
1078
- self . cols[ 1 ] [ Vector4Axis :: W ] ,
1079
- self . cols[ 2 ] [ Vector4Axis :: W ] ,
1080
- self . cols[ 3 ] [ Vector4Axis :: W ] ,
1081
- )
1082
- }
1083
- }
0 commit comments