pub enum Ccw {
OnlineFront = -2,
Clockwise = -1,
OnSegment = 0,
CounterClockwise = 1,
OnlineBack = 2,
}
Variants§
OnlineFront = -2
a–b–c
Clockwise = -1
a–b-vc
OnSegment = 0
a–c–b
CounterClockwise = 1
a–b-^c
OnlineBack = 2
c–a–b
Implementations§
Source§impl Ccw
impl Ccw
Sourcepub fn ccw<T>(a: Complex<T>, b: Complex<T>, c: Complex<T>) -> Selfwhere
T: Ccwable,
pub fn ccw<T>(a: Complex<T>, b: Complex<T>, c: Complex<T>) -> Selfwhere
T: Ccwable,
Examples found in repository?
crates/competitive/src/geometry/line.rs (line 21)
20 pub fn ccw(&self, p: Complex<T>) -> Ccw {
21 Ccw::ccw(self.p1, self.p2, p)
22 }
23 pub fn is_parallel(&self, other: &Self) -> bool {
24 Approx(self.dir().cross(other.dir())) == Approx(T::zero())
25 }
26 pub fn is_orthogonal(&self, other: &Self) -> bool {
27 Approx(self.dir().dot(other.dir())) == Approx(T::zero())
28 }
29}
30impl<T> Line<T>
31where
32 T: Ccwable + Float,
33{
34 pub fn projection(&self, p: Complex<T>) -> Complex<T> {
35 let e = self.dir().unit();
36 self.p1 + e * (p - self.p1).dot(e)
37 }
38 pub fn reflection(&self, p: Complex<T>) -> Complex<T> {
39 let d = self.projection(p) - p;
40 p + d + d
41 }
42 pub fn distance_point(&self, p: Complex<T>) -> T {
43 (p / self.dir().unit()).re
44 }
45}
46
47#[derive(Clone, Debug, PartialEq)]
48pub struct LineSegment<T> {
49 p1: Complex<T>,
50 p2: Complex<T>,
51}
52impl<T> LineSegment<T> {
53 pub fn new(p1: Complex<T>, p2: Complex<T>) -> Self {
54 LineSegment { p1, p2 }
55 }
56}
57impl<T> LineSegment<T>
58where
59 T: Ccwable,
60{
61 pub fn dir(&self) -> Complex<T> {
62 self.p2 - self.p1
63 }
64 pub fn ccw(&self, p: Complex<T>) -> Ccw {
65 Ccw::ccw(self.p1, self.p2, p)
66 }
More examples
crates/competitive/src/geometry/polygon.rs (line 12)
3pub fn convex_hull<T>(mut ps: Vec<Complex<T>>) -> Vec<Complex<T>>
4where
5 T: PartialOrd + Ccwable,
6{
7 ps.sort_by(|p1, p2| ((p1.re, p1.im).partial_cmp(&(p2.re, p2.im)).unwrap()));
8 let mut qs = Vec::new();
9 for &p in ps.iter().chain(ps.iter().rev().skip(1)) {
10 while {
11 let k = qs.len();
12 k > 1 && matches!(Ccw::ccw(qs[k - 2], qs[k - 1], p), Ccw::Clockwise)
13 } {
14 qs.pop();
15 }
16 qs.push(p);
17 }
18 qs.pop();
19 qs
20}
pub fn ccw_open<T>(a: Complex<T>, b: Complex<T>, c: Complex<T>) -> Selfwhere
T: Ccwable,
Trait Implementations§
Source§impl Ord for Ccw
impl Ord for Ccw
Source§impl PartialOrd for Ccw
impl PartialOrd for Ccw
impl Copy for Ccw
impl Eq for Ccw
impl StructuralPartialEq for Ccw
Auto Trait Implementations§
impl Freeze for Ccw
impl RefUnwindSafe for Ccw
impl Send for Ccw
impl Sync for Ccw
impl Unpin for Ccw
impl UnwindSafe for Ccw
Blanket Implementations§
Source§impl<T> AsTotalOrd for Twhere
T: PartialOrd,
impl<T> AsTotalOrd for Twhere
T: PartialOrd,
fn as_total_ord(&self) -> TotalOrd<&T>
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