@@ -8,41 +8,44 @@ pub struct Circle {
8
8
}
9
9
10
10
impl Circle {
11
+ /// Constructs a new `Circle` with the center `(x, y)` and radius `r`.
11
12
pub const fn new ( x : f32 , y : f32 , r : f32 ) -> Self {
12
13
Circle { x, y, r }
13
14
}
14
15
16
+ /// Returns the center point of the `Circle`.
15
17
pub const fn point ( & self ) -> Vec2 {
16
18
vec2 ( self . x , self . y )
17
19
}
18
20
21
+ /// Returns the radius of the `Circle`.
19
22
pub const fn radius ( & self ) -> f32 {
20
23
self . r
21
24
}
22
25
23
- /// Moves the `Circle`'s origin to (x, y)
24
- pub fn move_to ( & mut self , destination : Vec2 ) {
26
+ /// Moves the `Circle`'s origin to (x, y).
27
+ pub const fn move_to ( & mut self , destination : Vec2 ) {
25
28
self . x = destination. x ;
26
29
self . y = destination. y ;
27
30
}
28
31
29
- /// Scales the `Circle` by a factor of sr
30
- pub fn scale ( & mut self , sr : f32 ) {
32
+ /// Scales the `Circle` by a factor of `sr`.
33
+ pub const fn scale ( & mut self , sr : f32 ) {
31
34
self . r *= sr;
32
35
}
33
36
34
- /// Checks whether the `Circle` contains a `Point`
37
+ /// Checks whether the `Circle` contains a `Point`.
35
38
pub fn contains ( & self , pos : & Vec2 ) -> bool {
36
39
pos. distance ( vec2 ( self . x , self . y ) ) < self . r
37
40
}
38
41
39
- /// Checks whether the `Circle` overlaps a `Circle`
42
+ /// Checks whether the `Circle` overlaps a `Circle`.
40
43
pub fn overlaps ( & self , other : & Circle ) -> bool {
41
44
self . point ( ) . distance ( other. point ( ) ) < self . r + other. r
42
45
}
43
46
44
- /// Checks whether the `Circle` overlaps a `Rect`
45
- pub fn overlaps_rect ( & self , rect : & Rect ) -> bool {
47
+ /// Checks whether the `Circle` overlaps a `Rect`.
48
+ pub const fn overlaps_rect ( & self , rect : & Rect ) -> bool {
46
49
let dist_x = ( self . x - rect. center ( ) . x ) . abs ( ) ;
47
50
let dist_y = ( self . y - rect. center ( ) . y ) . abs ( ) ;
48
51
if dist_x > rect. w / 2.0 + self . r || dist_y > rect. h / 2.0 + self . r {
@@ -57,8 +60,8 @@ impl Circle {
57
60
dist_sq <= self . r * self . r
58
61
}
59
62
60
- /// Translate `Circle` origin by `offset` vector
61
- pub fn offset ( self , offset : Vec2 ) -> Circle {
63
+ /// Translate `Circle` origin by `offset` vector.
64
+ pub const fn offset ( self , offset : Vec2 ) -> Circle {
62
65
Circle :: new ( self . x + offset. x , self . y + offset. y , self . r )
63
66
}
64
67
}
0 commit comments