Skip to main content

rect_from_quad_points

Function rect_from_quad_points 

Source
pub fn rect_from_quad_points(array: Option<&Array>, index: usize) -> Rect
Expand description

The rectangle for quadrilateral index, or the zero rectangle when the index is past the end. Deliberately not clamped to the last quadrilateral.

use pdfrum_doc::annot::rect_from_quad_points;
use pdfrum_doc::geom;
use pdfrum_object::Array;

// `[x1 y1 x2 y2 x3 y3 x4 y4]`: (x3, y3) is left/bottom, (x2, y2) right/top.
let quad = Array::of([0, 8, 10, 8, 0, 0, 10, 0]);
assert_eq!(rect_from_quad_points(Some(&quad), 0), geom::rect(0.0, 0.0, 10.0, 8.0));
// Past the end is the zero rectangle, not the last quadrilateral.
assert_eq!(rect_from_quad_points(Some(&quad), 1), kurbo::Rect::ZERO);