cairo_viewport
This crate adds the Viewport abstraction on top of the excellent
cairo-rs crate, which itself is a Rust
wrapper around the cairo library. A
Viewport can be created from a BoundingBox and automatically configures
a cairo Context so it fits the underlying bounding box. This is useful to
simplify creating images of bounded objects, as shown below:
use ;
use BoundingBox;
let c = Circle ;
// The context is transformed so that the larger side (width or height) of the
// bounding box has 500 units when creating the image (e.g. 500 pixel for PNG).
let viewport = from_bounding_box;
// Use the viewport to create an image
viewport.write_to_file.expect;
File "docs/circle.svg":
Compare images
If the image-compare feature is enabled, the visual representation of objects
can be easily compared using the Viewport::compare_to_image function (only
for .png images). This is useful for testing:
use ;
use BoundingBox;
let c = Circle ;
let viewport = from_bounding_box;
viewport.compare_to_image.expect;
It is also possible to circumvent the usage of Viewport entirely by directly
calling the underlying free function compare_to_image. The convience wrapper
compare_or_create (also exists as method Viewport::compare_or_create)
either calls compare_to_image if the specified reference image exists or
creates the file if it doesn't.
Documentation
The full API documentation is available at https://docs.rs/cairo_canvas_autoconfig/0.1.0/var_quantity/.