]> git.lizzy.rs Git - rust.git/blob - src/test/incremental/change_private_impl_method_cc/auxiliary/point.rs
Rollup merge of #42037 - nagisa:charpat, r=sfackler
[rust.git] / src / test / incremental / change_private_impl_method_cc / auxiliary / point.rs
1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 pub struct Point {
12     pub x: f32,
13     pub y: f32,
14 }
15
16 impl Point {
17     fn distance_squared(&self) -> f32 {
18         #[cfg(rpass1)]
19         return self.x + self.y;
20
21         #[cfg(rpass2)]
22         return self.x * self.x + self.y * self.y;
23     }
24
25     pub fn distance_from_origin(&self) -> f32 {
26         self.distance_squared().sqrt()
27     }
28 }
29
30 impl Point {
31     pub fn translate(&mut self, x: f32, y: f32) {
32         self.x += x;
33         self.y += y;
34     }
35 }