rive_rs/math/
aabb.rs

1// Copyright 2021 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5use crate::math::Vec;
6
7#[derive(Clone, Debug, Eq, PartialEq)]
8pub struct Aabb {
9    pub min: Vec,
10    pub max: Vec,
11}
12
13impl Aabb {
14    pub fn new(min_x: f32, min_y: f32, max_x: f32, max_y: f32) -> Self {
15        Self { min: Vec::new(min_x, min_y), max: Vec::new(max_x, max_y) }
16    }
17
18    pub fn center(&self) -> Vec {
19        Vec::new((self.min.x + self.max.x) * 0.5, (self.min.y + self.max.y) * 0.5)
20    }
21
22    pub fn size(&self) -> Vec {
23        Vec::new(self.max.x - self.min.x, self.max.y - self.min.y)
24    }
25
26    pub fn extents(&self) -> Vec {
27        self.size() * 0.5
28    }
29}