@@ -113,7 +113,7 @@ impl EditorState {
113113 ) -> Option < & Element > {
114114 self . element_stack . iter ( ) . rev ( ) . find ( |e| {
115115 let circle = e. inner ( ) ;
116- let circle_in_pixel_coords = circle. convert_into_pixel_coordinate ( window_dimension) ;
116+ let circle_in_pixel_coords = circle. in_pixel_space ( window_dimension) ;
117117
118118 compute_distance ( circle_in_pixel_coords. center ( ) , point)
119119 <= circle_in_pixel_coords. radius ( )
@@ -161,9 +161,9 @@ impl EditorState {
161161
162162 pub fn copy_shape ( & mut self , circle : Circle , window_dimensions : ( f32 , f32 ) ) -> usize {
163163 let circle = circle
164- . convert_into_pixel_coordinate ( window_dimensions)
164+ . in_pixel_space ( window_dimensions)
165165 . translate ( ( 40.0 , 40.0 ) )
166- . convert_into_normalized_coordinate ( window_dimensions) ;
166+ . in_normalized_space ( window_dimensions) ;
167167
168168 self . create_shape ( circle)
169169 }
@@ -175,30 +175,31 @@ pub fn compute_distance(from: Coordinate, to: Coordinate) -> f32 {
175175
176176// Stored as (x, y)
177177pub type Coordinate = ( f32 , f32 ) ;
178+ pub type WindowDimension = ( f32 , f32 ) ;
178179
179- #[ derive( Debug , Clone ) ]
180+ #[ derive( Debug , Clone , Copy ) ]
180181pub struct Circle {
181182 center : Coordinate ,
182183 radius : f32 ,
183184}
184185
185186impl Circle {
186- pub fn from_pixel_coordinate (
187- center : Coordinate ,
188- radius : f32 ,
189- window_dimensions : ( f32 , f32 ) ,
187+ pub fn from_pixel_space (
188+ center_in_pixel_space : Coordinate ,
189+ radius_in_pixel_space : f32 ,
190+ window_dimension : WindowDimension ,
190191 ) -> Self {
191- let ( w, h) = window_dimensions ;
192- let ( cx, cy) = center ;
192+ let ( w, h) = window_dimension ;
193+ let ( cx, cy) = center_in_pixel_space ;
193194
194195 Self {
195196 center : ( cx / w, cy / h) ,
196- radius : radius / w. min ( h) ,
197+ radius : radius_in_pixel_space / w. min ( h) ,
197198 }
198199 }
199200
200- pub fn convert_into_normalized_coordinate ( & self , window_dimensions : ( f32 , f32 ) ) -> Self {
201- let ( w, h) = window_dimensions ;
201+ pub fn in_normalized_space ( & self , window_dimension : WindowDimension ) -> Self {
202+ let ( w, h) = window_dimension ;
202203 let ( cx, cy) = self . center ;
203204
204205 Self {
@@ -207,8 +208,8 @@ impl Circle {
207208 }
208209 }
209210
210- pub fn convert_into_pixel_coordinate ( & self , window_dimensions : ( f32 , f32 ) ) -> Self {
211- let ( w, h) = window_dimensions ;
211+ pub fn in_pixel_space ( & self , window_dimension : WindowDimension ) -> Self {
212+ let ( w, h) = window_dimension ;
212213 let ( cx, cy) = self . center ;
213214
214215 Self {
0 commit comments