Skip to content

Commit

Permalink
Merge pull request #7 from kitt159/dimensions
Browse files Browse the repository at this point in the history
Generalize dimensions
  • Loading branch information
hmeyer authored Sep 16, 2024
2 parents 2d2ca54 + 2723a7b commit 18eb557
Show file tree
Hide file tree
Showing 3 changed files with 283 additions and 222 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ version = "0.14.1"
authors = ["Henning Meyer <[email protected]>"]
edition = "2021"

description = "Managing axis aligned 3d Bounding Boxes."
description = "Managing axis aligned Bounding Boxes."
repository = "https://github.com/hmeyer/bbox"
readme = "README.md"
keywords = ["boundingbox", "3d", "csg", "union", "intersection"]
keywords = ["boundingbox", "csg", "union", "intersection"]
license = "MIT"

[lib]
Expand Down
50 changes: 31 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,49 +6,61 @@
[![Downloads](https://img.shields.io/crates/d/bbox.svg)](#downloads)


bbox is crate for managing axis aligned 3d Bounding Boxes.
bbox is crate for managing axis aligned Bounding Boxes.
Bounding Boxes can be created, dilated, transformed and joined with other Bounding Boxes using
CSG operations.
Finally you can test whether or not a Bounding Box contains some point and what approximate
distance a Point has to the Box.

# Examples

Intersect two Bounding Boxes
Insert points into a Bounding Box:

```rust
use nalgebra as na;
let bbox1 = bbox::BoundingBox::<f64>::new(na::Point3::new(0., 0., 0.),
na::Point3::new(1., 2., 3.));
let bbox2 = bbox::BoundingBox::<f64>::new(na::Point3::new(-1., -2., -3.),
na::Point3::new(3., 2., 1.));
let intersection = bbox1.intersection(&bbox2);
let mut bbox = bbox::BoundingBox::neg_infinity();
bbox.insert(&na::Point::from([0., 0., 0.]));
bbox.insert(&na::Point::from([1., 2., 3.]));

// or insert multiple points at once

let bbox = bbox::BoundingBox::from([na::Point::from([0., 0., 0.]),
na::Point::from([1., 2., 3.])]);
```
Intersect two Bounding Boxes:

```rust
use nalgebra as na;
let bbox1 = bbox::BoundingBox::new(&na::Point::from([0., 0., 0.]),
&na::Point::from([1., 2., 3.]));
let bbox2 = bbox::BoundingBox::new(&na::Point::from([-1., -2., -3.]),
&na::Point::from([3., 2., 1.]));
let intersection = bbox1.intersection(&bbox2);
```
Rotate a Bounding Box:

```rust
use nalgebra as na;
let rotation = na::Rotation::from_euler_angles(10., 11., 12.).to_homogeneous();
let bbox = bbox::BoundingBox::<f64>::new(na::Point3::new(0., 0., 0.),
na::Point3::new(1., 2., 3.));
let rotated_box = bbox.transform(&rotation);
let rotation = na::Rotation::from_euler_angles(10., 11., 12.);
let bbox = bbox::BoundingBox::new(&na::Point::from([0., 0., 0.]),
&na::Point::from([1., 2., 3.]));
let rotated_box = bbox.transform(&rotation.to_homogeneous());
```
Is a point contained in the Box?

```rust
use nalgebra as na;
let bbox = bbox::BoundingBox::<f64>::new(na::Point3::new(0., 0., 0.),
na::Point3::new(1., 2., 3.));
let result = bbox.contains(na::Point3::new(1., 1., 1.));
let bbox = bbox::BoundingBox::new(&na::Point::from([0., 0., 0.]),
&na::Point::from([1., 2., 3.]));
let result = bbox.contains(&na::Point::from([1., 1., 1.]));
```
Calculate approximate distance of a point to the Box:

```rust
use nalgebra as na;
let bbox = bbox::BoundingBox::<f64>::new(na::Point3::new(0., 0., 0.),
na::Point3::new(1., 2., 3.));
let distance = bbox.distance(na::Point3::new(1., 1., 1.));
let bbox = bbox::BoundingBox::new(&na::Point::from([0., 0., 0.]),
&na::Point::from([1., 2., 3.]));
let distance = bbox.distance(&na::Point::from([1., 1., 1.]));
```

## Cargo Features

* `mint` - Enable interoperation with other math libraries through the
Expand Down
Loading

0 comments on commit 18eb557

Please sign in to comment.