Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions examples/overlay_editor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ log = "0.4.22"
console_log = "^1.0.0"
console_error_panic_hook = "^0"

i_mesh = "^0.3.0"
i_triangle = { version = "^0.35.0", features = ["serde"] }
#i_mesh = "^0.4.0"
#i_triangle = { version = "^0.35.0", features = ["serde"] }

#i_triangle = { path = "../../../../iShape/iTriangle/iTriangle", default-features = true, features = ["serde"] }
#i_mesh = { path = "../../../../iShape/iMesh/iMesh" }
i_triangle = { path = "../../../../iShape/iTriangle/iTriangle", default-features = true, features = ["serde"] }
i_mesh = { path = "../../../../iShape/iMesh/iMesh" }

#ICED_BACKEND=wgpu cargo r -r
2 changes: 1 addition & 1 deletion examples/overlay_editor/src/app/boolean/content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub(crate) enum BooleanMessage {
}

impl EditorApp {
fn boolean_sidebar(&self) -> Column<AppMessage> {
fn boolean_sidebar(&self) -> Column<'_, AppMessage> {
let count = self.app_resource.boolean.count;
let mut column = Column::new().push(
Space::new()
Expand Down
3 changes: 0 additions & 3 deletions examples/overlay_editor/src/app/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use crate::app::string::content::StringMessage;
use crate::app::string::content::StringState;
use crate::app::stroke::content::StrokeMessage;
use crate::app::stroke::content::StrokeState;
use iced::event::Event as MainEvent;
use iced::keyboard::key::Named;
use iced::keyboard::Key;
use iced::widget::{rule, Space};
Expand Down Expand Up @@ -64,7 +63,6 @@ pub(crate) enum AppMessage {
String(StringMessage),
Stroke(StrokeMessage),
Outline(OutlineMessage),
EventOccurred(MainEvent),
NextTest,
PrevTest,
}
Expand Down Expand Up @@ -111,7 +109,6 @@ impl EditorApp {
MainAction::Stroke => self.stroke_prev_test(),
MainAction::Outline => self.outline_prev_test(),
}
_ => {}
}

Task::none()
Expand Down
5 changes: 3 additions & 2 deletions examples/overlay_editor/src/app/stroke/content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use i_triangle::i_overlay::i_float::int::rect::IntRect;
use iced::widget::{scrollable, Button, Column, Container, Row, Space, Text};
use iced::{Alignment, Length, Padding, Size, Vector};
use std::collections::HashMap;
use std::rc::Rc;

pub(crate) struct StrokeState {
pub(crate) test: usize,
Expand Down Expand Up @@ -307,7 +308,7 @@ impl StrokeState {
[ 3.0, 0.0],
[-1.0, 2.0],
];
style = style.start_cap(LineCap::Custom(points))
style = style.start_cap(LineCap::Custom(Rc::from(points)))
}
}

Expand All @@ -326,7 +327,7 @@ impl StrokeState {
[ 3.0, 0.0],
[-1.0, 2.0],
];
style = style.end_cap(LineCap::Custom(points))
style = style.end_cap(LineCap::Custom(Rc::from(points)))
}
}

Expand Down
4 changes: 2 additions & 2 deletions examples/overlay_editor/src/draw/shape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl ShapeWidget {
let validation = Validation::with_fill_rule(fill_rule.unwrap_or_default());
let triangulation =
IntTriangulator::new(shapes.points_count(), validation, Default::default())
.triangulate_shapes(shapes, false);
.triangulate_shapes(shapes);

Self::fill_mesh_for_triangulation(triangulation, camera, offset, color)
}
Expand All @@ -91,7 +91,7 @@ impl ShapeWidget {
let validation = Validation::with_fill_rule(fill_rule.unwrap_or_default());
let triangulation =
IntTriangulator::new(paths.points_count(), validation, Default::default())
.triangulate_shape(paths, false);
.triangulate_shape(paths);

// let triangulation = paths.triangulate().into_triangulation();

Expand Down
2 changes: 1 addition & 1 deletion iOverlay/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ allow_multithreading = ["dep:rayon"]
[dev-dependencies]
serde = { version = "^1.0", features = ["derive"] }
serde_json = "^1.0"
rand = { version = "~0.9", features = ["alloc"] }
rand = { version = "~0.10", features = ["alloc"] }
#i_float = { path = "../../iFloat", features = ["serde"] }
#i_shape = { path = "../../iShape", features = ["serde"] }
i_float = { version = "~1.16.0", features = ["serde"] }
Expand Down
69 changes: 0 additions & 69 deletions iOverlay/src/build/boolean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,19 +274,6 @@ impl BooleanFillFilter for SegmentFill {
}

impl OverlayLinkFilter for [OverlayLink] {
#[inline]
fn filter_by_overlay(&self, overlay_rule: OverlayRule) -> Vec<VisitState> {
match overlay_rule {
OverlayRule::Subject => filter_subject(self),
OverlayRule::Clip => filter_clip(self),
OverlayRule::Intersect => filter_intersect(self),
OverlayRule::Union => filter_union(self),
OverlayRule::Difference => filter_difference(self),
OverlayRule::Xor => filter_xor(self),
OverlayRule::InverseDifference => filter_inverse_difference(self),
}
}

#[inline]
fn filter_by_overlay_into(&self, overlay_rule: OverlayRule, buffer: &mut Vec<VisitState>) {
match overlay_rule {
Expand All @@ -301,62 +288,6 @@ impl OverlayLinkFilter for [OverlayLink] {
}
}

#[inline]
fn filter_subject(links: &[OverlayLink]) -> Vec<VisitState> {
links
.iter()
.map(|link| VisitState::new(!link.fill.is_subject()))
.collect()
}

#[inline]
fn filter_clip(links: &[OverlayLink]) -> Vec<VisitState> {
links
.iter()
.map(|link| VisitState::new(!link.fill.is_clip()))
.collect()
}

#[inline]
fn filter_intersect(links: &[OverlayLink]) -> Vec<VisitState> {
links
.iter()
.map(|link| VisitState::new(!link.fill.is_intersect()))
.collect()
}

#[inline]
fn filter_union(links: &[OverlayLink]) -> Vec<VisitState> {
links
.iter()
.map(|link| VisitState::new(!link.fill.is_union()))
.collect()
}

#[inline]
fn filter_difference(links: &[OverlayLink]) -> Vec<VisitState> {
links
.iter()
.map(|link| VisitState::new(!link.fill.is_difference()))
.collect()
}

#[inline]
fn filter_inverse_difference(links: &[OverlayLink]) -> Vec<VisitState> {
links
.iter()
.map(|link| VisitState::new(!link.fill.is_inverse_difference()))
.collect()
}

#[inline]
fn filter_xor(links: &[OverlayLink]) -> Vec<VisitState> {
links
.iter()
.map(|link| VisitState::new(!link.fill.is_xor()))
.collect()
}

#[inline]
fn filter_subject_into(links: &[OverlayLink], buffer: &mut Vec<VisitState>) {
buffer.clear();
Expand Down
2 changes: 1 addition & 1 deletion iOverlay/src/build/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pub(crate) mod boolean;
pub(crate) mod builder;
mod graph;
mod offset;
pub(crate) mod offset;
pub(crate) mod string;
pub(crate) mod sweep;
mod util;
30 changes: 26 additions & 4 deletions iOverlay/src/build/offset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ use crate::segm::segment::{Segment, SegmentFill};

impl GraphBuilder<ShapeCountOffset, OverlayNode> {
#[inline]
pub(crate) fn build_offset(
pub(crate) fn build_offset<F: FillStrategy<ShapeCountOffset>>(
&mut self,
solver: &Solver,
segments: &[Segment<ShapeCountOffset>],
) -> OffsetGraph<'_> {
self.build_fills_with_strategy::<SubjectOffsetStrategy>(solver, segments);
self.build_fills_with_strategy::<F>(solver, segments);
self.build_links_all(segments);
self.offset_graph(solver)
}
Expand All @@ -29,10 +29,11 @@ impl GraphBuilder<ShapeCountOffset, OverlayNode> {
}
}

struct SubjectOffsetStrategy;
pub(crate) struct PositiveSubjectOffsetStrategy;
pub(crate) struct NegativeSubjectOffsetStrategy;
const BOLD_BIT: usize = 2;

impl FillStrategy<ShapeCountOffset> for SubjectOffsetStrategy {
impl FillStrategy<ShapeCountOffset> for PositiveSubjectOffsetStrategy {
#[inline(always)]
fn add_and_fill(this: ShapeCountOffset, bot: ShapeCountOffset) -> (ShapeCountOffset, SegmentFill) {
let top_subj = bot.subj + this.subj;
Expand All @@ -53,6 +54,27 @@ impl FillStrategy<ShapeCountOffset> for SubjectOffsetStrategy {
}
}

impl FillStrategy<ShapeCountOffset> for NegativeSubjectOffsetStrategy {
#[inline(always)]
fn add_and_fill(this: ShapeCountOffset, bot: ShapeCountOffset) -> (ShapeCountOffset, SegmentFill) {
let top_subj = bot.subj + this.subj;
let bot_subj = bot.subj;

let subj_top = (top_subj < 0) as SegmentFill;
let subj_bot = (bot_subj < 0) as SegmentFill;

let bold = this.bold as SegmentFill;

let fill = subj_top | (subj_bot << 1) | (bold << BOLD_BIT);
let top = ShapeCountOffset {
subj: top_subj,
bold: false,
}; // bold not need

(top, fill)
}
}

impl OverlayLink {
#[inline(always)]
pub(crate) fn is_bold(&self) -> bool {
Expand Down
4 changes: 2 additions & 2 deletions iOverlay/src/core/extract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ impl OverlayGraph<'_> {
start_data: &StartPathData,
clockwise: bool,
visited_state: VisitState,
visited: &mut Vec<VisitState>,
visited: &mut [VisitState],
points: &mut Vec<IntPoint>,
) {
let mut link_id = start_data.link_id;
Expand All @@ -196,7 +196,7 @@ impl OverlayGraph<'_> {

// Find a closed tour
while node_id != last_node_id {
link_id = GraphUtil::next_link(self.links, self.nodes, link_id, node_id, clockwise, &visited);
link_id = GraphUtil::next_link(self.links, self.nodes, link_id, node_id, clockwise, visited);

let link = unsafe {
// Safety: `link_id` is always derived from a previous in-bounds index or
Expand Down
6 changes: 3 additions & 3 deletions iOverlay/src/core/extract_ogc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,8 @@ impl OverlayGraph<'_> {
&self,
start_data: &StartPathData,
clockwise: bool,
global_visited: &mut Vec<VisitState>,
contour_visited: &mut Vec<VisitState>,
global_visited: &mut [VisitState],
contour_visited: &mut [VisitState],
points: &mut Vec<IntPoint>,
) -> Option<IntShape> {
let mut link_id = start_data.link_id;
Expand Down Expand Up @@ -266,7 +266,7 @@ impl OverlayGraph<'_> {

points.reserve_capacity(original_contour_len);
self.find_contour(
&start_data,
start_data,
!clockwise,
VisitState::HullVisited,
contour_visited,
Expand Down
1 change: 0 additions & 1 deletion iOverlay/src/core/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,5 @@ impl OverlayLink {
}

pub(crate) trait OverlayLinkFilter {
fn filter_by_overlay(&self, fill_rule: OverlayRule) -> Vec<VisitState>;
fn filter_by_overlay_into(&self, overlay_rule: OverlayRule, buffer: &mut Vec<VisitState>);
}
Loading
Loading