Struct polytope::Polytope [] [src]

pub struct Polytope<V> { /* fields omitted */ }

A data structure that represents a polytope — a flat sided multi-dimensional object where the vertices are connected by edges, edges by faces, faces by cells, etc.

Vertex type is represented by the type parameter V and it must be implemented by the client depending on the problem at hand. For geometrical applications, it would make sense to represent a vertex as an n-dimensional vector, where n is equal to the dimension of the polytope, but this representation is not forced by the library.

The rest of the elements (edges, faces, cells, etc.) are represented as the list of indices of the lower dimensional bounding elements. For example, an edge bounded by the 4th and 5th vertices is represented as [4, 5].

Examples

The following code creates a 0-dimensional polytope (i.e. a point).

use polytope::Polytope;
let point = Polytope::<String>::new("".to_string());
assert_eq!(point.dimension(), 0);
assert_eq!(point.vertices().len(), 1);

Given a point, one can create a line, a rectangle and a prism using extrude():

use polytope::Polytope;
let pull_in = |v: &String| v.clone() + "-";
let push_out = |v: &String| v.clone() + "+";
let point = Polytope::<String>::new("".to_string());
let line = point.extrude(&pull_in, &push_out);
let rectangle = line.extrude(&pull_in, &push_out);
let prism = rectangle.extrude(&pull_in, &push_out);
assert_eq!(prism.dimension(), 3);
assert_eq!(prism.vertices().len(), 8);
assert_eq!(prism.elements(0).len(), 12);
assert_eq!(prism.elements(1).len(), 6);
assert_eq!(prism.elements(2).len(), 1);

...or, given a rectangle, one can create double pyramid using cone():

use polytope::Polytope;
let pull_in = |v: &String| v.clone() + "-";
let push_out = |v: &String| v.clone() + "+";
let point = Polytope::<String>::new("".to_string());
let line = point.extrude(&pull_in, &push_out);
let rectangle = line.extrude(&pull_in, &push_out);
let pyramid = rectangle.cone("0000".to_string(), pull_in, push_out);
assert_eq!(pyramid.dimension(), 3);
assert_eq!(pyramid.vertices().len(), 9);
assert_eq!(pyramid.elements(0).len(), 16);
assert_eq!(pyramid.elements(1).len(), 10);
assert_eq!(pyramid.elements(2).len(), 2);

Methods

impl<V> Polytope<V>
[src]

Constructs a 0-dimensional polytope with one vertex.

Returns the dimension of the polytope.

This is equal to the dimension of the highest dimensional element in the list of elements.

Lends the vertex list.

Lends the element list for the given dimension.

Extrudes the polytope into the higher dimension.

Two replicas of the polytope is created by applying the functions pull_in and push_out to the vertices. Then, the replicas are linked via higher dimensional elements (vertices via edges, edges via faces, etc.).

This can be used to construct lines out of vertices, rectangle out of lines, etc.

Constructs a higher dimensional double cone out of the polytope.

Two replicas of the polytope is created by applying the functions pull_in and push_out to the vertices. Then, the replicas are linked to the given apex via higher dimensional elements.

This can be used to construct double triangle, double pyramid, double cone, etc.

Trait Implementations

impl<V: Debug> Debug for Polytope<V>
[src]

Formats the value using the given formatter.