@@ -4,7 +4,6 @@ use std::{
44} ;
55
66use serde:: { Deserialize , Serialize } ;
7- use serde_tuple:: { Deserialize_tuple , Serialize_tuple } ;
87
98use crate :: {
109 maps:: {
@@ -43,26 +42,68 @@ impl Display for ContinentFloorId {
4342 }
4443}
4544
46- #[ derive( Clone , Debug , PartialOrd , PartialEq , Serialize_tuple , Deserialize_tuple ) ]
47- #[ cfg_attr ( test , serde ( deny_unknown_fields ) ) ]
45+ #[ derive( Clone , Debug , PartialOrd , PartialEq , Serialize , Deserialize ) ]
46+ #[ serde ( from = "[f32; 2]" , into = "[f32; 2]" ) ]
4847pub struct Coordinates {
4948 pub x : f32 ,
5049 pub y : f32 ,
5150}
51+ impl From < [ f32 ; 2 ] > for Coordinates {
52+ fn from ( [ x, y] : [ f32 ; 2 ] ) -> Self {
53+ Self { x, y }
54+ }
55+ }
56+ impl From < Coordinates > for [ f32 ; 2 ] {
57+ fn from ( v : Coordinates ) -> Self {
58+ [ v. x , v. y ]
59+ }
60+ }
5261
53- #[ derive( Clone , Debug , PartialOrd , PartialEq , Serialize_tuple , Deserialize_tuple ) ]
54- #[ cfg_attr ( test , serde ( deny_unknown_fields ) ) ]
62+ #[ derive( Clone , Debug , PartialOrd , PartialEq , Serialize , Deserialize ) ]
63+ #[ serde ( from = "[Coordinates; 2]" , into = "[Coordinates; 2]" ) ]
5564pub struct ContinentRectangle {
5665 pub top_left : Coordinates ,
5766 pub bottom_right : Coordinates ,
5867}
68+ impl < C : Into < Coordinates > > From < [ C ; 2 ] > for ContinentRectangle {
69+ fn from ( [ top_left, bottom_right] : [ C ; 2 ] ) -> Self {
70+ Self {
71+ top_left : top_left. into ( ) ,
72+ bottom_right : bottom_right. into ( ) ,
73+ }
74+ }
75+ }
76+ impl < C > From < ContinentRectangle > for [ C ; 2 ]
77+ where
78+ Coordinates : Into < C > ,
79+ {
80+ fn from ( v : ContinentRectangle ) -> Self {
81+ [ v. top_left . into ( ) , v. bottom_right . into ( ) ]
82+ }
83+ }
5984
60- #[ derive( Clone , Debug , PartialOrd , PartialEq , Serialize_tuple , Deserialize_tuple ) ]
61- #[ cfg_attr ( test , serde ( deny_unknown_fields ) ) ]
85+ #[ derive( Clone , Debug , PartialOrd , PartialEq , Serialize , Deserialize ) ]
86+ #[ serde ( from = "[Coordinates; 2]" , into = "[Coordinates; 2]" ) ]
6287pub struct MapRectangle {
6388 pub bottom_left : Coordinates ,
6489 pub top_right : Coordinates ,
6590}
91+ impl < C : Into < Coordinates > > From < [ C ; 2 ] > for MapRectangle {
92+ fn from ( [ bottom_left, top_right] : [ C ; 2 ] ) -> Self {
93+ Self {
94+ bottom_left : bottom_left. into ( ) ,
95+ top_right : top_right. into ( ) ,
96+ }
97+ }
98+ }
99+ impl < C > From < MapRectangle > for [ C ; 2 ]
100+ where
101+ Coordinates : Into < C > ,
102+ {
103+ fn from ( v : MapRectangle ) -> Self {
104+ [ v. bottom_left . into ( ) , v. top_right . into ( ) ]
105+ }
106+ }
66107
67108#[ derive( Clone , PartialEq , Eq , PartialOrd , Debug , Serialize , Deserialize ) ]
68109#[ serde( rename_all = "lowercase" ) ]
0 commit comments