Struct advent_of_code_2021::day_22::Cuboid[−][src]

struct Cuboid {
    x_min: isize,
    x_max: isize,
    y_min: isize,
    y_max: isize,
    z_min: isize,
    z_max: isize,
}
Expand description

Represents a cuboid as its range of co-ordinates on each axis. Both values are inclusive.

Fields

x_min: isizex_max: isizey_min: isizey_max: isizez_min: isizez_max: isize

Implementations

Utility so that a Cuboid can be created on a single line (struct literals are always split into multilines by rust-fmt)

Return the Cuboid region where this and another Cuboid overlap, if they do.

If there is an overlap with the incoming Cuboid, return a list of Cuboid slices that do not that do not intersect, if any. If there is no intersection return this cube, unaffected.

E.g. in 2D do the following

-----------------          self.dff_and_split(&other);
| self          |
|   ---------   |
|   | other |   |
|   ---------   |
|               |
-----------------

----| |-------| |----      First split on the x axis creating rectangles  
| l | |       | | r |      left and right with their x bounds set to just
| e | |-------| | i |      outside the intersecting region.
| f | | other | | g |
| t | |-------| | h |
|   | |       | | t |
----| |-------| |----

      ----------
      |  top   |
----| ---------- |----     Then split on the y-axis creating rectangles   
| l |            | r |     top and bottom. Their y bounds set to just
| e | ---------- | i |     outside the intersecting region, but their x
| f | | other  | | g |     bounds are the same as the intersecting region's
| t | ---------- | h |     so that they don't overlap left and right at the
|   |            | t |     corners
----| ---------- |----
      | bottom |
      ----------

----| ---------- |----      Just return the slices from self. Other will
| l | |  top   | | r |      only be added to the next iteration if it is
| e | ---------- | i |      'on', which is done elsewhere.
| f |            | g |      
| t | ---------- | h |
|   | | bottom | | t |
----| ---------- |----

Note: Not all slices always get returned e.g. a corner intersect
just creates two slices.

                                       -----            
                                       |top|            
---------|      ----| |----      ----| -----      ----| -----                   
|  self  |      | L | |   |      | L |            | L | |top|
|   -------- => |   | |------ => |   | ------- => |   | -----
----|other |    |---| |other|    ----| |other|    ----|
    --------          |------          |------         

The above is expanded to three dimensions, but the logic is the same.

Calculates the volume of this Cuboid. Note the +1s because both limits are inclusive.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.