Skip to content

Commit

Permalink
Move background behind details arrow.
Browse files Browse the repository at this point in the history
A bit long to keep in the top level of the README.
  • Loading branch information
chinedufn committed Apr 27, 2021
1 parent 1052597 commit 9ffcf49
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
30 changes: 29 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ target_bins.insert(MyCustomBinId::DestinationBinTwo, TargetBin::new(4096, 4096,
// Information about where each `MyCustomRectId` was placed
let rectangle_placements = pack_rects(
&rects_to_place,
target_bins,
&mut target_bins,
&volume_heuristic,
&contains_smallest_box
).unwrap();
Expand All @@ -97,6 +97,22 @@ let rectangle_placements = pack_rects(

## Background / Initial Motivation

<details>
<summary>
Click to show the initial motivation for the library.

In my application I've switched to dynamically placing textures into atlases at runtime
instead of in how I previously used an asset compilation step, so some of the problems
explained here are now moot.

I still use rectangle-pack to power my runtime texture allocation, though,
along with a handful of other strategies depending on the nature of the
textures that need to be placed into the atlas.

rectangle-pack knows nothing about textures, so you can use it for any form of bin
packing, whether at runtime, during an offline step or any other time you like.
</summary>

I'm working on a game with some of the following texture atlas requirements (as of March 2020):

- I need to be able to guarantee that certain textures are available in the same atlas.
Expand Down Expand Up @@ -139,6 +155,9 @@ The API shouldn't know about the specifics of any of these requirements - it sho
> Given these rectangles that need to be placed, the maximum sizes of the target bins to place them in and some criteria about how to place and how not to place them,
> where can I put all of these rectangles?
</details>
<p></p>

## Features

- Place any number of 2d / 3d rectangles into any number of 2d / 3d target bins.
Expand Down Expand Up @@ -208,6 +227,15 @@ support our goal of flexibly supporting all use cases.

- There is a third dimension.

## In The Wild

Here are some known production users of `rectangle-pack`.

- [Akigi](https://akigi.com) uses `rectangle-pack` to power parts of its runtime texture allocation strategy.

- [Bevy](https://github.com/bevyengine/bevy/blob/9ae56e860468aa3158a702cbcf64e511b84a4b1c/crates/bevy_sprite/Cargo.toml#L29) uses `rectangle-pack`
to create texture atlases.

## Contributing

If you have a use case that isn't supported, a question, a patch, or anything else, go right ahead and open an issue or submit a pull request.
Expand Down
17 changes: 14 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ mod box_size_heuristics;
/// ## Example
///
/// ```
/// //! A basic example of packing rectangles into target bins
///
/// use rectangle_pack::{
/// GroupedRectsToPlace,
/// RectToInsert,
Expand All @@ -42,9 +44,11 @@ mod box_size_heuristics;
/// volume_heuristic,
/// contains_smallest_box
/// };
/// use std::collections::{BTreeMap};
/// use std::collections::BTreeMap;
///
/// // A rectangle ID just needs to meet these trait bounds (ideally also Copy)
/// // A rectangle ID just needs to meet these trait bounds (ideally also Copy).
/// // So you could use a String, PathBuf, or any other type that meets these
/// // trat bounds. You do not have to use a custom enum.
/// #[derive(Debug, Hash, PartialEq, Eq, Clone, Ord, PartialOrd)]
/// enum MyCustomRectId {
/// RectOne,
Expand All @@ -53,6 +57,8 @@ mod box_size_heuristics;
/// }
///
/// // A target bin ID just needs to meet these trait bounds (ideally also Copy)
/// // So you could use a u32, &str, or any other type that meets these
/// // trat bounds. You do not have to use a custom enum.
/// #[derive(Debug, Hash, PartialEq, Eq, Clone, Ord, PartialOrd)]
/// enum MyCustomBinId {
/// DestinationBinOne,
Expand All @@ -61,8 +67,13 @@ mod box_size_heuristics;
///
/// // A placement group just needs to meet these trait bounds (ideally also Copy).
/// //
/// // Groups are optional - they allow you to ensure that a set of rectangles will be placed
/// // Groups allow you to ensure that a set of rectangles will be placed
/// // into the same bin. If this isn't possible an error is returned.
/// //
/// // Groups are optional.
/// //
/// // You could use an i32, &'static str, or any other type that meets these
/// // trat bounds. You do not have to use a custom enum.
/// #[derive(Debug, Hash, PartialEq, Eq, Clone, Ord, PartialOrd)]
/// enum MyCustomGroupId {
/// GroupIdOne
Expand Down

0 comments on commit 9ffcf49

Please sign in to comment.