/// scale by different amounts in x and y.
pub orig_size: Vec<f64>,
- pub centre: [f64; 2],
+ #[serde(default)]
+ /// Default if not supplied is the centre according to the size.
+ pub centre: Option<[f64; 2]>,
#[serde(default)]
/// Default is `false`
impl FaceTransform {
#[throws(LLE)]
fn from_group(d: &GroupDetails) -> Self {
- let centre = d.centre;
+ // by this point d.size has already been scaled by scale
+ let centre = d.centre.map(Ok).unwrap_or_else(|| Ok::<_,LLE>({
+ match d.size.as_slice() {
+ [a] => [a,a],
+ [a,b] => [a,b],
+ x => throw!(LLE::WrongNumberOfSizeDimensions {
+ got: x.len(),
+ expected: [1,2],
+ }),
+ }.iter().cloned().map(|size| {
+ size * 0.5 / d.scale
+ })
+ .collect::<ArrayVec<[_;2]>>()
+ .into_inner()
+ .unwrap()
+ }))?;
let scale = if ! d.orig_size.is_empty() && ! d.size.is_empty() {
- // by this point d.size has already been scaled by scale
izip!(&d.orig_size, &d.size)
.map(|(&orig_size, &target_size)| {
target_size / orig_size