MCPcopy Index your code
hub / github.com/Libbum/spherical-cow

github.com/Libbum/spherical-cow @v0.1.4

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.1.4 ↗ · + Follow
92 symbols 125 edges 21 files 36 documented · 39% updated 5y ago★ 528 open issues
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Spherical Cow

A high volume fraction sphere packing library

<a href="https://crates.io/crates/spherical-cow">
    <img src="https://img.shields.io/crates/v/spherical-cow.svg" alt="Crates.io" />
</a>
│
<a href="https://docs.rs/spherical-cow/">
    <img src="https://img.shields.io/badge/api-documentation-blue.svg" alt="Docs.rs" />
</a>
│
<a href="https://travis-ci.org/Libbum/spherical-cow">
    <img src="https://travis-ci.org/Libbum/spherical-cow.svg?branch=master" alt="Travis-ci" />
</a>
│
<a href="https://codecov.io/gh/Libbum/spherical-cow">
    <img src="https://codecov.io/gh/Libbum/spherical-cow/branch/master/graph/badge.svg" alt="Codecov" />
</a>
│
<a href="https://app.fossa.io/projects/git%2Bgithub.com%2FLibbum%2Fspherical-cow?ref=badge_shield">
    <img src="https://app.fossa.io/api/projects/git%2Bgithub.com%2FLibbum%2Fspherical-cow.svg?type=shield" alt="FOSSA Status" />
</a>

Based on the advancing fronts algorithm outlined in Valera et al., Computational Particle Mechanics 2, 161 (2015).

Milk production at a dairy farm was low, so the farmer wrote to the local university, asking for help from academia. A multidisciplinary team of professors was assembled, headed by a theoretical physicist, and two weeks of intensive on-site investigation took place. The scholars then returned to the university, notebooks crammed with data, where the task of writing the report was left to the team leader. Shortly thereafter the physicist returned to the farm, saying to the farmer, "I have the solution, but it works only in the case of spherical cows in a vacuum".

Usage

Complete documentation can be found at docs.rs.

A simple example to get you packing spheres of radii (0.1..0.2) into a container sphere of radius 2.

use spherical_cow::shapes::Sphere;
use rand::distributions::Uniform;
use nalgebra::Point3;

fn main() {
    let boundary = Sphere::new(Point3::origin(), 2.0).unwrap();
    let mut sizes = Uniform::new(0.1, 0.2);

    let spheres = spherical_cow::pack_spheres(boundary, &mut sizes).unwrap();

    println!("Number of spheres: {}", spheres.len());
}

More elaborate examples can be found in the examples directory.

Output

True to its name, it is indeed possible to build a spherical cow:

spherical cow in vacuum

You can run this example yourself from show_in_cow.

Example use cases

The paper which this algorithm comes from gives two examples of real world use cases:

  1. Sphere packing a skull model to study fractures due to shocks and penetrating objects.
  2. Sphere packing a cutting tool to identify the failure / breaking points when the tool is placed under load.

The reason this library was initially written was to optimise the layout of inflatable space habitats which may one day be constructed on the Moon and Mars.

License

Licensed under the Apache License, Version 2.0 or the MIT license, at your option. These files may not be copied, modified, or distributed except according to those terms.

FOSSA Status

Deeply linked dependencies

The wayland-protocols library (released under an MIT license) is used by kiss3d and obj, both of which are only extant in the examples directory of this project (and thus are NOT a part of the library). Content therein: the file misc/server-decoration.xml, is Copyright (C) 2015 Martin Gräßlin and licensed under the GNU Lesser General Public Library, version 2.1. You can find a copy of this license at https://www.gnu.org/licenses/lgpl-2.1.en.html

Extension points exported contracts — how you extend this code

Container (Interface)
The `Container` trait must be implemented for all shapes you wish to pack spheres into. Standard shapes such as spheres [6 …
src/lib.rs

Core symbols most depended-on inside this repo

contains
called by 6
src/shapes/cuboid.rs
pack_spheres
called by 5
src/lib.rs
volume
called by 4
src/shapes/cuboid.rs
ray_intersection_count
called by 4
src/util/mod.rs
trimesh_volume
called by 4
src/util/mod.rs
init_spheres
called by 2
src/lib.rs
overlaps
called by 2
src/shapes/sphere.rs
sphere_contacts
called by 1
src/lib.rs

Shape

Function 45
Method 33
Class 11
Enum 2
Interface 1

Languages

Rust100%

Modules by API surface

src/lib.rs15 symbols
tests/containers.rs13 symbols
src/serialization.rs11 symbols
tests/shapes.rs8 symbols
src/shapes/sphere.rs6 symbols
src/errors.rs6 symbols
src/shapes/cuboid.rs5 symbols
tests/packing.rs4 symbols
examples/statistics_emerald.rs4 symbols
examples/show_in_emerald.rs4 symbols
examples/show_in_cow.rs4 symbols
tests/serialization.rs3 symbols

For agents

$ claude mcp add spherical-cow \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact