Add TODO messages and rename Canvas::push_back to Canvas::add_element
This commit is contained in:
parent
bbd221e489
commit
4b1dd4caed
|
|
@ -37,6 +37,7 @@ impl CanvasElement {
|
|||
}
|
||||
|
||||
// O(1) complexity
|
||||
// TODO: This is only a toy implementation, this is not at all correct!
|
||||
fn segment_intersects_rect(segment: &druid::kurbo::PathSeg, rect: druid::Rect) -> bool {
|
||||
match segment {
|
||||
druid::kurbo::PathSeg::Line(line) => rect.contains(line.p0) || rect.contains(line.p1),
|
||||
|
|
@ -46,7 +47,7 @@ fn segment_intersects_rect(segment: &druid::kurbo::PathSeg, rect: druid::Rect) -
|
|||
}
|
||||
|
||||
druid::kurbo::PathSeg::Cubic(cubic) => {
|
||||
rect.contains(cubic.p0) || rect.contains(cubic.p1) || rect.contains(cubic.p2)
|
||||
rect.contains(cubic.p0) || rect.contains(cubic.p1) || rect.contains(cubic.p2) || rect.contains(cubic.p3)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -68,6 +69,7 @@ impl Canvas {
|
|||
pub fn erase(&mut self, eraser_rect: druid::Rect) {
|
||||
for elem in self.elements.iter_mut() {
|
||||
if elem.bounding_box().intersect(eraser_rect).area() > 0.0 {
|
||||
// TODO: if a part of the path is erased, split the path into subpaths
|
||||
match elem {
|
||||
CanvasElement::Freehand { path, thickness: _ } => {
|
||||
// Remove segments intersecting the eraser
|
||||
|
|
@ -82,7 +84,7 @@ impl Canvas {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn push_back(&mut self, element: CanvasElement) {
|
||||
pub fn add_element(&mut self, element: CanvasElement) {
|
||||
self.elements.push_back(element);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ impl CanvasTool {
|
|||
if let Some(current_element) = current_element.take() {
|
||||
canvas.update(move |canvas: &Canvas| -> Canvas {
|
||||
let mut new_canvas = canvas.clone();
|
||||
new_canvas.push_back(current_element);
|
||||
new_canvas.add_element(current_element);
|
||||
return new_canvas;
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue