| 1 | //! Implements the Cohen-Sutherland line clipping algorithm. |
| 2 | //! |
| 3 | //! Returns the clipped line if the original line intersects the clipping window, or `None` if the |
| 4 | //! original line is completely outside the clipping window. |
| 5 | //! |
| 6 | //! Reference: [Cohen-Sutherland algorithm](https://en.wikipedia.org/wiki/Cohen%E2%80%93Sutherland_algorithm) |
| 7 | //! |
| 8 | //! The Cohen-Sutherland algorithm is a line clipping algorithm that divides the 2D plane into 9 |
| 9 | //! regions and then determines the region in which the line lies. If the line lies completely |
| 10 | //! outside the clipping window, it is rejected. If the line lies completely inside the clipping |
| 11 | //! window, it is accepted. If the line lies partially inside the clipping window, it is clipped. |
| 12 | //! |
| 13 | //! The regions are defined as follows: |
| 14 | //! |
| 15 | //! ```plain |
| 16 | //! 1001 | 1000 | 1010 |
| 17 | //! -----|------|----- |
| 18 | //! 0001 | 0000 | 0010 |
| 19 | //! -----|------|----- |
| 20 | //! 0101 | 0100 | 0110 |
| 21 | //! ``` |
| 22 | //! |
| 23 | //! The algorithm works as follows: |
| 24 | //! |
| 25 | //! 1. Determine the region in which the line's starting point lies. |
| 26 | //! 2. Determine the region in which the line's ending point lies. |
| 27 | //! 3. If both points lie in region 0000, the line is completely inside the clipping window and |
| 28 | //! should be accepted. |
| 29 | //! 4. If both points lie in the same region that is not 0000, the line is completely outside the |
| 30 | //! clipping window and should be rejected. |
| 31 | //! 5. If the points lie in different regions, the line is partially inside the clipping window and |
| 32 | //! should be clipped. |
| 33 | //! 6. Clip the line using the Cohen-Sutherland algorithm. |
| 34 | //! 7. Repeat the process for the clipped line. |
| 35 | //! |
| 36 | //! The Cohen-Sutherland algorithm is commonly used in computer graphics to clip lines against a |
| 37 | //! rectangular window. |
| 38 | //! |
| 39 | //! # Examples |
| 40 | //! |
| 41 | //! ``` |
| 42 | //! use line_clipping::cohen_sutherland::clip_line; |
| 43 | //! use line_clipping::{LineSegment, Point, Window}; |
| 44 | //! |
| 45 | //! let line = LineSegment::new(Point::new(-10.0, -10.0), Point::new(20.0, 20.0)); |
| 46 | //! let window = Window::new(0.0, 10.0, 0.0, 10.0); |
| 47 | //! let clipped_line = clip_line(line, window); |
| 48 | //! ``` |
| 49 | use bitflagsrust-analyzer cargo bitflags 2.10.0 crate/::bitflagsrust-analyzer cargo bitflags 2.10.0 bitflags!; |
| 50 | |
| 51 | use craterust-analyzer cargo line-clipping 0.3.5 crate/::{LineSegmentrust-analyzer cargo line-clipping 0.3.5 LineSegment#, Pointrust-analyzer cargo line-clipping 0.3.5 Point#, Windowrust-analyzer cargo line-clipping 0.3.5 Window#}; |
| 52 | |
| 53 | /// Clips a line segment against a rectangular window using the Cohen-Sutherland algorithm. |
| 54 | /// |
| 55 | /// See the [module-level documentation](crate::cohen_sutherland) for more details on the algorithm. |
| 56 | /// |
| 57 | /// # Examples |
| 58 | /// |
| 59 | /// ``` |
| 60 | /// use line_clipping::cohen_sutherland::clip_line; |
| 61 | /// use line_clipping::{LineSegment, Point, Window}; |
| 62 | /// |
| 63 | /// let line = LineSegment::new(Point::new(-10.0, -10.0), Point::new(20.0, 20.0)); |
| 64 | /// let window = Window::new(0.0, 10.0, 0.0, 10.0); |
| 65 | /// let clipped_line = clip_line(line, window); |
| 66 | /// ``` |
| 67 | #[must_use] |
| 68 | pub fn clip_linerust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/clip_line().(mut line: LineSegmentrust-analyzer cargo line-clipping 0.3.5 LineSegment#, window: Windowrust-analyzer cargo line-clipping 0.3.5 Window#) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<LineSegmentrust-analyzer cargo line-clipping 0.3.5 LineSegment#> { |
| 69 | let mut region_1 = Regionrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/Region#::from_pointrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/impl#[Region]from_point().(line.p1rust-analyzer cargo line-clipping 0.3.5 LineSegment#p1., window); |
| 70 | let mut region_2 = Regionrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/Region#::from_pointrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/impl#[Region]from_point().(line.p2rust-analyzer cargo line-clipping 0.3.5 LineSegment#p2., window); |
| 71 | |
| 72 | while region_1.is_outsiderust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/impl#[Region]is_outside().() || region_2.is_outsiderust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/impl#[Region]is_outside().() { |
| 73 | if region_1.intersectsrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/impl#[Region]intersects().(region_2) { |
| 74 | // The line is completely outside the clipping window. |
| 75 | return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#; |
| 76 | } |
| 77 | if region_1.is_outsiderust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/impl#[Region]is_outside().() { |
| 78 | line.p1rust-analyzer cargo line-clipping 0.3.5 LineSegment#p1. = calculate_intersectionrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/calculate_intersection().(line.p1rust-analyzer cargo line-clipping 0.3.5 LineSegment#p1., line.p2rust-analyzer cargo line-clipping 0.3.5 LineSegment#p2., region_1, window); |
| 79 | region_1 = Regionrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/Region#::from_pointrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/impl#[Region]from_point().(line.p1rust-analyzer cargo line-clipping 0.3.5 LineSegment#p1., window); |
| 80 | } else { |
| 81 | line.p2rust-analyzer cargo line-clipping 0.3.5 LineSegment#p2. = calculate_intersectionrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/calculate_intersection().(line.p2rust-analyzer cargo line-clipping 0.3.5 LineSegment#p2., line.p1rust-analyzer cargo line-clipping 0.3.5 LineSegment#p1., region_2, window); |
| 82 | region_2 = Regionrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/Region#::from_pointrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/impl#[Region]from_point().(line.p2rust-analyzer cargo line-clipping 0.3.5 LineSegment#p2., window); |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(line) |
| 87 | } |
| 88 | |
| 89 | fn calculate_intersectionrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/calculate_intersection().(p1: Pointrust-analyzer cargo line-clipping 0.3.5 Point#, p2: Pointrust-analyzer cargo line-clipping 0.3.5 Point#, region: Regionrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/Region#, window: Windowrust-analyzer cargo line-clipping 0.3.5 Window#) -> Pointrust-analyzer cargo line-clipping 0.3.5 Point# { |
| 90 | let dx = p2.xrust-analyzer cargo line-clipping 0.3.5 Point#x. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Sub<Self>`]sub().p1.xrust-analyzer cargo line-clipping 0.3.5 Point#x.; |
| 91 | let dy = p2.yrust-analyzer cargo line-clipping 0.3.5 Point#y. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Sub<Self>`]sub().p1.yrust-analyzer cargo line-clipping 0.3.5 Point#y.; |
| 92 | if region.containsrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/impl#[Region]contains().(Regionrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/Region#::LEFTrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/impl#[Region]LEFT.) { |
| 93 | let y = p1.yrust-analyzer cargo line-clipping 0.3.5 Point#y. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Add<Self>`]add().(window.x_minrust-analyzer cargo line-clipping 0.3.5 Window#x_min. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Sub<Self>`]sub().p1.xrust-analyzer cargo line-clipping 0.3.5 Point#x.) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Mul<Self>`]mul().dy rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Div<Self>`]div().dx; |
| 94 | Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(window.x_minrust-analyzer cargo line-clipping 0.3.5 Window#x_min., y) |
| 95 | } else if region.containsrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/impl#[Region]contains().(Regionrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/Region#::RIGHTrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/impl#[Region]RIGHT.) { |
| 96 | let y = p1.yrust-analyzer cargo line-clipping 0.3.5 Point#y. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Add<Self>`]add().(window.x_maxrust-analyzer cargo line-clipping 0.3.5 Window#x_max. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Sub<Self>`]sub().p1.xrust-analyzer cargo line-clipping 0.3.5 Point#x.) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Mul<Self>`]mul().dy rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Div<Self>`]div().dx; |
| 97 | Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(window.x_maxrust-analyzer cargo line-clipping 0.3.5 Window#x_max., y) |
| 98 | } else if region.containsrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/impl#[Region]contains().(Regionrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/Region#::BOTTOMrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/impl#[Region]BOTTOM.) { |
| 99 | let x = p1.xrust-analyzer cargo line-clipping 0.3.5 Point#x. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Add<Self>`]add().(window.y_minrust-analyzer cargo line-clipping 0.3.5 Window#y_min. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Sub<Self>`]sub().p1.yrust-analyzer cargo line-clipping 0.3.5 Point#y.) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Mul<Self>`]mul().dx rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Div<Self>`]div().dy; |
| 100 | Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(x, window.y_minrust-analyzer cargo line-clipping 0.3.5 Window#y_min.) |
| 101 | } else if region.containsrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/impl#[Region]contains().(Regionrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/Region#::TOPrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/impl#[Region]TOP.) { |
| 102 | let x = p1.xrust-analyzer cargo line-clipping 0.3.5 Point#x. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Add<Self>`]add().(window.y_maxrust-analyzer cargo line-clipping 0.3.5 Window#y_max. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Sub<Self>`]sub().p1.yrust-analyzer cargo line-clipping 0.3.5 Point#y.) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Mul<Self>`]mul().dx rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Div<Self>`]div().dy; |
| 103 | Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(x, window.y_maxrust-analyzer cargo line-clipping 0.3.5 Window#y_max.) |
| 104 | } else { |
| 105 | p1 |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | bitflagsrust-analyzer cargo bitflags 2.10.0 bitflags!! { |
| 110 | /// Represents the regions in the Cohen-Sutherland algorithm. |
| 111 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:)] |
| 112 | struct Regionrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/Region#: u8 { |
| 113 | const LEFTrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/impl#[Region]LEFT. = 0b0001; |
| 114 | const RIGHTrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/impl#[Region]RIGHT. = 0b0010; |
| 115 | const BOTTOMrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/impl#[Region]BOTTOM. = 0b0100; |
| 116 | const TOPrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/impl#[Region]TOP. = 0b1000; |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | impl Regionrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/Region# { |
| 121 | const fn is_outsiderust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/impl#[Region]is_outside().(self) -> bool { |
| 122 | !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.is_emptyrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/impl#[Region]is_empty().() |
| 123 | } |
| 124 | |
| 125 | /// Determines the region in which a point lies. |
| 126 | fn from_pointrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/impl#[Region]from_point().(point: Pointrust-analyzer cargo line-clipping 0.3.5 Point#, window: Windowrust-analyzer cargo line-clipping 0.3.5 Window#) -> Selfrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/impl#[Region] { |
| 127 | let mut region = Selfrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/impl#[Region]::emptyrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/impl#[Region]empty().(); |
| 128 | if point.xrust-analyzer cargo line-clipping 0.3.5 Point#x. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[f64][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[f64][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[f64][`PartialOrd<Self>`]lt().window.x_minrust-analyzer cargo line-clipping 0.3.5 Window#x_min. { |
| 129 | region rust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/impl#[Region][`BitOrAssign<Self>`]bitor_assign().|=rust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/impl#[Region][`BitOrAssign<Self>`]bitor_assign(). rust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/impl#[Region][`BitOrAssign<Self>`]bitor_assign().Selfrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/impl#[Region]::LEFTrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/impl#[Region]LEFT.; |
| 130 | } else if point.xrust-analyzer cargo line-clipping 0.3.5 Point#x. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[f64][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[f64][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[f64][`PartialOrd<Self>`]gt().window.x_maxrust-analyzer cargo line-clipping 0.3.5 Window#x_max. { |
| 131 | region rust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/impl#[Region][`BitOrAssign<Self>`]bitor_assign().|=rust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/impl#[Region][`BitOrAssign<Self>`]bitor_assign(). rust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/impl#[Region][`BitOrAssign<Self>`]bitor_assign().Selfrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/impl#[Region]::RIGHTrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/impl#[Region]RIGHT.; |
| 132 | } |
| 133 | if point.yrust-analyzer cargo line-clipping 0.3.5 Point#y. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[f64][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[f64][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[f64][`PartialOrd<Self>`]lt().window.y_minrust-analyzer cargo line-clipping 0.3.5 Window#y_min. { |
| 134 | region rust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/impl#[Region][`BitOrAssign<Self>`]bitor_assign().|=rust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/impl#[Region][`BitOrAssign<Self>`]bitor_assign(). rust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/impl#[Region][`BitOrAssign<Self>`]bitor_assign().Selfrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/impl#[Region]::BOTTOMrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/impl#[Region]BOTTOM.; |
| 135 | } else if point.yrust-analyzer cargo line-clipping 0.3.5 Point#y. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[f64][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[f64][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[f64][`PartialOrd<Self>`]gt().window.y_maxrust-analyzer cargo line-clipping 0.3.5 Window#y_max. { |
| 136 | region rust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/impl#[Region][`BitOrAssign<Self>`]bitor_assign().|=rust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/impl#[Region][`BitOrAssign<Self>`]bitor_assign(). rust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/impl#[Region][`BitOrAssign<Self>`]bitor_assign().Selfrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/impl#[Region]::TOPrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/impl#[Region]TOP.; |
| 137 | } |
| 138 | region |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | #[cfg(test)] |
| 143 | mod testsrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/tests/ { |
| 144 | use rstestrust-analyzer cargo rstest 0.17.0 crate/::rstestrust-analyzer cargo rstest_macros 0.17.0 rstest:; |
| 145 | |
| 146 | use superrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/::*; |
| 147 | |
| 148 | #[rstestrust-analyzer cargo rstest_macros 0.17.0 rstest:] |
| 149 | #[case::left(Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().2.0, 0.0), Regionrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/Region#::LEFTrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/impl#[Region]LEFT.)] |
| 150 | #[case::right(Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(2.0, 0.0), Regionrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/Region#::RIGHTrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/impl#[Region]RIGHT.)] |
| 151 | #[case::top(Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(0.0, 2.0), Regionrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/Region#::TOPrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/impl#[Region]TOP.)] |
| 152 | #[case::bottom(Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(0.0, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().2.0), Regionrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/Region#::BOTTOMrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/impl#[Region]BOTTOM.)] |
| 153 | #[case::top_left(Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().2.0, 2.0), Regionrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/Region#::LEFTrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/impl#[Region]LEFT. |rust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/impl#[Region][`BitOr<Self>`]bitor(). Regionrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/Region#::TOPrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/impl#[Region]TOP.)] |
| 154 | #[case::top_right(Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(2.0, 2.0), Regionrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/Region#::RIGHTrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/impl#[Region]RIGHT. |rust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/impl#[Region][`BitOr<Self>`]bitor(). Regionrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/Region#::TOPrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/impl#[Region]TOP.)] |
| 155 | #[case::bottom_left(Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().2.0, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().2.0), Regionrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/Region#::LEFTrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/impl#[Region]LEFT. |rust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/impl#[Region][`BitOr<Self>`]bitor(). Regionrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/Region#::BOTTOMrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/impl#[Region]BOTTOM.)] |
| 156 | #[case::bottom_right(Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(2.0, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().2.0), Regionrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/Region#::RIGHTrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/impl#[Region]RIGHT. |rust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/impl#[Region][`BitOr<Self>`]bitor(). Regionrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/Region#::BOTTOMrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/impl#[Region]BOTTOM.)] |
| 157 | #[case::inside(Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(0.0, 0.0), Regionrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/Region#::emptyrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/impl#[Region]empty().())] |
| 158 | #[case::inside_left(Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().1.0, 0.0), Regionrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/Region#::emptyrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/impl#[Region]empty().())] |
| 159 | #[case::inside_right(Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(1.0, 0.0), Regionrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/Region#::emptyrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/impl#[Region]empty().())] |
| 160 | #[case::inside_top(Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(0.0, 1.0), Regionrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/Region#::emptyrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/impl#[Region]empty().())] |
| 161 | #[case::inside_bottom(Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(0.0, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().1.0), Regionrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/Region#::emptyrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/impl#[Region]empty().())] |
| 162 | #[case::inside_top_left(Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().1.0, 1.0), Regionrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/Region#::emptyrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/impl#[Region]empty().())] |
| 163 | #[case::inside_top_right(Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(1.0, 1.0), Regionrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/Region#::emptyrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/impl#[Region]empty().())] |
| 164 | #[case::inside_bottom_left(Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().1.0, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().1.0), Regionrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/Region#::emptyrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/impl#[Region]empty().())] |
| 165 | #[case::inside_bottom_right(Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(1.0, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().1.0), Regionrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/Region#::emptyrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/impl#[Region]empty().())] |
| 166 | fn region_from_pointrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/tests/region_from_point().(#[case] point: Pointrust-analyzer cargo line-clipping 0.3.5 Point#, #[case] expected: Regionrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/Region#) { |
| 167 | let window = Windowrust-analyzer cargo line-clipping 0.3.5 Window#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Window]new().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().1.0, 1.0, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().1.0, 1.0); |
| 168 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(Regionrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/Region#::from_pointrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/impl#[Region]from_point().(point, window), expected); |
| 169 | } |
| 170 | |
| 171 | #[rstestrust-analyzer cargo rstest_macros 0.17.0 rstest:] |
| 172 | #[case::top_left(Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().2.0, 2.0), Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().3.0, 3.0))] |
| 173 | #[case::top_right(Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(2.0, 2.0), Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(3.0, 3.0))] |
| 174 | #[case::bottom_left(Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().2.0, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().2.0), Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().3.0, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().3.0))] |
| 175 | #[case::bottom_right(Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(2.0, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().2.0), Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(3.0, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().3.0))] |
| 176 | #[case::left(Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().2.0, 0.0), Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().3.0, 0.0))] |
| 177 | #[case::right(Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(2.0, 0.0), Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(3.0, 0.0))] |
| 178 | #[case::top(Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(0.0, 2.0), Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(0.0, 2.0))] |
| 179 | #[case::bottom(Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(0.0, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().2.0), Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(0.0, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().3.0))] |
| 180 | fn outsiderust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/tests/outside().(#[case] p1: Pointrust-analyzer cargo line-clipping 0.3.5 Point#, #[case] p2: Pointrust-analyzer cargo line-clipping 0.3.5 Point#) { |
| 181 | let line = LineSegmentrust-analyzer cargo line-clipping 0.3.5 LineSegment#::newrust-analyzer cargo line-clipping 0.3.5 impl#[LineSegment]new().(p1, p2); |
| 182 | let window = Windowrust-analyzer cargo line-clipping 0.3.5 Window#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Window]new().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().1.0, 1.0, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().1.0, 1.0); |
| 183 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(clip_linerust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/clip_line().(line, window), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 184 | } |
| 185 | |
| 186 | #[rstestrust-analyzer cargo rstest_macros 0.17.0 rstest:] |
| 187 | #[case::left_border(Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().1.0, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().1.0), Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().1.0, 1.0))] |
| 188 | #[case::right_border(Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(1.0, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().1.0), Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(1.0, 1.0))] |
| 189 | #[case::top_border(Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().1.0, 1.0), Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(1.0, 1.0))] |
| 190 | #[case::bottom_border(Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().1.0, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().1.0), Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(1.0, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().1.0))] |
| 191 | #[case::corners_up(Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().1.0, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().1.0), Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(1.0, 1.0))] |
| 192 | #[case::corners_down(Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().1.0, 1.0), Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(1.0, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().1.0))] |
| 193 | #[case::horizontal(Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().0.5, 0.0), Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(0.5, 0.0))] |
| 194 | #[case::vertical(Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(0.0, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().0.5), Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(0.0, 0.5))] |
| 195 | #[case::diagonal_up(Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().0.5, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().0.5), Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(0.5, 0.5))] |
| 196 | #[case::diagonal_down(Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().0.5, 0.5), Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(0.5, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().0.5))] |
| 197 | fn insiderust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/tests/inside().(#[case] p1: Pointrust-analyzer cargo line-clipping 0.3.5 Point#, #[case] p2: Pointrust-analyzer cargo line-clipping 0.3.5 Point#) { |
| 198 | let line = LineSegmentrust-analyzer cargo line-clipping 0.3.5 LineSegment#::newrust-analyzer cargo line-clipping 0.3.5 impl#[LineSegment]new().(p1, p2); |
| 199 | let window = Windowrust-analyzer cargo line-clipping 0.3.5 Window#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Window]new().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().1.0, 1.0, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().1.0, 1.0); |
| 200 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(clip_linerust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/clip_line().(line, window), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(line)); |
| 201 | } |
| 202 | |
| 203 | /// Test cases for lines that point to the origin and intersect the window. The cases move |
| 204 | /// clockwise around the window. This makes sure that we test the intersection of the line with |
| 205 | /// the window from all regions. |
| 206 | /// |
| 207 | /// ``` |
| 208 | /// 1 2 3 4 5 6 7 8 1 |
| 209 | /// 8 2 |
| 210 | /// 7 ┌───────┐ 3 |
| 211 | /// 6 │ │ 4 |
| 212 | /// 5 │ . │ 5 |
| 213 | /// 4 │ │ 6 |
| 214 | /// 3 └───────┘ 7 |
| 215 | /// 2 8 |
| 216 | /// 1 8 7 6 5 4 3 2 1 |
| 217 | /// ``` |
| 218 | #[rstestrust-analyzer cargo rstest_macros 0.17.0 rstest:] |
| 219 | #[case::top_1(Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().2.0, 2.0), Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().1.0, 1.0))] |
| 220 | #[case::top_2(Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().1.5, 2.0), Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().0.75, 1.0))] |
| 221 | #[case::top_3(Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().1.0, 2.0), Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().0.5, 1.0))] |
| 222 | #[case::top_4(Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().0.5, 2.0), Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().0.25, 1.0))] |
| 223 | #[case::top_5(Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(0.0, 2.0), Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(0.0, 1.0))] |
| 224 | #[case::top_6(Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(0.5, 2.0), Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(0.25, 1.0))] |
| 225 | #[case::top_7(Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(1.0, 2.0), Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(0.5, 1.0))] |
| 226 | #[case::top_8(Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(1.5, 2.0), Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(0.75, 1.0))] |
| 227 | #[case::right_1(Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(2.0, 2.0), Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(1.0, 1.0))] |
| 228 | #[case::right_2(Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(2.0, 1.5), Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(1.0, 0.75))] |
| 229 | #[case::right_3(Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(2.0, 1.0), Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(1.0, 0.5))] |
| 230 | #[case::right_4(Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(2.0, 0.5), Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(1.0, 0.25))] |
| 231 | #[case::right_5(Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(2.0, 0.0), Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(1.0, 0.0))] |
| 232 | #[case::right_6(Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(2.0, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().0.5), Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(1.0, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().0.25))] |
| 233 | #[case::right_7(Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(2.0, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().1.0), Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(1.0, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().0.5))] |
| 234 | #[case::right_8(Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(2.0, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().1.5), Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(1.0, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().0.75))] |
| 235 | #[case::bottom_1(Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(2.0, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().2.0), Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(1.0, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().1.0))] |
| 236 | #[case::bottom_2(Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(1.5, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().2.0), Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(0.75, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().1.0))] |
| 237 | #[case::bottom_3(Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(1.0, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().2.0), Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(0.5, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().1.0))] |
| 238 | #[case::bottom_4(Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(0.5, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().2.0), Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(0.25, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().1.0))] |
| 239 | #[case::bottom_5(Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(0.0, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().2.0), Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(0.0, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().1.0))] |
| 240 | #[case::bottom_6(Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().0.5, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().2.0), Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().0.25, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().1.0))] |
| 241 | #[case::bottom_7(Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().1.0, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().2.0), Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().0.5, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().1.0))] |
| 242 | #[case::bottom_8(Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().1.5, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().2.0), Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().0.75, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().1.0))] |
| 243 | #[case::left_1(Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().2.0, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().2.0), Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().1.0, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().1.0))] |
| 244 | #[case::left_2(Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().2.0, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().1.5), Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().1.0, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().0.75))] |
| 245 | #[case::left_3(Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().2.0, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().1.0), Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().1.0, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().0.5))] |
| 246 | #[case::left_4(Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().2.0, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().0.5), Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().1.0, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().0.25))] |
| 247 | #[case::left_5(Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().2.0, 0.0), Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().1.0, 0.0))] |
| 248 | #[case::left_6(Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().2.0, 0.5), Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().1.0, 0.25))] |
| 249 | #[case::left_7(Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().2.0, 1.0), Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().1.0, 0.5))] |
| 250 | #[case::left_8(Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().2.0, 1.5), Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().1.0, 0.75))] |
| 251 | fn one_intersectionrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/tests/one_intersection().(#[case] p1: Pointrust-analyzer cargo line-clipping 0.3.5 Point#, #[case] expected: Pointrust-analyzer cargo line-clipping 0.3.5 Point#) { |
| 252 | let line = LineSegmentrust-analyzer cargo line-clipping 0.3.5 LineSegment#::newrust-analyzer cargo line-clipping 0.3.5 impl#[LineSegment]new().(p1, Pointrust-analyzer cargo line-clipping 0.3.5 Point#::ORIGINrust-analyzer cargo line-clipping 0.3.5 impl#[Point]ORIGIN.); |
| 253 | let window = Windowrust-analyzer cargo line-clipping 0.3.5 Window#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Window]new().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().1.0, 1.0, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().1.0, 1.0); |
| 254 | let expected = LineSegmentrust-analyzer cargo line-clipping 0.3.5 LineSegment#::newrust-analyzer cargo line-clipping 0.3.5 impl#[LineSegment]new().(expected, Pointrust-analyzer cargo line-clipping 0.3.5 Point#::ORIGINrust-analyzer cargo line-clipping 0.3.5 impl#[Point]ORIGIN.); |
| 255 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(clip_linerust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/clip_line().(line, window), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(expected)); |
| 256 | } |
| 257 | |
| 258 | const Arust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/tests/A.: Pointrust-analyzer cargo line-clipping 0.3.5 Point# = Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().2.0, 2.0); |
| 259 | const Brust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/tests/B.: Pointrust-analyzer cargo line-clipping 0.3.5 Point# = Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(0.0, 2.0); |
| 260 | const Crust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/tests/C.: Pointrust-analyzer cargo line-clipping 0.3.5 Point# = Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(2.0, 2.0); |
| 261 | const Drust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/tests/D.: Pointrust-analyzer cargo line-clipping 0.3.5 Point# = Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(2.0, 0.0); |
| 262 | const Erust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/tests/E.: Pointrust-analyzer cargo line-clipping 0.3.5 Point# = Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(2.0, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().2.0); |
| 263 | const Frust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/tests/F.: Pointrust-analyzer cargo line-clipping 0.3.5 Point# = Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(0.0, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().2.0); |
| 264 | const Grust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/tests/G.: Pointrust-analyzer cargo line-clipping 0.3.5 Point# = Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().2.0, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().2.0); |
| 265 | const Hrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/tests/H.: Pointrust-analyzer cargo line-clipping 0.3.5 Point# = Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().2.0, 0.0); |
| 266 | |
| 267 | /// Test cases for lines that intersect the window twice. The cases move clockwise around the |
| 268 | /// window. This makes sure that we test every region to each other region. |
| 269 | /// ``` |
| 270 | /// A B C |
| 271 | /// |
| 272 | /// ┌───────┐ |
| 273 | /// │ │ |
| 274 | /// H │ . │ D |
| 275 | /// │ │ |
| 276 | /// └───────┘ |
| 277 | /// |
| 278 | /// G F E |
| 279 | /// ``` |
| 280 | #[rstestrust-analyzer cargo rstest_macros 0.17.0 rstest:] |
| 281 | #[case::a_to_d(Arust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/tests/A., Drust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/tests/D., Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(0.0, 1.0), Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(1.0, 0.5))] |
| 282 | #[case::a_to_e(Arust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/tests/A., Erust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/tests/E., Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().1.0, 1.0), Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(1.0, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().1.0))] |
| 283 | #[case::a_to_k(Arust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/tests/A., Frust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/tests/F., Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().1.0, 0.0), Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().0.5, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().1.0))] |
| 284 | #[case::b_to_d(Brust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/tests/B., Drust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/tests/D., Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(1.0, 1.0), Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(1.0, 1.0))] |
| 285 | #[case::b_to_e(Brust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/tests/B., Erust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/tests/E., Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(0.5, 1.0), Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(1.0, 0.0))] |
| 286 | #[case::b_to_f(Brust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/tests/B., Frust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/tests/F., Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(0.0, 1.0), Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(0.0, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().1.0))] |
| 287 | #[case::b_to_g(Brust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/tests/B., Grust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/tests/G., Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().0.5, 1.0), Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().1.0, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().0.0))] |
| 288 | #[case::b_to_h(Brust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/tests/B., Hrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/tests/H., Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().1.0, 1.0), Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().1.0, 1.0))] |
| 289 | #[case::c_to_f(Crust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/tests/C., Frust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/tests/F., Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(1.0, 0.0), Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(0.5, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().1.0))] |
| 290 | #[case::c_to_g(Crust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/tests/C., Grust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/tests/G., Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(1.0, 1.0), Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().1.0, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().1.0))] |
| 291 | #[case::c_to_h(Crust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/tests/C., Hrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/tests/H., Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(0.0, 1.0), Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().1.0, 0.5))] |
| 292 | #[case::d_to_f(Drust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/tests/D., Frust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/tests/F., Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(1.0, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().1.0), Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(1.0, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().1.0))] |
| 293 | #[case::d_to_g(Drust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/tests/D., Grust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/tests/G., Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(1.0, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().0.5), Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(0.0, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().1.0))] |
| 294 | #[case::d_to_h(Drust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/tests/D., Hrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/tests/H., Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(1.0, 0.0), Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().1.0, 0.0))] |
| 295 | #[case::e_to_h(Erust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/tests/E., Hrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/tests/H., Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(0.0, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().1.0), Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().1.0, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().0.5))] |
| 296 | #[case::f_to_h(Frust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/tests/F., Hrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/tests/H., Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().1.0, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().1.0), Pointrust-analyzer cargo line-clipping 0.3.5 Point#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Point]new().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().1.0, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().1.0))] |
| 297 | fn two_intersectionsrust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/tests/two_intersections().( |
| 298 | #[case] p1: Pointrust-analyzer cargo line-clipping 0.3.5 Point#, |
| 299 | #[case] p2: Pointrust-analyzer cargo line-clipping 0.3.5 Point#, |
| 300 | #[case] expected_p1: Pointrust-analyzer cargo line-clipping 0.3.5 Point#, |
| 301 | #[case] expected_p2: Pointrust-analyzer cargo line-clipping 0.3.5 Point#, |
| 302 | ) { |
| 303 | let line = LineSegmentrust-analyzer cargo line-clipping 0.3.5 LineSegment#::newrust-analyzer cargo line-clipping 0.3.5 impl#[LineSegment]new().(p1, p2); |
| 304 | let window = Windowrust-analyzer cargo line-clipping 0.3.5 Window#::newrust-analyzer cargo line-clipping 0.3.5 impl#[Window]new().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().1.0, 1.0, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().1.0, 1.0); |
| 305 | let expected = LineSegmentrust-analyzer cargo line-clipping 0.3.5 LineSegment#::newrust-analyzer cargo line-clipping 0.3.5 impl#[LineSegment]new().(expected_p1, expected_p2); |
| 306 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(clip_linerust-analyzer cargo line-clipping 0.3.5 cohen_sutherland/clip_line().(line, window).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(), expected); |
| 307 | } |
| 308 | } |