A Rust library for constructing tilings of regular polygons

Related tags

Utilities tiling
Overview

tiling

Crates.io Crates.io License License

tiling is a library for constructing tilings of regular polygons and their dual tilings.

tiling

Resources

Examples

Here are some tilings produced by the examples in the examples directory.

examples

Requirements

tiling uses cairo-rs for rendering and requires cairo to be installed.

Usage

Create an empty tiling model.

let (width, height, scale) = (1024, 1024, 128.0);

let mut model = Model::new(width, height, scale);

Place a polygon at the origin. This adds a hexagon.

let stroke = Color::new(242, 60, 60)?;
let fill_hexagon = Color::new(242, 194, 106)?;

model.add(Shape::new(6, fill_hexagon, stroke)?);

At this point we can render the model.

let background = Color::new(242, 242, 242)?;
let margin = 0.1;
let show_labels = false;
let line_width = 0.1;

let render = model.render(background, margin, line_width, show_labels)?;
render.write_to_png("output.png")?;

hexagon

Let's continue by attaching a square to each of the hexagon's sides.

let fill_square = Color::new(23, 216, 146)?;

let squares = model.add_multi(0..1, 0..6, Shape::new(4, fill_square, stroke)?)?;

The first parameter 0..1 is a range that indicates the shape(s) to attach to (by their index). In this example, the square is attached to the hexagon (index 0).

When show_labels is true, each shape is labeled with its index.

The second paramter 0..6 is a range that indicates the edge(s) to attach to (by their index). In this example, the square is attached to all six edges of the hexagon.

When show_labels is true, each edge is labeled with its index.

The final paramter defines the shape to add (a square).

The add_multi method returns a range containing the indexes of the added square shapes so they can be referenced later. We'll see how to do that next.

hexagon squares

Now, attach triangles to all of the squares using the previously returned range squares. Here, a triangle is attached to edge 1 of each square.

let fill_triangle = Color::new(242, 209, 48)?;

let _ = model.add_multi(squares.clone(), 1..2, Shape::new(3, fill_triangle, stroke)?)?;

hexagon squares triangles

Let's wrap up by attaching a hexagon to the outer edge of each square. These hexagons will define the repeating positions of the tiling.

let hexagons = model.add_multi(squares.clone(), 2..3, Shape::new(6, fill_hexagon, stroke)?)?;

hexagon squares triangles hexagons

Now that the tiling's repeating pattern is complete, use the repeat method to fill the rest of the surface with the pattern.

model.repeat(hexagons)?;

hexagon squares triangles hexagons repeated

Once satisfied, disable the shape and edge labels and adjust the scale.

The complete code for this example is in examples/intro.rs.

Dual tilings may be created using the render_dual method. A tiling's dual is formed by drawing edges between the centers of adjacent polygons.

Here is the dual tiling of the above example.

hexagon squares triangles hexagons dual tiling

Installation

tiling is available on crates.io and can be included in your Cargo enabled project.

[dependencies]
tiling = "0.1.0"

Future improvements

  • Declarative API
  • Reduce memory usage by reusing Shape references
  • Generate tiling models by interpreting their vertex configuration
  • Command line tool
  • Support shape and edge attachment via disjoint ranges
  • Support different image output types

Acknowledgements

This library was inspired by Michael Fogleman's Tiling Python tool. Several of the low-level geometric computations in this crate are based on implementations found in Tiling.

You might also like...
Membrane is an opinionated crate that generates a Dart package from a Rust library. Extremely fast performance with strict typing and zero copy returns over the FFI boundary via bincode.

Membrane is an opinionated crate that generates a Dart package from a Rust library. Extremely fast performance with strict typing and zero copy returns over the FFI boundary via bincode.

Stack unwinding library in Rust

Unwinding library in Rust and for Rust This library serves two purposes: Provide a pure Rust alternative to libgcc_eh or libunwind. Provide easier unw

Easy to use Rust i18n library based on code generation

rosetta-i18n rosetta-i18n is an easy-to-use and opinionated Rust internationalization (i18n) library powered by code generation. rosetta_i18n::include

A library for advanced finite element computations in Rust
A library for advanced finite element computations in Rust

A Rust library for building advanced applications with the Finite Element Method (FEM). Although developed with a special emphasis on solid mechanics

Mononym is a library for creating unique type-level names for each value in Rust.

Mononym is a library for creating unique type-level names for each value in Rust.

tiny_id is a Rust library for generating non-sequential, tightly-packed short IDs.

tiny_id tiny_id is a Rust library for generating non-sequential, tightly-packed short IDs. Most other short ID generators just string together random

islam is an Islamic library for Rust.

islam is an Islamic library for Rust. It is a direct port of PyIslam with a slight change in the API part.

A Rust library for managing eBPF programs.

oxidebpf oxidebpf is a permissive licensed Rust library for managing eBPF programs. Motivation The motivation behind oxidebpf is to create a permissiv

A rust library that makes reading and writing memory of the Dolphin emulator easier.

dolphin-memory-rs A crate for reading from and writing to the emulated memory of Dolphin in rust. A lot of internals here are directly based on aldela

Owner
Jonas Michel
Jonas Michel
A library to compile USDT probes into a Rust library

sonde sonde is a library to compile USDT probes into a Rust library, and to generate a friendly Rust idiomatic API around it. Userland Statically Defi

Ivan Enderlin 40 Jan 7, 2023
A Rust library for calculating sun positions

sun A rust port of the JS library suncalc. Install Add the following to your Cargo.toml [dependencies] sun = "0.2" Usage pub fn main() { let unixti

Markus Kohlhase 36 Dec 28, 2022
A cross-platform serial port library in Rust.

Introduction serialport-rs is a general-purpose cross-platform serial port library for Rust. It provides a blocking I/O interface and port enumeration

Bryant Mairs 143 Nov 5, 2021
A high level diffing library for rust based on diffs

Similar: A Diffing Library Similar is a dependency free crate for Rust that implements different diffing algorithms and high level interfaces for it.

Armin Ronacher 617 Dec 30, 2022
A reactive DOM library for Rust in WASM

maple A VDOM-less web library with fine-grained reactivity. Getting started The recommended build tool is Trunk. Start by adding maple-core to your Ca

Luke Chu 1.8k Jan 3, 2023
transmute-free Rust library to work with the Arrow format

Arrow2: Transmute-free Arrow This repository contains a Rust library to work with the Arrow format. It is a re-write of the official Arrow crate using

Jorge Leitao 708 Dec 30, 2022
Cross-platform Window library in Rust for Tauri. [WIP]

Cross-platform application window creation library in Rust that supports all major platforms like Windows, macOS, Linux, iOS and Android. Built for you, maintained for Tauri.

Tauri 899 Jan 1, 2023
A library in Rust for theorem proving with Intuitionistic Propositional Logic.

Prop Propositional logic with types in Rust. A library in Rust for theorem proving with Intuitionistic Propositional Logic. Supports theorem proving i

AdvancedResearch 48 Jan 3, 2023
miette is a diagnostic library for Rust. It includes a series of traits/protocols that allow you to hook into its error reporting facilities, and even write your own error reports!

miette is a diagnostic library for Rust. It includes a series of traits/protocols that allow you to hook into its error reporting facilities, and even write your own error reports!

Kat Marchán 1.2k Jan 1, 2023
Generative arts library in Rust

Generative Generative (WIP) is 2D generational arts creation library written in Rust. Currently it is in nascent stage and is somewhat unstable. Examp

Gaurav Patel 22 May 13, 2022