mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-15 22:28:10 +08:00
* Begin implementing viewport selection * Implement viewport click and drag selection for ellipse and rectangle * Begin implementing line selection * Remove debug prints * Run cargo format * Use DVec2 instead of kurbo::Point * Line and polyline intersection * Run cargo format * Add fix for missing layer panel update * Replace point selection with box selection * Formatting Co-authored-by: Keavon Chambers <keavon@keavon.com>
38 lines
1.1 KiB
Rust
38 lines
1.1 KiB
Rust
use glam::DAffine2;
|
|
use glam::DVec2;
|
|
use kurbo::Shape;
|
|
|
|
use crate::intersection::intersect_quad_bez_path;
|
|
use crate::LayerId;
|
|
|
|
use super::style;
|
|
use super::LayerData;
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
use std::fmt::Write;
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Default, Deserialize, Serialize)]
|
|
pub struct Ellipse {}
|
|
|
|
impl Ellipse {
|
|
pub fn new() -> Ellipse {
|
|
Ellipse {}
|
|
}
|
|
}
|
|
|
|
impl LayerData for Ellipse {
|
|
fn to_kurbo_path(&self, transform: glam::DAffine2, _style: style::PathStyle) -> kurbo::BezPath {
|
|
kurbo::Ellipse::from_affine(kurbo::Affine::new(transform.to_cols_array())).to_path(0.01)
|
|
}
|
|
|
|
fn render(&mut self, svg: &mut String, transform: glam::DAffine2, style: style::PathStyle) {
|
|
let _ = write!(svg, r#"<path d="{}" {} />"#, self.to_kurbo_path(transform, style).to_svg(), style.render());
|
|
}
|
|
|
|
fn intersects_quad(&self, quad: [DVec2; 4], path: &mut Vec<LayerId>, intersections: &mut Vec<Vec<LayerId>>, style: style::PathStyle) {
|
|
if intersect_quad_bez_path(quad, &self.to_kurbo_path(DAffine2::IDENTITY, style), true) {
|
|
intersections.push(path.clone());
|
|
}
|
|
}
|
|
}
|