1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Copyright © 2025-2026 The µcad authors <info@microcad.xyz>
// SPDX-License-Identifier: AGPL-3.0-or-later
//! µcad core geometry traits
use crate::{Integer, Rect};
/// Trait to align something to center.
pub trait Center<T = Self> {
/// Align geometry.
fn center(&self) -> T;
}
/// Trait to distribute geometries in a 2D grid.
pub trait DistributeGrid<T = Self> {
/// Distribute in a grid.
fn distribute_grid(&self, rect: Rect, rows: Integer, columns: Integer) -> T;
}
/// Return total amount of memory in bytes.
pub trait TotalMemory {
/// Total amount of memory in bytes.
fn total_memory(&self) -> usize {
self.stack_memory() + self.heap_memory()
}
/// Get amount of stack memory in bytes.
fn stack_memory(&self) -> usize {
std::mem::size_of_val(self)
}
/// Get amount of heap memory in bytes.
fn heap_memory(&self) -> usize {
0
}
}
impl<T> TotalMemory for Vec<T> {
fn heap_memory(&self) -> usize {
self.capacity() * std::mem::size_of::<T>()
}
}
/// Return number of vertices.
pub trait VertexCount {
/// Return vertex count.
fn vertex_count(&self) -> usize;
}