diff --git a/README.md b/README.md index 95f58b0..1797efe 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ A rewrite of the original CAD package [`sdfx`](https://github.com/deadsy/sdfx) for generating 2D and 3D geometry using [Go](https://go.dev/). ## Highlights +* GUI with real-time rendering using [sdf3ui](https://github.com/soypat/sdf3ui). * 3d and 2d objects modelled with signed distance functions (SDFs). * Minimal and idiomatic API. * Render objects as triangles or save to STL, 3MF(experimental) file format. diff --git a/internal/d3/box.go b/internal/d3/box.go index a0b5344..fa99274 100644 --- a/internal/d3/box.go +++ b/internal/d3/box.go @@ -16,6 +16,14 @@ func NewBox(center, size r3.Vec) Box { return Box{Min: r3.Sub(center, half), Max: r3.Add(center, half)} } +// CenteredBox creates a Box with a given center and size. +// Negative components of size will be interpreted as zero. +func CenteredBox(center, size r3.Vec) Box { + size = MaxElem(size, r3.Vec{}) // set negative values to zero. + half := r3.Scale(0.5, size) + return Box{Min: r3.Sub(center, half), Max: r3.Add(center, half)} +} + // Equals test the equality of 3d boxes. func (a Box) Equals(b Box, tol float64) bool { return EqualWithin(a.Min, b.Min, tol) && EqualWithin(a.Max, b.Max, tol)