mirror of
https://github.com/penpot/penpot.git
synced 2025-05-18 14:16:11 +02:00
✨ Use skia matrix for internal data
This commit is contained in:
parent
4594c7bf0a
commit
3dcabc9502
13 changed files with 228 additions and 211 deletions
40
render-wasm/src/shapes/modifiers.rs
Normal file
40
render-wasm/src/shapes/modifiers.rs
Normal file
|
@ -0,0 +1,40 @@
|
|||
use skia_safe as skia;
|
||||
|
||||
use std::collections::HashSet;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::shapes::{Shape, TransformEntry};
|
||||
use crate::state::State;
|
||||
|
||||
fn propagate_shape(_state: &State, shape: &Shape, transform: skia::Matrix) -> Vec<TransformEntry> {
|
||||
let children: Vec<TransformEntry> = shape
|
||||
.children
|
||||
.iter()
|
||||
.map(|id| TransformEntry {
|
||||
id: id.clone(),
|
||||
transform,
|
||||
})
|
||||
.collect();
|
||||
|
||||
children
|
||||
}
|
||||
|
||||
pub fn propagate_modifiers(state: &State, modifiers: Vec<TransformEntry>) -> Vec<TransformEntry> {
|
||||
let mut entries = modifiers.clone();
|
||||
let mut processed = HashSet::<Uuid>::new();
|
||||
let mut result = Vec::<TransformEntry>::new();
|
||||
|
||||
// Propagate the transform to children
|
||||
while let Some(entry) = entries.pop() {
|
||||
if !processed.contains(&entry.id) {
|
||||
if let Some(shape) = state.shapes.get(&entry.id) {
|
||||
let mut children = propagate_shape(state, shape, entry.transform);
|
||||
entries.append(&mut children);
|
||||
processed.insert(entry.id);
|
||||
result.push(entry.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
result
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue