| 1 | // Copyright 2012 Google Inc. |
| 2 | // Copyright 2020 Yevhenii Reizner |
| 3 | // |
| 4 | // Use of this source code is governed by a BSD-style license that can be |
| 5 | // found in the LICENSE file. |
| 6 | |
| 7 | use crate::Point; |
| 8 | |
| 9 | #[derive (Copy, Clone, PartialEq, Debug)] |
| 10 | pub enum SearchAxis { |
| 11 | X, |
| 12 | Y, |
| 13 | } |
| 14 | |
| 15 | #[repr (C)] |
| 16 | #[derive (Copy, Clone, PartialEq, Default, Debug)] |
| 17 | pub struct Point64 { |
| 18 | pub x: f64, |
| 19 | pub y: f64, |
| 20 | } |
| 21 | |
| 22 | impl Point64 { |
| 23 | pub fn from_xy(x: f64, y: f64) -> Self { |
| 24 | Point64 { x, y } |
| 25 | } |
| 26 | |
| 27 | pub fn from_point(p: Point) -> Self { |
| 28 | Point64 { |
| 29 | x: f64::from(p.x), |
| 30 | y: f64::from(p.y), |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | pub fn zero() -> Self { |
| 35 | Point64 { x: 0.0, y: 0.0 } |
| 36 | } |
| 37 | |
| 38 | pub fn to_point(&self) -> Point { |
| 39 | Point::from_xy(self.x as f32, self.y as f32) |
| 40 | } |
| 41 | |
| 42 | pub fn axis_coord(&self, axis: SearchAxis) -> f64 { |
| 43 | match axis { |
| 44 | SearchAxis::X => self.x, |
| 45 | SearchAxis::Y => self.y, |
| 46 | } |
| 47 | } |
| 48 | } |
| 49 | |