pub struct LineSegment<T> { /* private fields */ }
Implementations§
Source§impl<T> LineSegment<T>where
T: Ccwable,
impl<T> LineSegment<T>where
T: Ccwable,
Sourcepub fn dir(&self) -> Complex<T>
pub fn dir(&self) -> Complex<T>
Examples found in repository?
crates/competitive/src/geometry/line.rs (line 68)
67 pub fn is_parallel(&self, other: &Self) -> bool {
68 Approx(self.dir().cross(other.dir())) == Approx(T::zero())
69 }
70 pub fn is_orthogonal(&self, other: &Self) -> bool {
71 Approx(self.dir().dot(other.dir())) == Approx(T::zero())
72 }
73 pub fn intersect(&self, other: &Self) -> bool {
74 self.ccw(other.p1) as i8 * self.ccw(other.p2) as i8 <= 0
75 && other.ccw(self.p1) as i8 * other.ccw(self.p2) as i8 <= 0
76 }
77 pub fn intersect_point(&self, p: Complex<T>) -> bool {
78 self.ccw(p) == Ccw::OnSegment
79 }
80}
81impl<T> LineSegment<T>
82where
83 T: Ccwable + Float,
84{
85 pub fn projection(&self, p: Complex<T>) -> Complex<T> {
86 let e = self.dir().unit();
87 self.p1 + e * (p - self.p1).dot(e)
88 }
89 pub fn reflection(&self, p: Complex<T>) -> Complex<T> {
90 let d = self.projection(p) - p;
91 p + d + d
92 }
93 pub fn cross_point(&self, other: &Self) -> Option<Complex<T>> {
94 if self.intersect(other) {
95 let a = self.dir().cross(other.dir());
96 let b = self.dir().cross(self.p2 - other.p1);
97 if Approx(a.abs()) == Approx(T::zero()) && Approx(b.abs()) == Approx(T::zero()) {
98 Some(other.p1)
99 } else {
100 Some(other.p1 + (other.dir() * b / a))
101 }
102 } else {
103 None
104 }
105 }
pub fn is_parallel(&self, other: &Self) -> bool
pub fn is_orthogonal(&self, other: &Self) -> bool
Sourcepub fn intersect(&self, other: &Self) -> bool
pub fn intersect(&self, other: &Self) -> bool
Examples found in repository?
crates/competitive/src/geometry/line.rs (line 94)
93 pub fn cross_point(&self, other: &Self) -> Option<Complex<T>> {
94 if self.intersect(other) {
95 let a = self.dir().cross(other.dir());
96 let b = self.dir().cross(self.p2 - other.p1);
97 if Approx(a.abs()) == Approx(T::zero()) && Approx(b.abs()) == Approx(T::zero()) {
98 Some(other.p1)
99 } else {
100 Some(other.p1 + (other.dir() * b / a))
101 }
102 } else {
103 None
104 }
105 }
106 pub fn distance_point(&self, p: Complex<T>) -> T {
107 let r = self.projection(p);
108 if self.intersect_point(r) {
109 (r - p).abs()
110 } else {
111 (self.p1 - p).abs().min((self.p2 - p).abs())
112 }
113 }
114 pub fn distance(&self, other: &Self) -> T {
115 if self.intersect(other) {
116 T::zero()
117 } else {
118 let d1 = self.distance_point(other.p1);
119 let d2 = self.distance_point(other.p2);
120 let d3 = other.distance_point(self.p1);
121 let d4 = other.distance_point(self.p2);
122 d1.min(d2).min(d3).min(d4)
123 }
124 }
Sourcepub fn intersect_point(&self, p: Complex<T>) -> bool
pub fn intersect_point(&self, p: Complex<T>) -> bool
Source§impl<T> LineSegment<T>
impl<T> LineSegment<T>
Sourcepub fn projection(&self, p: Complex<T>) -> Complex<T>
pub fn projection(&self, p: Complex<T>) -> Complex<T>
Examples found in repository?
crates/competitive/src/geometry/line.rs (line 90)
89 pub fn reflection(&self, p: Complex<T>) -> Complex<T> {
90 let d = self.projection(p) - p;
91 p + d + d
92 }
93 pub fn cross_point(&self, other: &Self) -> Option<Complex<T>> {
94 if self.intersect(other) {
95 let a = self.dir().cross(other.dir());
96 let b = self.dir().cross(self.p2 - other.p1);
97 if Approx(a.abs()) == Approx(T::zero()) && Approx(b.abs()) == Approx(T::zero()) {
98 Some(other.p1)
99 } else {
100 Some(other.p1 + (other.dir() * b / a))
101 }
102 } else {
103 None
104 }
105 }
106 pub fn distance_point(&self, p: Complex<T>) -> T {
107 let r = self.projection(p);
108 if self.intersect_point(r) {
109 (r - p).abs()
110 } else {
111 (self.p1 - p).abs().min((self.p2 - p).abs())
112 }
113 }
pub fn reflection(&self, p: Complex<T>) -> Complex<T>
pub fn cross_point(&self, other: &Self) -> Option<Complex<T>>
Sourcepub fn distance_point(&self, p: Complex<T>) -> T
pub fn distance_point(&self, p: Complex<T>) -> T
pub fn distance(&self, other: &Self) -> T
Trait Implementations§
Source§impl<T: Clone> Clone for LineSegment<T>
impl<T: Clone> Clone for LineSegment<T>
Source§fn clone(&self) -> LineSegment<T>
fn clone(&self) -> LineSegment<T>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl<T: Debug> Debug for LineSegment<T>
impl<T: Debug> Debug for LineSegment<T>
Source§impl<T: PartialEq> PartialEq for LineSegment<T>
impl<T: PartialEq> PartialEq for LineSegment<T>
impl<T> StructuralPartialEq for LineSegment<T>
Auto Trait Implementations§
impl<T> Freeze for LineSegment<T>where
T: Freeze,
impl<T> RefUnwindSafe for LineSegment<T>where
T: RefUnwindSafe,
impl<T> Send for LineSegment<T>where
T: Send,
impl<T> Sync for LineSegment<T>where
T: Sync,
impl<T> Unpin for LineSegment<T>where
T: Unpin,
impl<T> UnwindSafe for LineSegment<T>where
T: UnwindSafe,
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