pub struct ArgCmp(/* private fields */);Expand description
2次元座標の偏角順
§Examples
use arg_cmp::ArgCmp;
let north = (0, 1);
let south = (0, -1);
let east = (1, 0);
let west = (-1, 0);
let mut points = vec![north, south, east, west];
points.sort_by_key(|&(x, y)| ArgCmp::new(x, y));
// 0°, 90°, 180°, 270°
assert_eq!(points, vec![(1, 0), (0, 1), (-1, 0), (0, -1)]);§偏角が等しい例
use arg_cmp::ArgCmp;
assert!(ArgCmp::new(1, 0).cmp(&ArgCmp::new(1, 0)).is_eq());
assert!(ArgCmp::new(1, 0).cmp(&ArgCmp::new(2, 0)).is_eq());Implementations§
Source§impl ArgCmp
impl ArgCmp
pub fn x(&self) -> i64
pub fn y(&self) -> i64
Sourcepub fn quadrant(&self) -> Quadrant
pub fn quadrant(&self) -> Quadrant
象限を返す
§Examples
use arg_cmp::{ArgCmp, Quadrant};
let north_east = ArgCmp::new(1, 1);
let north_west = ArgCmp::new(-1, 1);
let south_west = ArgCmp::new(-1, -1);
let south_east = ArgCmp::new(1, -1);
assert_eq!(north_east.quadrant(), Quadrant::First);
assert_eq!(north_west.quadrant(), Quadrant::Second);
assert_eq!(south_west.quadrant(), Quadrant::Third);
assert_eq!(south_east.quadrant(), Quadrant::Fourth);Trait Implementations§
Source§impl Ord for ArgCmp
impl Ord for ArgCmp
Source§impl PartialOrd for ArgCmp
impl PartialOrd for ArgCmp
impl Copy for ArgCmp
impl Eq for ArgCmp
impl StructuralPartialEq for ArgCmp
Auto Trait Implementations§
impl Freeze for ArgCmp
impl RefUnwindSafe for ArgCmp
impl Send for ArgCmp
impl Sync for ArgCmp
impl Unpin for ArgCmp
impl UnsafeUnpin for ArgCmp
impl UnwindSafe for ArgCmp
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more