Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generalize dimensions #7

Merged
merged 17 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading