[][src]Function nannou::geom::quad::triangles

pub fn triangles<V>(q: &Quad<V>) -> (Tri<V>, Tri<V>) where
    V: Vertex

Triangulates the given quad, represented by four points that describe its edges in either clockwise or anti-clockwise order.

Example

The following rectangle

This example is not tested

 a        b
  --------
  |      |
  |      |
  |      |
  --------
 d        c

given as

This example is not tested
triangles([a, b, c, d])

returns

This example is not tested
(Tri([a, b, c]), Tri([a, c, d]))

Here's a basic code example:

use nannou::geom::{self, pt2, Quad, Tri};

fn main() {
    let a = pt2(0.0, 1.0);
    let b = pt2(1.0, 1.0);
    let c = pt2(1.0, 0.0);
    let d = pt2(0.0, 0.0);
    let quad = Quad([a, b, c, d]);
    let triangles = geom::quad::triangles(&quad);
    assert_eq!(triangles, (Tri([a, b, c]), Tri([a, c, d])));
}