From eee2ccc7b15b53e1f81f447e3a4fde6af77d4bc2 Mon Sep 17 00:00:00 2001 From: Jovansonlee Cesar Date: Fri, 23 Sep 2022 16:46:19 +0800 Subject: breaking: remove settings from the low-level function calls --- packages/svgbob/src/buffer/cell_buffer.rs | 26 +++---- packages/svgbob/src/buffer/cell_buffer/cell.rs | 8 +- packages/svgbob/src/buffer/cell_buffer/contacts.rs | 7 +- packages/svgbob/src/buffer/cell_buffer/endorse.rs | 2 +- packages/svgbob/src/buffer/cell_buffer/span.rs | 31 +++----- .../src/buffer/cell_buffer/span/test_span.rs | 23 +++--- packages/svgbob/src/buffer/fragment_buffer.rs | 5 +- .../src/buffer/fragment_buffer/fragment/line.rs | 61 +++++++-------- .../src/buffer/fragment_buffer/fragment/text.rs | 7 +- packages/svgbob/src/buffer/property_buffer.rs | 17 +--- .../svgbob/src/buffer/property_buffer/property.rs | 30 +++----- packages/svgbob/src/map/ascii_map.rs | 90 +++++++++------------- packages/svgbob/src/map/circle_map.rs | 6 +- .../svgbob/src/map/circle_map/test_circle_map.rs | 2 +- 14 files changed, 124 insertions(+), 191 deletions(-) diff --git a/packages/svgbob/src/buffer/cell_buffer.rs b/packages/svgbob/src/buffer/cell_buffer.rs index 0727800..c9d4444 100644 --- a/packages/svgbob/src/buffer/cell_buffer.rs +++ b/packages/svgbob/src/buffer/cell_buffer.rs @@ -94,15 +94,12 @@ impl CellBuffer { } /// return the group of contacting fragments - pub fn group_contacts( - &self, - settings: &Settings, - ) -> (Vec, Vec) { + pub fn group_contacts(&self) -> (Vec, Vec) { let groups: Vec<(Vec, Vec)> = self .group_adjacents() .into_iter() .map(|span| { - let contacts = span.get_contacts(settings); + let contacts = span.get_contacts(); if contacts.is_empty() { (vec![span], vec![]) } else { @@ -191,12 +188,9 @@ impl CellBuffer { } /// return fragments that are Rect, Circle, - pub fn get_shapes_fragment( - &self, - settings: &Settings, - ) -> Vec { + pub fn get_shapes_fragment(&self) -> Vec { let (single_member, _, endorsed_fragments) = - self.group_single_members_from_other_fragments(settings); + self.group_single_members_from_other_fragments(); endorsed_fragments .into_iter() .chain(single_member.into_iter().filter(|frag| { @@ -208,7 +202,6 @@ impl CellBuffer { /// returns (single_member, grouped, rest of the fragments fn group_single_members_from_other_fragments( &self, - settings: &Settings, ) -> (Vec, Vec>, Vec) { // endorsed_fragments are the fragment result of successful endorsement // @@ -220,7 +213,7 @@ impl CellBuffer { ) = self .group_adjacents() .into_iter() - .map(|span| span.endorse(settings)) + .map(|span| span.endorse()) .unzip(); // partition the vec_groups into groups that is alone and the group @@ -262,10 +255,9 @@ impl CellBuffer { /// return the fragments that are (close objects, touching grouped fragments) pub fn get_fragment_spans( &self, - settings: &Settings, ) -> (Vec, Vec>) { let (single_member_fragments, vec_group_fragments, vec_fragments) = - self.group_single_members_from_other_fragments(settings); + self.group_single_members_from_other_fragments(); let escaped_text = self.escaped_text_nodes(); let regulars = @@ -281,7 +273,7 @@ impl CellBuffer { settings: &Settings, ) -> (Vec>, Vec) { let (single_member_fragments, vec_group_fragments, vec_fragments) = - self.group_single_members_from_other_fragments(settings); + self.group_single_members_from_other_fragments(); // grouped fragments will be rendered as svg groups let group_nodes: Vec> = vec_group_fragments @@ -760,7 +752,7 @@ This is a text "#; let buffer = CellBuffer::from(art); - let shapes = buffer.get_shapes_fragment(&Settings::default()); + let shapes = buffer.get_shapes_fragment(); println!("shapes: {:#?}", shapes); assert_eq!(2, shapes.len()); } @@ -774,7 +766,7 @@ This is a text "#; let buffer = CellBuffer::from(art); - let shapes = buffer.get_shapes_fragment(&Settings::default()); + let shapes = buffer.get_shapes_fragment(); println!("shapes: {:#?}", shapes); assert_eq!(1, shapes.len()); assert!(shapes[0] diff --git a/packages/svgbob/src/buffer/cell_buffer/cell.rs b/packages/svgbob/src/buffer/cell_buffer/cell.rs index e2fa1ca..c7c779f 100644 --- a/packages/svgbob/src/buffer/cell_buffer/cell.rs +++ b/packages/svgbob/src/buffer/cell_buffer/cell.rs @@ -86,18 +86,14 @@ impl Cell { } pub fn snap_group(points: &[Point]) -> Self { - let snaps: Vec<(Self, Point)> = points - .iter() - .map(|point| Self::snap_point(*point)) - .collect(); let (cells, _snap_points): (Vec, Vec) = - snaps.into_iter().unzip(); + points.iter().map(|point| Self::snap_point(*point)).unzip(); let min_cell: Self = cells.into_iter().min().expect("should have a min cell"); min_cell } - pub(in crate) fn absolute_position(&self, point: Point) -> Point { + pub(crate) fn absolute_position(&self, point: Point) -> Point { self.top_left_most() + point } diff --git a/packages/svgbob/src/buffer/cell_buffer/contacts.rs b/packages/svgbob/src/buffer/cell_buffer/contacts.rs index d1a5764..7805b78 100644 --- a/packages/svgbob/src/buffer/cell_buffer/contacts.rs +++ b/packages/svgbob/src/buffer/cell_buffer/contacts.rs @@ -66,12 +66,9 @@ impl Contacts { let fragments = self.fragments(); if let Some(rect) = endorse::endorse_rect(&fragments) { Some(rect.into()) - } else if let Some(rounded_rect) = - endorse::endorse_rounded_rect(&fragments) - { - Some(rounded_rect.into()) } else { - None + endorse::endorse_rounded_rect(&fragments) + .map(|rounded_rect| rounded_rect.into()) } } diff --git a/packages/svgbob/src/buffer/cell_buffer/endorse.rs b/packages/svgbob/src/buffer/cell_buffer/endorse.rs index 15a4cc8..8e93a64 100644 --- a/packages/svgbob/src/buffer/cell_buffer/endorse.rs +++ b/packages/svgbob/src/buffer/cell_buffer/endorse.rs @@ -142,7 +142,7 @@ fn parallel_aabb_group(fragments: &[&Fragment]) -> Vec<(usize, usize)> { || index2 == *pair1 || index2 == *pair2 }) - && frag1.is_aabb_parallel(&frag2) + && frag1.is_aabb_parallel(frag2) { parallels.push((index1, index2)); } diff --git a/packages/svgbob/src/buffer/cell_buffer/span.rs b/packages/svgbob/src/buffer/cell_buffer/span.rs index 8ded0ae..9c2856e 100644 --- a/packages/svgbob/src/buffer/cell_buffer/span.rs +++ b/packages/svgbob/src/buffer/cell_buffer/span.rs @@ -16,7 +16,7 @@ use std::{ /// A describes where a char came from relative to the source ascii text /// The primary purpose of span is to group adjacent cell together -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Eq)] pub struct Span(pub Vec<(Cell, char)>); impl Deref for Span { @@ -137,11 +137,11 @@ impl Span { /// Only elements on the same span are checked to see if they /// belong on the same group /// - pub(crate) fn get_contacts(&self, settings: &Settings) -> Vec { - let fb: FragmentBuffer = self.into_fragment_buffer(settings); + pub(crate) fn get_contacts(&self) -> Vec { + let fb: FragmentBuffer = self.clone().into_fragment_buffer(); let mut groups: Vec = vec![]; - let merged_fragments = fb.merge_fragment_spans(settings); + let merged_fragments = fb.merge_fragment_spans(); for fragment in merged_fragments.into_iter() { let belongs_to_group = groups.iter_mut().rev().any(|group| { if group.is_contacting_frag(&fragment) { @@ -168,10 +168,7 @@ impl Span { /// The second element of the tuple: `contacts` are fragments that are touching together /// but can not form a fragment shape. These will be grouped in the svg nodes /// to keep them go together, when dragged (editing) - pub(crate) fn endorse( - self, - settings: &Settings, - ) -> (Vec, Vec) { + pub(crate) fn endorse(self) -> (Vec, Vec) { let mut fragments = vec![]; let (top_left, _) = self.bounds().expect("must have bounds"); let un_endorsed_span = if let Some((circle, un_endorsed_span)) = @@ -193,7 +190,7 @@ impl Span { self }; - let groups: Vec = un_endorsed_span.get_contacts(settings); + let groups: Vec = un_endorsed_span.get_contacts(); let (rect_fragments, un_endorsed) = Contacts::endorse_rects(groups); fragments.extend(rect_fragments); @@ -227,20 +224,14 @@ impl Span { /// We try it again for endorsing to circle fn re_endorsed( grouped: Vec>, - settings: &Settings, ) -> (Vec, Vec) { let spans = Self::extract_spans(grouped); let merged_spans: Vec = Self::merge_recursive(spans); - let endorsed_spans: Vec<(Vec, Vec)> = - merged_spans - .into_iter() - .map(|span| span.endorse(settings)) - .collect(); let (endorsed_frag_spans, endorsed_contacts): ( Vec>, Vec>, - ) = endorsed_spans.into_iter().unzip(); + ) = merged_spans.into_iter().map(|span| span.endorse()).unzip(); ( endorsed_frag_spans.into_iter().flatten().collect(), @@ -293,7 +284,7 @@ impl Bounds { } /// create a property buffer for all the cells of this span -impl<'p> Into> for &Span { +impl<'p> Into> for Span { fn into(self) -> PropertyBuffer<'p> { let mut pb = PropertyBuffer::new(); for (cell, ch) in self.iter() { @@ -311,9 +302,9 @@ impl<'p> Into> for &Span { /// If a character has no property, try to see if has equivalent fragments from unicode_map /// otherwise add it to the fragment_buffer as a text fragment impl Span { - fn into_fragment_buffer(&self, settings: &Settings) -> FragmentBuffer { - let pb: PropertyBuffer = self.into(); - let mut fb: FragmentBuffer = pb.into_fragment_buffer(settings); + fn into_fragment_buffer(self) -> FragmentBuffer { + let pb: PropertyBuffer = self.clone().into(); + let mut fb: FragmentBuffer = pb.into_fragment_buffer(); for (cell, ch) in self.iter() { if pb.as_ref().get(cell).is_none() { if let Some(fragments) = UNICODE_FRAGMENTS.get(ch) { diff --git a/packages/svgbob/src/buffer/cell_buffer/span/test_span.rs b/packages/svgbob/src/buffer/cell_buffer/span/test_span.rs index 73c3947..26e88d4 100644 --- a/packages/svgbob/src/buffer/cell_buffer/span/test_span.rs +++ b/packages/svgbob/src/buffer/cell_buffer/span/test_span.rs @@ -58,8 +58,7 @@ fn test_1span_1group() { let span = adjacents.remove(0); let (top_left, _) = span.bounds().unwrap(); assert_eq!(top_left, Cell::new(0, 1)); - let groups: Vec = - span.localize().get_contacts(&Settings::default()); + let groups: Vec = span.localize().get_contacts(); for (i, group) in groups.iter().enumerate() { println!("group {} is: \n{}", i, group); } @@ -98,9 +97,8 @@ fn test_2spans_1group_for_each_span() { let (bound2, _) = span2.bounds().unwrap(); assert_eq!(bound1, Cell::new(0, 1)); assert_eq!(bound2, Cell::new(0, 5)); - let settings = &Settings::default(); - let groups1: Vec = span1.localize().get_contacts(settings); - let groups2: Vec = span2.localize().get_contacts(settings); + let groups1: Vec = span1.localize().get_contacts(); + let groups2: Vec = span2.localize().get_contacts(); assert_eq!(groups1.len(), 1); assert_eq!(groups2.len(), 1); @@ -145,8 +143,7 @@ fn test_1spans_2group_for_each_span() { let span1 = spans.remove(0); let (bound1, _) = span1.bounds().unwrap(); assert_eq!(bound1, Cell::new(0, 1)); - let groups: Vec = - span1.localize().get_contacts(&Settings::default()); + let groups: Vec = span1.localize().get_contacts(); assert_eq!(groups.len(), 2); let rect1 = groups[0].endorse_rect().unwrap(); @@ -188,7 +185,7 @@ fn test_endorse_circle() { let span = adjacents.remove(0); let (top_left, _) = span.bounds().unwrap(); assert_eq!(top_left, Cell::new(8, 1)); - let (mut fragments, _groups) = span.endorse(&Settings::default()); + let (mut fragments, _groups) = span.endorse(); for (i, frag) in fragments.iter().enumerate() { println!("frag {}:\n{}", i, frag); } @@ -219,7 +216,7 @@ fn test_endorse_circle_with_rect() { let span1 = adjacents.remove(0); let (top_left1, _) = span1.bounds().unwrap(); assert_eq!(top_left1, Cell::new(8, 1)); - let (mut fragments, _groups) = span1.endorse(&Settings::default()); + let (mut fragments, _groups) = span1.endorse(); assert_eq!(fragments.len(), 2); let circle = fragments.remove(0); @@ -268,7 +265,7 @@ fn test_endorse_with_big_circle() { let span1 = adjacents.remove(0); let (top_left1, _) = span1.bounds().unwrap(); assert_eq!(top_left1, Cell::new(12, 3)); - let (mut fragments, _groups) = span1.endorse(&Settings::default()); + let (mut fragments, _groups) = span1.endorse(); assert_eq!(fragments.len(), 1); let circle = fragments.remove(0); @@ -304,7 +301,7 @@ fn test_endorse_with_big_circle_extra_match() { let span1 = adjacents.remove(0); let (top_left1, _) = span1.bounds().unwrap(); assert_eq!(top_left1, Cell::new(12, 3)); - let (fragments, groups) = span1.endorse(&Settings::default()); + let (fragments, groups) = span1.endorse(); assert_eq!(fragments.len(), 1); assert_eq!(groups.len(), 0); for (i, fragment) in groups.iter().enumerate() { @@ -335,7 +332,7 @@ fn test_absolute_positions() { let (top_left1, _br) = span1.bounds().unwrap(); assert_eq!(top_left1, Cell::new(8, 5)); - let groups1 = span1.localize().get_contacts(&Settings::default()); + let groups1 = span1.localize().get_contacts(); let since = groups1[11].as_ref()[0].fragment.as_cell_text().unwrap(); assert_eq!(since.content, "since"); assert_eq!(since.start, Cell::new(20, 1)); @@ -357,7 +354,7 @@ fn test_endorse_arc() { let span = adjacents.remove(0); let (top_left, _) = span.bounds().unwrap(); assert_eq!(top_left, Cell::new(8, 1)); - let (mut fragments, _groups) = span.endorse(&Settings::default()); + let (mut fragments, _groups) = span.endorse(); for (i, frag) in fragments.iter().enumerate() { println!("frag {}:\n{}", i, frag); } diff --git a/packages/svgbob/src/buffer/fragment_buffer.rs b/packages/svgbob/src/buffer/fragment_buffer.rs index e9bdddb..0a308a9 100644 --- a/packages/svgbob/src/buffer/fragment_buffer.rs +++ b/packages/svgbob/src/buffer/fragment_buffer.rs @@ -134,10 +134,7 @@ impl FragmentBuffer { self.sort_fragments_in_cell(cell); } - pub fn merge_fragment_spans( - &self, - settings: &Settings, - ) -> Vec { + pub fn merge_fragment_spans(&self) -> Vec { let fragment_spans = self.into_fragment_spans(); FragmentSpan::merge_recursive(fragment_spans) } diff --git a/packages/svgbob/src/buffer/fragment_buffer/fragment/line.rs b/packages/svgbob/src/buffer/fragment_buffer/fragment/line.rs index d113e40..7aaa552 100644 --- a/packages/svgbob/src/buffer/fragment_buffer/fragment/line.rs +++ b/packages/svgbob/src/buffer/fragment_buffer/fragment/line.rs @@ -35,7 +35,7 @@ impl Line { } /// creates a new line, but don't reorder the points - pub(in crate) fn new_noswap( + pub(crate) fn new_noswap( start: Point, end: Point, is_broken: bool, @@ -49,7 +49,7 @@ impl Line { /// reorder the end points swap end points such that /// start < end - pub(in crate) fn sort_reorder_end_points(&mut self) { + pub(crate) fn sort_reorder_end_points(&mut self) { if self.start > self.end { self.swap() } @@ -62,7 +62,7 @@ impl Line { } /// does this line can completely cover line a b? - pub(in crate) fn overlaps(&self, a: Point, b: Point) -> bool { + pub(crate) fn overlaps(&self, a: Point, b: Point) -> bool { let segment = Segment::new(*self.start, *self.end); let identity = &Isometry::identity(); segment.contains_point(identity, &a) @@ -133,10 +133,10 @@ impl Line { /// round angle closest to /// /// slash line is not really 60% but 63.435 - /// 63.435 0 63.435 - /// 180 116.565 - /// 180 243.435 - /// 360 296.565 + /// 63.435 0 63.435 + /// 180 116.565 + /// 180 243.435 + /// 360 296.565 /// /// fn line_angle(&self) -> f32 { @@ -159,19 +159,19 @@ impl Line { } } - /// 0 0 - /// 45 45 - /// 63.435 63 - /// 90 90 - /// 116.565 117 - /// 135 135 - /// 180 180 - /// 225 225 - /// 243.435 243 - /// 270 270 - /// 296.565 297 - /// 315 315 - /// 360 360 + /// 0 0 + /// 45 45 + /// 63.435 63 + /// 90 90 + /// 116.565 117 + /// 135 135 + /// 180 180 + /// 225 225 + /// 243.435 243 + /// 270 270 + /// 296.565 297 + /// 315 315 + /// 360 360 pub(crate) fn heading(&self) -> Direction { match self.line_angle().round() as i32 { 0 => Direction::Right, @@ -278,7 +278,7 @@ impl Line { /// and are collinear ( lies on the same line) can be test by computing the triangle area which /// should be equal to 0. /// therefore can merge - pub(in crate) fn can_merge(&self, other: &Self) -> bool { + pub(crate) fn can_merge(&self, other: &Self) -> bool { self.is_touching(other) && util::is_collinear(&self.start, &self.end, &other.start) && util::is_collinear(&self.start, &self.end, &other.end) @@ -287,7 +287,7 @@ impl Line { /// check if this line and the other can merge /// returns None if it can not merge /// the merged line used the starting_point of self and the end_point of other - pub(in crate) fn merge(&self, other: &Self) -> Option { + pub(crate) fn merge(&self, other: &Self) -> Option { if self.can_merge(other) { let start = std::cmp::min(self.start, other.start); let end = std::cmp::max(self.end, other.end); @@ -389,15 +389,15 @@ impl Line { /// check to see if any of the line endpoints is touching. /// this will be used to group lines together /// This does not check if the lines are intersecting - pub(in crate) fn is_touching(&self, other: &Self) -> bool { + pub(crate) fn is_touching(&self, other: &Self) -> bool { self.touching_line(other) || other.touching_line(self) } - pub(in crate) fn has_endpoint(&self, p: Point) -> bool { + pub(crate) fn has_endpoint(&self, p: Point) -> bool { self.start == p || self.end == p } - pub(in crate) fn is_touching_arc(&self, other: &Arc) -> bool { + pub(crate) fn is_touching_arc(&self, other: &Arc) -> bool { self.start == other.start || self.end == other.end || self.start == other.end @@ -416,7 +416,7 @@ impl Line { /// check if 2 lines are parallel in axis align box /// for the purpose of promoting lines into rect - pub(in crate) fn is_aabb_parallel(&self, other: &Self) -> bool { + pub(crate) fn is_aabb_parallel(&self, other: &Self) -> bool { (self.is_horizontal() && other.is_horizontal() && self.start.x == other.start.x @@ -429,22 +429,19 @@ impl Line { /// check if 2 lines are perpendicular in axis align box only /// for the purpose of promoting lines into rect - pub(in crate) fn is_aabb_perpendicular(&self, other: &Self) -> bool { + pub(crate) fn is_aabb_perpendicular(&self, other: &Self) -> bool { (self.is_horizontal() && other.is_vertical()) || (self.is_vertical() && other.is_horizontal()) } /// check if 2 lines are touching and aabb perpendicular at the same time - pub(in crate) fn is_touching_aabb_perpendicular( - &self, - other: &Self, - ) -> bool { + pub(crate) fn is_touching_aabb_perpendicular(&self, other: &Self) -> bool { self.is_touching(other) && self.is_aabb_perpendicular(other) } /// recompute the line with start and end point offset by the cell /// location - pub(in crate) fn absolute_position(&self, cell: Cell) -> Self { + pub(crate) fn absolute_position(&self, cell: Cell) -> Self { Line { start: cell.absolute_position(self.start), end: cell.absolute_position(self.end), diff --git a/packages/svgbob/src/buffer/fragment_buffer/fragment/text.rs b/packages/svgbob/src/buffer/fragment_buffer/fragment/text.rs index 8d1e0a4..1504b55 100644 --- a/packages/svgbob/src/buffer/fragment_buffer/fragment/text.rs +++ b/packages/svgbob/src/buffer/fragment_buffer/fragment/text.rs @@ -265,7 +265,7 @@ mod tests { let mut spans: Vec = cell_buffer.group_adjacents(); assert_eq!(spans.len(), 1); let span1 = spans.remove(0); - let groups = span1.localize().get_contacts(&Settings::default()); + let groups = span1.localize().get_contacts(); for (i, group) in groups.iter().enumerate() { println!("group{}\n{}", i, group); } @@ -311,9 +311,8 @@ mod tests { let cell_buffer = CellBuffer::from(art); let mut spans: Vec = cell_buffer.group_adjacents(); assert_eq!(spans.len(), 2); - let settings = &Settings::default(); - let groups2 = spans.remove(1).localize().get_contacts(settings); - let groups1 = spans.remove(0).localize().get_contacts(settings); + let groups2 = spans.remove(1).localize().get_contacts(); + let groups1 = spans.remove(0).localize().get_contacts(); println!("span1 groups:"); for (i, group1) in groups1.iter().enumerate() { println!("\tgroup {} {}", i, group1); diff --git a/packages/svgbob/src/buffer/property_buffer.rs b/packages/svgbob/src/buffer/property_buffer.rs index 67d72b8..89cc2df 100644 --- a/packages/svgbob/src/buffer/property_buffer.rs +++ b/packages/svgbob/src/buffer/property_buffer.rs @@ -1,7 +1,7 @@ use crate::{ fragment, map::{ASCII_PROPERTIES, UNICODE_FRAGMENTS}, - Cell, Fragment, FragmentBuffer, Merge, Settings, + Cell, Fragment, FragmentBuffer, Merge, }; pub use property::{Property, Signal}; use std::collections::HashMap; @@ -28,7 +28,6 @@ impl<'p> PropertyBuffer<'p> { /// into the most fitting ascii / unicode character pub fn match_char_from_cell( &self, - settings: &Settings, cell: Cell, fragments: &Vec, try_unicode: bool, @@ -57,7 +56,6 @@ impl<'p> PropertyBuffer<'p> { self.as_ref().get(&cell.bottom_right()).unwrap_or(empty); Self::match_char_with_surrounding_properties( - settings, &fragments, top_left, top, @@ -74,7 +72,6 @@ impl<'p> PropertyBuffer<'p> { /// if the fragments match to the return fragments /// of the property behavior, then it is a match pub fn match_char_with_surrounding_properties( - settings: &Settings, fragments: &Vec, top_left: &Property, top: &Property, @@ -99,7 +96,6 @@ impl<'p> PropertyBuffer<'p> { } else { ASCII_PROPERTIES.iter().find_map(|(ch, property)| { let behavioral_fragments = property.fragments( - settings, top_left, top, top_right, @@ -139,10 +135,7 @@ impl<'p> AsMut> for PropertyBuffer<'p> { /// convert property buffer to fragment buffer impl<'p> PropertyBuffer<'p> { - pub(crate) fn into_fragment_buffer( - &self, - settings: &Settings, - ) -> FragmentBuffer { + pub(crate) fn into_fragment_buffer(&self) -> FragmentBuffer { let mut fb = FragmentBuffer::new(); for (cell, property) in self.as_ref() { let empty = &&Property::empty(); @@ -158,7 +151,6 @@ impl<'p> PropertyBuffer<'p> { let bottom_right = self.as_ref().get(&cell.bottom_right()).unwrap_or(empty); let cell_fragments = property.fragments( - settings, top_left, top, top_right, @@ -217,7 +209,6 @@ mod tests { let bottom = &Property::empty(); let bottom_right = &Property::empty(); let ch = PropertyBuffer::match_char_with_surrounding_properties( - &Settings::default(), &fragments, top_left, top, @@ -254,7 +245,6 @@ mod tests { let bottom = &Property::empty(); let bottom_right = &Property::empty(); let ch = PropertyBuffer::match_char_with_surrounding_properties( - &Settings::default(), &fragments, top_left, top, @@ -292,7 +282,6 @@ mod tests { let bottom = &Property::from_char('|').unwrap(); let bottom_right = &Property::empty(); let ch = PropertyBuffer::match_char_with_surrounding_properties( - &Settings::default(), &fragments, top_left, top, @@ -325,7 +314,6 @@ mod tests { let bottom = &Property::empty(); let bottom_right = &Property::empty(); let ch = PropertyBuffer::match_char_with_surrounding_properties( - &Settings::default(), &fragments, top_left, top, @@ -359,7 +347,6 @@ mod tests { let bottom = &Property::empty(); let bottom_right = &Property::empty(); let ch = PropertyBuffer::match_char_with_surrounding_properties( - &Settings::default(), &fragments, top_left, top, diff --git a/packages/svgbob/src/buffer/property_buffer/property.rs b/packages/svgbob/src/buffer/property_buffer/property.rs index 20d5a35..7d51dae 100644 --- a/packages/svgbob/src/buffer/property_buffer/property.rs +++ b/packages/svgbob/src/buffer/property_buffer/property.rs @@ -1,7 +1,7 @@ use self::Signal::Strong; use crate::{ map::{ASCII_PROPERTIES, UNICODE_PROPERTIES}, - Fragment, Point, Settings, + Fragment, Point, }; use std::{cmp, fmt, sync::Arc}; @@ -58,7 +58,6 @@ pub struct Property { /// depending on flag that is meet when checked agains the surrounding characters pub behavior: Arc< dyn Fn( - &Settings, &Property, &Property, &Property, @@ -90,7 +89,6 @@ impl Property { signature: Vec<(Signal, Vec)>, behavior: Arc< dyn Fn( - &Settings, &Property, &Property, &Property, @@ -114,7 +112,7 @@ impl Property { /// get the matching property of this char /// start from the ascii_map lookup /// then to the unicode_map lookup when it can't find from the first map. - pub(in crate) fn from_char<'a>(ch: char) -> Option<&'a Property> { + pub(crate) fn from_char<'a>(ch: char) -> Option<&'a Property> { match ASCII_PROPERTIES.get(&ch) { Some(property) => Some(property), None => UNICODE_PROPERTIES.get(&ch), @@ -127,7 +125,7 @@ impl Property { Property { ch: ' ', signature: vec![], - behavior: Arc::new(|_, _, _, _, _, _, _, _, _| vec![]), + behavior: Arc::new(|_, _, _, _, _, _, _, _| vec![]), } } @@ -137,9 +135,7 @@ impl Property { ch, signature: vec![(Signal::Strong, fragments)], //TODO find a way to move the fragments here - behavior: Arc::new(|_, _, _, _, _, _, _, _, _| { - vec![(true, vec![])] - }), + behavior: Arc::new(|_, _, _, _, _, _, _, _| vec![(true, vec![])]), } } @@ -164,7 +160,7 @@ impl Property { /// Check if the property is exactly this character /// returns true if this property is derive from character `ch` - pub(in crate) fn is(&self, ch: char) -> bool { + pub(crate) fn is(&self, ch: char) -> bool { self.ch == ch } @@ -179,25 +175,25 @@ impl Property { /// evaluate this property together with the supplied surrounding /// to see if the resulting fragments is equal to the supplied fragments - pub(in crate) fn match_property(&self, _fragments: &Vec) -> bool { + pub(crate) fn match_property(&self, _fragments: &Vec) -> bool { false } /// Check to see if this spot can overal the line a b with at least Medium signal - pub(in crate) fn line_overlap(&self, a: Point, b: Point) -> bool { + pub(crate) fn line_overlap(&self, a: Point, b: Point) -> bool { self.line_overlap_with_signal(a, b, Signal::Medium) } - pub(in crate) fn line_strongly_overlap(&self, a: Point, b: Point) -> bool { + pub(crate) fn line_strongly_overlap(&self, a: Point, b: Point) -> bool { self.line_overlap_with_signal(a, b, Signal::Strong) } - pub(in crate) fn line_weakly_overlap(&self, a: Point, b: Point) -> bool { + pub(crate) fn line_weakly_overlap(&self, a: Point, b: Point) -> bool { self.line_overlap_with_signal(a, b, Signal::Weak) } /// Check to see if this spot has an endpoint to p - pub(in crate) fn has_endpoint(&self, p: Point) -> bool { + pub(crate) fn has_endpoint(&self, p: Point) -> bool { self.signature.iter().any(|(_signal, signature)| { signature.iter().any(|fragment| fragment.has_endpoint(p)) }) @@ -221,16 +217,15 @@ impl Property { /// Check to see if any fragment that is generated in this character /// can arc from a to b regardless of the radius - pub(in crate) fn arcs_to(&self, a: Point, b: Point) -> bool { + pub(crate) fn arcs_to(&self, a: Point, b: Point) -> bool { self.signature.iter().any(|(_signal, signature)| { signature.iter().any(|fragment| fragment.arcs_to(a, b)) }) } /// the fragments of this property when the surrounding properties is supplied - pub(in crate) fn fragments( + pub(crate) fn fragments( &self, - settings: &Settings, top_left: &Property, top: &Property, top_right: &Property, @@ -241,7 +236,6 @@ impl Property { bottom_right: &Property, ) -> Vec { let bool_fragments = self.behavior.as_ref()( - settings, top_left, top, top_right, diff --git a/packages/svgbob/src/map/ascii_map.rs b/packages/svgbob/src/map/ascii_map.rs index b11582d..76da352 100644 --- a/packages/svgbob/src/map/ascii_map.rs +++ b/packages/svgbob/src/map/ascii_map.rs @@ -7,7 +7,7 @@ use crate::{ Cell, CellGrid, }, fragment::{arc, broken_line, circle, line, polygon, rect}, - Fragment, Property, Settings, + Fragment, Property, Signal::{self, Medium, Strong, Weak}, }; use lazy_static::lazy_static; @@ -99,7 +99,7 @@ lazy_static! { let map: Vec<( char, Vec<(Signal, Vec)>, - Arc Vec<(bool, Vec)> + Sync + Send >, + Arc Vec<(bool, Vec)> + Sync + Send >, )> = vec![ /////////////// // dash - @@ -110,17 +110,9 @@ lazy_static! { (Strong, vec![line(k, o)]), ], Arc::new( - move|settings, top_left, top, top_right, left, right, bottom_left, bottom, bottom_right| { + move| top_left, top, top_right, left, right, bottom_left, bottom, bottom_right| { vec![ (true, vec![line(k,o)]), - /* - // | - // .-. - // | - (settings.enhance_circuitries && left.is('.') && right.is('.') && top.line_strongly_overlap(r,w) && bottom.line_strongly_overlap(c,h), - vec![arc(o,k,unit4),line(c,w)] - ), - */ ] } ) @@ -134,7 +126,7 @@ lazy_static! { (Strong, vec![broken_line(k, o)]), ], Arc::new( - move|settings, top_left, top, top_right, left, right, bottom_left, bottom, bottom_right| { + move|top_left, top, top_right, left, right, bottom_left, bottom, bottom_right| { vec![ (true, vec![broken_line(k, o)]), ] @@ -150,7 +142,7 @@ lazy_static! { (Strong, vec![line(c,w)]), ], Arc::new( - move|settings, top_left, top, top_right, left, right, bottom_left, bottom, bottom_right| { + move|top_left, top, top_right, left, right, bottom_left, bottom, bottom_right| { vec![ (!bottom_left.is('/') && !bottom_right.is('\\') && !top_left.is('\\') && !top_right.is('/'), vec![line(c,w)]), // _ @@ -193,7 +185,7 @@ lazy_static! { (Strong, vec![broken_line(c,w)]), ], Arc::new( - move|settings, top_left, top, top_right, left, right, bottom_left, bottom, bottom_right| { + move| top_left, top, top_right, left, right, bottom_left, bottom, bottom_right| { vec![ (top.line_strongly_overlap(r,w) || bottom.line_strongly_overlap(c,h), vec![broken_line(c,w)]), ] @@ -209,7 +201,7 @@ lazy_static! { (Strong, vec![broken_line(c,w)]), ], Arc::new( - move|settings, top_left, top, top_right, left, right, bottom_left, bottom, bottom_right| { + move| top_left, top, top_right, left, right, bottom_left, bottom, bottom_right| { vec![ (top.line_strongly_overlap(r,w) || bottom.line_strongly_overlap(c,h), vec![broken_line(c,w)]), ] @@ -226,7 +218,7 @@ lazy_static! { (Weak, vec![line(a,y), line(u,e)]), ], Arc::new( - move|settings, top_left, top, top_right, left, right, bottom_left, bottom, bottom_right| { + move| top_left, top, top_right, left, right, bottom_left, bottom, bottom_right| { vec![ // | // + @@ -269,7 +261,7 @@ lazy_static! { (Strong, vec![line(a,y), line(u,e)]), ], Arc::new( - move|settings, top_left, top, top_right, left, right, bottom_left, bottom, bottom_right| { + move|top_left, top, top_right, left, right, bottom_left, bottom, bottom_right| { vec![ /* // \ X @@ -317,7 +309,7 @@ lazy_static! { (Weak, vec![line(a,y), line(u,e)]), ], Arc::new( - move|settings, top_left, top, top_right, left, right, bottom_left, bottom, bottom_right| { + move| top_left, top, top_right, left, right, bottom_left, bottom, bottom_right| { vec![ // must have at least one connection @@ -381,7 +373,7 @@ lazy_static! { (Weak, vec![line(a,y), line(u,e)]), ], Arc::new( - move|settings, top_left, top, top_right, left, right, bottom_left, bottom, bottom_right| { + move| top_left, top, top_right, left, right, bottom_left, bottom, bottom_right| { vec![ // // | @@ -448,7 +440,7 @@ lazy_static! { (Weak, vec![line(a,y), line(u,e)]), ], Arc::new( - move|settings, top_left, top, top_right, left, right, bottom_left, bottom, bottom_right| { + move| top_left, top, top_right, left, right, bottom_left, bottom, bottom_right| { vec![ // must have at least one connection // \|/ @@ -506,7 +498,7 @@ lazy_static! { (Weak, vec![line(a,y), line(u,e)]), ], Arc::new( - move|settings, top_left, top, top_right, left, right, bottom_left, bottom, bottom_right| { + move| top_left, top, top_right, left, right, bottom_left, bottom, bottom_right| { vec![ // must have at least one connection // \|/ @@ -559,7 +551,7 @@ lazy_static! { (Strong, vec![line(u, y)]) ], Arc::new( - move|settings, top_left, top, top_right, left, right, bottom_left, bottom, bottom_right| { + move| top_left, top, top_right, left, right, bottom_left, bottom, bottom_right| { vec![ (true, vec![line(u,y)]), // /_ @@ -581,7 +573,7 @@ lazy_static! { (Weak, vec![line(m,o)]), // connects right ], Arc::new( - move|settings, top_left, top, top_right, left, right, bottom_left, bottom, bottom_right| { + move| top_left, top, top_right, left, right, bottom_left, bottom, bottom_right| { vec![ // . // | @@ -668,7 +660,7 @@ lazy_static! { (Weak, vec![line(m,o)]), // connects right ], Arc::new( - move|settings, top_left, top, top_right, left, right, bottom_left, bottom, bottom_right| { + move|top_left, top, top_right, left, right, bottom_left, bottom, bottom_right| { vec![ // ,- // | @@ -693,7 +685,7 @@ lazy_static! { (Weak, vec![line(m,o)]), // connects right ], Arc::new( - move|settings, top_left, top, top_right, left, right, bottom_left, bottom, bottom_right| { + move|top_left, top, top_right, left, right, bottom_left, bottom, bottom_right| { vec![ // | // ' @@ -762,7 +754,7 @@ lazy_static! { (Weak, vec![line(m,o)]), // connects right ], Arc::new( - move|settings, top_left, top, top_right, left, right, bottom_left, bottom, bottom_right| { + move|top_left, top, top_right, left, right, bottom_left, bottom, bottom_right| { vec![ // | // ’- @@ -819,7 +811,7 @@ lazy_static! { (Weak, vec![line(m,o)]), // connects right ], Arc::new( - move|settings, top_left, top, top_right, left, right, bottom_left, bottom, bottom_right| { + move| top_left, top, top_right, left, right, bottom_left, bottom, bottom_right| { vec![ // | // `- @@ -854,16 +846,16 @@ lazy_static! { (Strong, vec![line(u,e)]), ], Arc::new( - move|settings, top_left, top, top_right, left, right, bottom_left, bottom, bottom_right| { + move|top_left, top, top_right, left, right, bottom_left, bottom, bottom_right| { vec![ (!bottom.line_strongly_overlap(c,h), vec![line(u,e)]), // /- - (settings.enhance_circuitries && right.line_strongly_overlap(k,l), vec![line(m,o)]), + ( right.line_strongly_overlap(k,l), vec![line(m,o)]), // -/ - (settings.enhance_circuitries && left.line_strongly_overlap(n,o), vec![line(m,k)]), + ( left.line_strongly_overlap(n,o), vec![line(m,k)]), // / // | - (settings.enhance_circuitries && bottom.line_strongly_overlap(c,h), vec![line(e,m),line(m,w)]), + (bottom.line_strongly_overlap(c,h), vec![line(e,m),line(m,w)]), ]} ) ), @@ -876,23 +868,17 @@ lazy_static! { (Strong, vec![line(a,y)]), ], Arc::new( - move|settings, top_left, top, top_right, left, right, bottom_left, bottom, bottom_right| { + move| top_left, top, top_right, left, right, bottom_left, bottom, bottom_right| { vec![ (!bottom.is('|'), vec![line(a,y)]), - /* - // . - // \ - // | - (top_left.is('.') && bottom_right.is('|'), vec![arc(cell.bottom_right().w(),a, unit8 * 4.0)]), - */ // \ // | (bottom.line_overlap(c,m), vec![line(a,m),line(m,w)]), // \- - (settings.enhance_circuitries && right.line_strongly_overlap(k,l), vec![line(m,o)]), + ( right.line_strongly_overlap(k,l), vec![line(m,o)]), // -\ - (settings.enhance_circuitries && left.line_strongly_overlap(n,o), vec![line(m,k)]), + (left.line_strongly_overlap(n,o), vec![line(m,k)]), ] } ) @@ -905,15 +891,15 @@ lazy_static! { (Medium, vec![arc(e,y, unit8)]), ], Arc::new( - move|settings, top_left, top, top_right, left, right, bottom_left, bottom, bottom_right| { + move| top_left, top, top_right, left, right, bottom_left, bottom, bottom_right| { vec![ (!top.line_overlap(r,w) && !bottom.line_overlap(c,h), vec![arc(e,y,unit8)]), // | // ( // | - (settings.enhance_circuitries && top.line_overlap(r,w) && bottom.line_overlap(c,h), vec![arc(c,w,unit6)]), + ( bottom.line_overlap(c,h), vec![arc(c,w,unit6)]), // -(- - (settings.enhance_circuitries && left.line_overlap(m,o) && right.line_overlap(k,l), vec![line(k,o)]), + ( left.line_overlap(m,o) && right.line_overlap(k,l), vec![line(k,o)]), ] } ) @@ -926,15 +912,15 @@ lazy_static! { (Medium, vec![arc(u,a, unit8)]), ], Arc::new( - move|settings, top_left, top, top_right, left, right, bottom_left, bottom, bottom_right| { + move| top_left, top, top_right, left, right, bottom_left, bottom, bottom_right| { vec![ (!top.line_overlap(r,w) && !bottom.line_overlap(c,h), vec![arc(u,a,unit8)]), // | // ) // | - (settings.enhance_circuitries && top.line_overlap(r,w) && bottom.line_overlap(c,h), vec![arc(w,c,unit6)]), + (top.line_overlap(r,w) && bottom.line_overlap(c,h), vec![arc(w,c,unit6)]), // -)- - (settings.enhance_circuitries && left.line_overlap(m,o) && right.line_overlap(k,l), vec![line(k,o)]), + (left.line_overlap(m,o) && right.line_overlap(k,l), vec![line(k,o)]), ] } ) @@ -948,7 +934,7 @@ lazy_static! { (Weak, vec![line(m,w)]), ], Arc::new( - move|settings, top_left, top, top_right, left, right, bottom_left, bottom, bottom_right| { + move| top_left, top, top_right, left, right, bottom_left, bottom, bottom_right| { vec![ // | // V @@ -981,7 +967,7 @@ lazy_static! { (Medium, vec![polygon(vec![f,j,w], true, vec![ArrowBottom, ArrowBottomLeft, ArrowBottomRight])]), ], Arc::new( - move|settings, top_left, top, top_right, left, right, bottom_left, bottom, bottom_right| { + move|top_left, top, top_right, left, right, bottom_left, bottom, bottom_right| { vec![ // | // v @@ -1013,7 +999,7 @@ lazy_static! { (Medium, vec![polygon(vec![p,c,t], true, vec![ArrowTop, ArrowTopLeft, ArrowTopRight])]), ], Arc::new( - move|settings, top_left, top, top_right, left, right, bottom_left, bottom, bottom_right| { + move|top_left, top, top_right, left, right, bottom_left, bottom, bottom_right| { vec![ // ^ // | @@ -1042,7 +1028,7 @@ lazy_static! { (Medium, vec![polygon(vec![f,o,p], true, vec![ArrowRight])]), ], Arc::new( - move|settings, top_left, top, top_right, left, right, bottom_left, bottom, bottom_right| { + move|top_left, top, top_right, left, right, bottom_left, bottom, bottom_right| { vec![ // ---> (left.line_overlap(n,o), vec![polygon(vec![f,o,p], true, vec![ArrowRight])]), @@ -1067,7 +1053,7 @@ lazy_static! { (Medium, vec![polygon(vec![j,k,t], true, vec![ArrowLeft])]), ], Arc::new( - move|settings, top_left, top, top_right, left, right, bottom_left, bottom, bottom_right| { + move|top_left, top, top_right, left, right, bottom_left, bottom, bottom_right| { vec![ // <-- (right.line_overlap(k,l), vec![polygon(vec![j,k,t], true, vec![ArrowLeft])]), @@ -1092,7 +1078,7 @@ lazy_static! { (Medium, vec![line(_03, _43), line(_05, _45)]), ], Arc::new( - move|settings, top_left, top, top_right, left, right, bottom_left, bottom, bottom_right| { + move|top_left, top, top_right, left, right, bottom_left, bottom, bottom_right| { vec![ (true, vec![line(_03, _43), line(_05, _45)]), ] diff --git a/packages/svgbob/src/map/circle_map.rs b/packages/svgbob/src/map/circle_map.rs index 6c65ab2..b878a51 100644 --- a/packages/svgbob/src/map/circle_map.rs +++ b/packages/svgbob/src/map/circle_map.rs @@ -542,7 +542,7 @@ lazy_static! { /// Calculate the span and get the group fragments static ref FRAGMENTS_CIRCLE: Vec<(Vec,Circle)> = Vec::from_iter( CIRCLE_MAP.iter().map(|circle_art|{ - (circle_art_to_group(circle_art.ascii_art, &Settings::default()), Circle::new(circle_art.center(), circle_art.radius(), false)) + (circle_art_to_group(circle_art.ascii_art), Circle::new(circle_art.center(), circle_art.radius(), false)) }) ); @@ -732,9 +732,9 @@ impl Ord for DiameterArc { } } -fn circle_art_to_group(art: &str, settings: &Settings) -> Vec { +fn circle_art_to_group(art: &str) -> Vec { let span1 = circle_art_to_span(art); - span1.get_contacts(settings) + span1.get_contacts() } fn circle_art_to_span(art: &str) -> Span { diff --git a/packages/svgbob/src/map/circle_map/test_circle_map.rs b/packages/svgbob/src/map/circle_map/test_circle_map.rs index 7c1fd34..f2e449e 100644 --- a/packages/svgbob/src/map/circle_map/test_circle_map.rs +++ b/packages/svgbob/src/map/circle_map/test_circle_map.rs @@ -18,7 +18,7 @@ fn test_circle1() { let mut spans: Vec = cell_buffer.group_adjacents(); assert_eq!(spans.len(), 1); let span1 = spans.remove(0); - let groups = span1.get_contacts(&Settings::default()); + let groups = span1.get_contacts(); for (i, group) in groups.iter().enumerate() { println!("group{}\n{}", i, group); } -- cgit v1.2.3