@@ -95,7 +95,7 @@ impl<Unit> Rect<Unit> {
9595 /// # Errors
9696 ///
9797 /// Returns `<NewUnit as TryFrom>::Error` when the inner type cannot be
98- /// converted. For this crate's types, this genenerally will be
98+ /// converted. For this crate's types, this generally will be
9999 pub fn try_cast < NewUnit > ( self ) -> Result < Rect < NewUnit > , NewUnit :: Error >
100100 where
101101 NewUnit : TryFrom < Unit > ,
@@ -191,24 +191,53 @@ impl<Unit> Rect<Unit> {
191191 /// Returns the non-origin point.
192192 pub fn extent ( & self ) -> Point < Unit >
193193 where
194- Unit : crate :: Unit ,
194+ Unit : Add < Output = Unit > + Copy ,
195195 {
196196 self . origin + self . size
197197 }
198198}
199199
200200impl < Unit > Rect < Unit >
201201where
202+ // alternatively we could reduce the traits for `extent()`
202203 Unit : Add < Output = Unit > + Ord + Copy ,
203204{
204205 /// Returns the top-left and bottom-right points of this rectangle.
205206 ///
206- /// The first point returned will always be the top-right point, even if the size of the rectangle is negative.
207+ /// The first point returned will always be the top-left point, even if the size of the rectangle is negative.
207208 pub fn extents ( & self ) -> ( Point < Unit > , Point < Unit > ) {
208- let extent = self . origin + self . size ;
209- (
210- Point :: new ( self . origin . x . min ( extent. x ) , self . origin . y . min ( extent. y ) ) ,
211- Point :: new ( self . origin . x . max ( extent. x ) , self . origin . y . max ( extent. y ) ) ,
209+ ( self . top_left ( ) , self . bottom_right ( ) )
210+ }
211+
212+ /// Returns the top-left corner of this rectangle.
213+ pub fn top_left ( & self ) -> Point < Unit > {
214+ Point :: new (
215+ self . origin . x . min ( self . extent ( ) . x ) ,
216+ self . origin . y . min ( self . extent ( ) . y ) ,
217+ )
218+ }
219+
220+ /// Returns the top-right corner of this rectangle.
221+ pub fn top_right ( & self ) -> Point < Unit > {
222+ Point :: new (
223+ self . origin . x . max ( self . extent ( ) . x ) ,
224+ self . origin . y . min ( self . extent ( ) . y ) ,
225+ )
226+ }
227+
228+ /// Returns the bottom-left corner of this rectangle.
229+ pub fn bottom_left ( & self ) -> Point < Unit > {
230+ Point :: new (
231+ self . origin . x . min ( self . extent ( ) . x ) ,
232+ self . origin . y . max ( self . extent ( ) . y ) ,
233+ )
234+ }
235+
236+ /// Returns the bottom-right corner of this rectangle.
237+ pub fn bottom_right ( & self ) -> Point < Unit > {
238+ Point :: new (
239+ self . origin . x . max ( self . extent ( ) . x ) ,
240+ self . origin . y . max ( self . extent ( ) . y ) ,
212241 )
213242 }
214243}
0 commit comments