From 54cacb663c5a51ec82bdbbd2fc96067daf08cff5 Mon Sep 17 00:00:00 2001 From: Jovansonlee Cesar Date: Tue, 11 Feb 2020 17:22:35 +0800 Subject: More improvements on the Architecture design --- Architecture.md | 46 ++++- Cargo.lock | 432 --------------------------------------- svgbob/Cargo.toml | 3 +- svgbob/src/buffer/cell_buffer.rs | 114 +++++++---- 4 files changed, 119 insertions(+), 476 deletions(-) diff --git a/Architecture.md b/Architecture.md index 9a182e3..950dcc3 100644 --- a/Architecture.md +++ b/Architecture.md @@ -1,5 +1,9 @@ # Svgbob Architecture and Design phases +Svgbob creates an svg drawing based on the input ascii art diagrams. +It achieves this by creating a corresponding fragment for each character, and then this little fragments +are then merged to form lines and arcs. The lines and arcs are then endorsed into high level shapes such as rect, circles. + ## Name inspiration: - svg for svg document and drawing. - bob for Alice and Bob as common characters in most diagrams @@ -491,6 +495,44 @@ Pros: PropertyBuffer is calculated only once for each character, so the succeeding lookup should not waste execution time to recompute. + +### How the fragments are conceived based on a character. + +### Neighbor character: There are 8 neighbors of a character and each character on the input is checked agains this 8 neighbor for appropriate drawing element +```bob ++---------+ +-----+ +---------+ +| TopLeft| | Top | | TopRight| ++---------+--+-----+---+---------+ + ++---------+ +------+ +--------+ +| Left | |(char)| | Right | ++---------+ +------+ +--------+ + ++----------+ +------+ +-----------+ +|BottomLeft| |Bottom| |BottomRight| ++----------+ +------+ +-----------+ +``` + +### Character Grid: a 5x5 grid which covers the most significant points for a character to be converted into drawing elements. + +Character grid: / is the line connecting E to U. Dash is connecting K to O, etc. +```bob + + 0 1 2 3 4 B C D + 0┌─┬─┬─┬─┐ A┌─┬─┬─┬─┐E + 1├─┼─┼─┼─┤ │ │ │ │ │ + 2├─┼─┼─┼─┤ F├─G─H─I─┤J + 3├─┼─┼─┼─┤ │ │ │ │ │ + 4├─┼─┼─┼─┤ K├─L─M─N─┤O + 5├─┼─┼─┼─┤ │ │ │ │ │ + 6├─┼─┼─┼─┤ P├─Q─R─S─┤T + 7├─┼─┼─┼─┤ │ │ │ │ │ + 8└─┴─┴─┴─┘ U└─┴─┴─┴─┘Y + V W X + +``` +These fragments are processed such as merging collinear lines that are touching their endpoints. + ```bob +--------------+ +------------+ +----------------+ +-----------------+ @@ -501,9 +543,9 @@ PropertyBuffer is calculated only once for each character, so the succeeding loo `-->| Spans | / +-------+ / \ / - \ +---------------+ .---------------. / + \ +---------------+ .----------------. / `-->|Contact groups |---/ endorse shapes /--' - +---------------+ `---------------' + +---------------+ '----------------' ``` - Optimizations. diff --git a/Cargo.lock b/Cargo.lock index e49388f..dd4f80e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -21,12 +21,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "anyhow" -version = "1.0.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7825f6833612eb2414095684fcf6c635becf3ce97fe48cf6421321e93bfbd53c" - [[package]] name = "approx" version = "0.3.2" @@ -65,12 +59,6 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" -[[package]] -name = "bumpalo" -version = "3.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5fb8038c1ddc0a5f73787b130f4cc75151e96ed33e417fde765eb5a81e3532f4" - [[package]] name = "cfg-if" version = "0.1.10" @@ -125,16 +113,6 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" -[[package]] -name = "futf" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c9c1ce3fa9336301af935ab852c437817d14cd33690446569392e65170aac3b" -dependencies = [ - "mac", - "new_debug_unreachable", -] - [[package]] name = "generic-array" version = "0.12.3" @@ -144,15 +122,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "getopts" -version = "0.2.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5" -dependencies = [ - "unicode-width", -] - [[package]] name = "handlebars" version = "0.21.1" @@ -165,15 +134,6 @@ dependencies = [ "rustc-serialize", ] -[[package]] -name = "heck" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205" -dependencies = [ - "unicode-segmentation", -] - [[package]] name = "hermit-abi" version = "0.1.6" @@ -183,20 +143,6 @@ dependencies = [ "libc", ] -[[package]] -name = "html5ever" -version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ce65ac8028cf5a287a7dbf6c4e0a6cf2dcf022ed5b167a81bae66ebf599a8b7" -dependencies = [ - "log 0.4.8", - "mac", - "markup5ever", - "proc-macro2 0.4.30", - "quote 0.6.13", - "syn 0.15.44", -] - [[package]] name = "itertools" version = "0.8.2" @@ -212,15 +158,6 @@ version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b8b7a7c0c47db5545ed3fef7468ee7bb5b74691498139e4b3f6a20685dc6dd8e" -[[package]] -name = "js-sys" -version = "0.3.35" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7889c7c36282151f6bf465be4700359318aef36baa951462382eae49e9577cf9" -dependencies = [ - "wasm-bindgen", -] - [[package]] name = "lazy_static" version = "1.4.0" @@ -257,29 +194,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "mac" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4" - -[[package]] -name = "markup5ever" -version = "0.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1af46a727284117e09780d05038b1ce6fc9c76cc6df183c3dae5a8955a25e21" -dependencies = [ - "log 0.4.8", - "phf", - "phf_codegen", - "serde", - "serde_derive", - "serde_json", - "string_cache", - "string_cache_codegen", - "tendril", -] - [[package]] name = "matrixmultiply" version = "0.2.3" @@ -295,12 +209,6 @@ version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "60302e4db3a61da70c0cb7991976248362f30319e88850c487b9b95bbf059e00" -[[package]] -name = "memchr" -version = "2.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3197e20c7edb283f87c071ddfc7a2cca8f8e0b888c242959846a6fce03c72223" - [[package]] name = "nalgebra" version = "0.18.1" @@ -337,22 +245,6 @@ dependencies = [ "smallvec", ] -[[package]] -name = "new_debug_unreachable" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e4a24736216ec316047a1fc4252e27dabb04218aa4a3f37c6e7ddbf1f9782b54" - -[[package]] -name = "nom" -version = "4.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ad2a91a8e869eeb30b9cb3119ae87773a8f4ae617f41b1eb9c154b2905f7bd6" -dependencies = [ - "memchr", - "version_check 0.1.5", -] - [[package]] name = "num-complex" version = "0.2.4" @@ -415,110 +307,18 @@ dependencies = [ "ordermap", ] -[[package]] -name = "phf" -version = "0.7.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3da44b85f8e8dfaec21adae67f95d93244b2ecf6ad2a692320598dcc8e6dd18" -dependencies = [ - "phf_shared", -] - -[[package]] -name = "phf_codegen" -version = "0.7.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b03e85129e324ad4166b06b2c7491ae27fe3ec353af72e72cd1654c7225d517e" -dependencies = [ - "phf_generator", - "phf_shared", -] - -[[package]] -name = "phf_generator" -version = "0.7.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09364cc93c159b8b06b1f4dd8a4398984503483891b0c26b867cf431fb132662" -dependencies = [ - "phf_shared", - "rand", -] - -[[package]] -name = "phf_shared" -version = "0.7.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "234f71a15de2288bcb7e3b6515828d22af7ec8598ee6d24c3b526fa0a80b67a0" -dependencies = [ - "siphasher", -] - [[package]] name = "pom" version = "3.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ef5cf7f52c12da93c26b63ee0d9f012bc82fb071851c546c030dc6ecb5f2994b" -[[package]] -name = "precomputed-hash" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" - -[[package]] -name = "proc-macro2" -version = "0.4.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759" -dependencies = [ - "unicode-xid 0.1.0", -] - -[[package]] -name = "proc-macro2" -version = "1.0.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3acb317c6ff86a4e579dfa00fc5e6cca91ecbb4e7eb2df0468805b674eb88548" -dependencies = [ - "unicode-xid 0.2.0", -] - -[[package]] -name = "pulldown-cmark" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77043da1282374688ee212dc44b3f37ff929431de9c9adc3053bd3cee5630357" -dependencies = [ - "bitflags", - "getopts", - "memchr", - "unicase", -] - [[package]] name = "quick-error" version = "1.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" -[[package]] -name = "quote" -version = "0.6.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ce23b6b870e8f94f81fb0a363d65d86675884b34a09043c81e5562f11c1f8e1" -dependencies = [ - "proc-macro2 0.4.30", -] - -[[package]] -name = "quote" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "053a8c8bcc71fcce321828dc897a98ab9760bef03a4fc36693c231e5b3216cfe" -dependencies = [ - "proc-macro2 1.0.8", -] - [[package]] name = "rand" version = "0.6.5" @@ -659,13 +459,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ee92eb275e1c4dd3d2f314cf162d67f9db7916436a59aebf93715c40d6818c16" dependencies = [ "cfg-if", - "js-sys", "lazy_static", "log 0.4.8", - "pulldown-cmark", "sauron_vdom 0.21.0", - "wasm-bindgen", - "web-sys", ] [[package]] @@ -689,17 +485,6 @@ version = "1.0.104" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "414115f25f818d7dfccec8ee535d76949ae78584fc4f79a6f45a904bf8ab4449" -[[package]] -name = "serde_derive" -version = "1.0.104" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "128f9e303a5a29922045a830221b8f78ec74a5f544944f3d5984f8ec3895ef64" -dependencies = [ - "proc-macro2 1.0.8", - "quote 1.0.2", - "syn 1.0.14", -] - [[package]] name = "serde_json" version = "1.0.46" @@ -711,12 +496,6 @@ dependencies = [ "serde", ] -[[package]] -name = "siphasher" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b8de496cf83d4ed58b6be86c3a275b8602f6ffe98d3024a869e124147a9a3ac" - [[package]] name = "slab" version = "0.4.2" @@ -732,46 +511,6 @@ dependencies = [ "maybe-uninit", ] -[[package]] -name = "sourcefile" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4bf77cb82ba8453b42b6ae1d692e4cdc92f9a47beaf89a847c8be83f4e328ad3" - -[[package]] -name = "string_cache" -version = "0.7.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89c058a82f9fd69b1becf8c274f412281038877c553182f1d02eb027045a2d67" -dependencies = [ - "lazy_static", - "new_debug_unreachable", - "phf_shared", - "precomputed-hash", - "serde", - "string_cache_codegen", - "string_cache_shared", -] - -[[package]] -name = "string_cache_codegen" -version = "0.4.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0f45ed1b65bf9a4bf2f7b7dc59212d1926e9eaf00fa998988e420fd124467c6" -dependencies = [ - "phf_generator", - "phf_shared", - "proc-macro2 1.0.8", - "quote 1.0.2", - "string_cache_shared", -] - -[[package]] -name = "string_cache_shared" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1884d1bc09741d466d9b14e6d37ac89d6909cbcac41dd9ae982d4d063bbedfc" - [[package]] name = "strsim" version = "0.8.0" @@ -782,7 +521,6 @@ checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" name = "svgbob" version = "0.5.0" dependencies = [ - "html5ever", "itertools", "lazy_static", "nalgebra", @@ -803,39 +541,6 @@ dependencies = [ "svgbob", ] -[[package]] -name = "syn" -version = "0.15.44" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ca4b3b69a77cbe1ffc9e198781b7acb0c7365a883670e8f1c1bc66fba79a5c5" -dependencies = [ - "proc-macro2 0.4.30", - "quote 0.6.13", - "unicode-xid 0.1.0", -] - -[[package]] -name = "syn" -version = "1.0.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af6f3550d8dff9ef7dc34d384ac6f107e5d31c8f57d9f28e0081503f547ac8f5" -dependencies = [ - "proc-macro2 1.0.8", - "quote 1.0.2", - "unicode-xid 0.2.0", -] - -[[package]] -name = "tendril" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "707feda9f2582d5d680d733e38755547a3e8fb471e7ba11452ecfd9ce93a5d3b" -dependencies = [ - "futf", - "mac", - "utf-8", -] - [[package]] name = "textwrap" version = "0.11.0" @@ -851,155 +556,18 @@ version = "1.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6d2783fe2d6b8c1101136184eb41be8b1ad379e4657050b8aaff0c79ee7575f9" -[[package]] -name = "unicase" -version = "2.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6" -dependencies = [ - "version_check 0.9.1", -] - -[[package]] -name = "unicode-segmentation" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e83e153d1053cbb5a118eeff7fd5be06ed99153f00dbcd8ae310c5fb2b22edc0" - [[package]] name = "unicode-width" version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "caaa9d531767d1ff2150b9332433f32a24622147e5ebb1f26409d5da67afd479" -[[package]] -name = "unicode-xid" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" - -[[package]] -name = "unicode-xid" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" - -[[package]] -name = "utf-8" -version = "0.7.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05e42f7c18b8f902290b009cde6d651262f956c98bc51bca4cd1d511c9cd85c7" - [[package]] name = "vec_map" version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a" -[[package]] -name = "version_check" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd" - -[[package]] -name = "version_check" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "078775d0255232fb988e6fccf26ddc9d1ac274299aaedcedce21c6f72cc533ce" - -[[package]] -name = "wasm-bindgen" -version = "0.2.58" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5205e9afdf42282b192e2310a5b463a6d1c1d774e30dc3c791ac37ab42d2616c" -dependencies = [ - "cfg-if", - "wasm-bindgen-macro", -] - -[[package]] -name = "wasm-bindgen-backend" -version = "0.2.58" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11cdb95816290b525b32587d76419facd99662a07e59d3cdb560488a819d9a45" -dependencies = [ - "bumpalo", - "lazy_static", - "log 0.4.8", - "proc-macro2 1.0.8", - "quote 1.0.2", - "syn 1.0.14", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-macro" -version = "0.2.58" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "574094772ce6921576fb6f2e3f7497b8a76273b6db092be18fc48a082de09dc3" -dependencies = [ - "quote 1.0.2", - "wasm-bindgen-macro-support", -] - -[[package]] -name = "wasm-bindgen-macro-support" -version = "0.2.58" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e85031354f25eaebe78bb7db1c3d86140312a911a106b2e29f9cc440ce3e7668" -dependencies = [ - "proc-macro2 1.0.8", - "quote 1.0.2", - "syn 1.0.14", - "wasm-bindgen-backend", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-shared" -version = "0.2.58" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f5e7e61fc929f4c0dddb748b102ebf9f632e2b8d739f2016542b4de2965a9601" - -[[package]] -name = "wasm-bindgen-webidl" -version = "0.2.58" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef012a0d93fc0432df126a8eaf547b2dce25a8ce9212e1d3cbeef5c11157975d" -dependencies = [ - "anyhow", - "heck", - "log 0.4.8", - "proc-macro2 1.0.8", - "quote 1.0.2", - "syn 1.0.14", - "wasm-bindgen-backend", - "weedle", -] - -[[package]] -name = "web-sys" -version = "0.3.35" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aaf97caf6aa8c2b1dac90faf0db529d9d63c93846cca4911856f78a83cebf53b" -dependencies = [ - "anyhow", - "js-sys", - "sourcefile", - "wasm-bindgen", - "wasm-bindgen-webidl", -] - -[[package]] -name = "weedle" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3bb43f70885151e629e2a19ce9e50bd730fd436cfd4b666894c9ce4de9141164" -dependencies = [ - "nom", -] - [[package]] name = "winapi" version = "0.3.8" diff --git a/svgbob/Cargo.toml b/svgbob/Cargo.toml index a7f2dfc..7210f63 100644 --- a/svgbob/Cargo.toml +++ b/svgbob/Cargo.toml @@ -9,8 +9,7 @@ publish = false nalgebra = "0.18.0" ncollide2d = "0.19.1" lazy_static = "1.3.0" -html5ever = "0.23.0" -sauron = { version = "0.21.0"} +sauron = { version = "0.21.0", default-features = false} unicode-width = "0.1.5" itertools = "0.8.0" pom = { version = "3.1.0" } diff --git a/svgbob/src/buffer/cell_buffer.rs b/svgbob/src/buffer/cell_buffer.rs index 55bb260..f60a79b 100644 --- a/svgbob/src/buffer/cell_buffer.rs +++ b/svgbob/src/buffer/cell_buffer.rs @@ -56,14 +56,18 @@ impl DerefMut for CellBuffer { impl CellBuffer { pub fn new() -> Self { - CellBuffer { map: BTreeMap::new(), css_styles: vec![] } + CellBuffer { + map: BTreeMap::new(), + css_styles: vec![], + } } pub fn add_css_styles(&mut self, css_styles: Vec<(String, String)>) { self.css_styles.extend(css_styles); } - /// Groups cell that are adjacents + /// Groups cell that are adjacents (cells that are next to each other, horizontally or + /// vertically) /// Note: using .rev() since this has a high change that the last cell is adjacent with the /// current cell tested pub fn group_adjacents(&self) -> Vec { @@ -89,7 +93,11 @@ impl CellBuffer { let original_len = adjacents.len(); let merged = Self::second_pass_merge(adjacents); // if has merged continue merging until nothing can be merged - if merged.len() < original_len { Self::merge_recursive(merged) } else { merged } + if merged.len() < original_len { + Self::merge_recursive(merged) + } else { + merged + } } /// second pass merge is operating on span comparing to other spans @@ -144,17 +152,23 @@ impl CellBuffer { // // vec_groups are not endorsed, but are still touching, these will be grouped together in // the svg node - let (vec_fragments, vec_contacts): (Vec>, Vec>) = - self.group_adjacents().into_iter().map(|span| span.endorse()).unzip(); - + let (vec_fragments, vec_contacts): (Vec>, Vec>) = self + .group_adjacents() + .into_iter() + .map(|span| span.endorse()) + .unzip(); // partition the vec_groups into groups that is alone and the group // that is contacting their parts - let (single_member, vec_groups): (Vec, Vec) = - vec_contacts.into_iter().flatten().partition(move |contacts| contacts.0.len() == 1); + let (single_member, vec_groups): (Vec, Vec) = vec_contacts + .into_iter() + .flatten() + .partition(move |contacts| contacts.0.len() == 1); - let single_member_fragments: Vec = - single_member.into_iter().flat_map(|contact| contact.0).collect(); + let single_member_fragments: Vec = single_member + .into_iter() + .flat_map(|contact| contact.0) + .collect(); let group_nodes: Vec> = vec_groups .into_iter() @@ -186,8 +200,10 @@ impl CellBuffer { } fn get_style(settings: &Settings, legend_css: String) -> Node<()> { - html::tags::style(vec![], vec![text(format!( - "line, path, circle,rect,polygon {{ + html::tags::style( + vec![], + vec![text(format!( + "line, path, circle,rect,polygon {{ stroke: {stroke_color}; stroke-width: {stroke_width}; stroke-opacity: 1; @@ -258,14 +274,15 @@ impl CellBuffer { {legend_css} ", - background = settings.background, - fill_color = settings.fill_color, - stroke_color = settings.stroke_color, - stroke_width = settings.stroke_width, - font_size = settings.font_size, - font_family = settings.font_family, - legend_css = legend_css, - ))]) + background = settings.background, + fill_color = settings.fill_color, + stroke_color = settings.stroke_color, + stroke_width = settings.stroke_width, + font_size = settings.font_size, + font_family = settings.font_family, + legend_css = legend_css, + ))], + ) } /// convert the fragments into svg nodes using the supplied settings, with size for the @@ -277,28 +294,38 @@ impl CellBuffer { w: f32, h: f32, ) -> Node<()> { - let fragments_scaled: Vec = - fragments.into_iter().map(|frag| frag.scale(settings.scale)).collect(); + let fragments_scaled: Vec = fragments + .into_iter() + .map(|frag| frag.scale(settings.scale)) + .collect(); let fragment_nodes: Vec> = FragmentTree::fragments_to_node(fragments_scaled); - - let svg_node = svg(vec![xmlns("http://www.w3.org/2000/svg"), width(w), height(h)], vec![ - Self::get_style(settings, legend_css), - Self::get_defs(), - rect(vec![class("backdrop"), x(0), y(0), width(w), height(h)], vec![]), - ]) + let svg_node = svg( + vec![xmlns("http://www.w3.org/2000/svg"), width(w), height(h)], + vec![ + Self::get_style(settings, legend_css), + Self::get_defs(), + rect( + vec![class("backdrop"), x(0), y(0), width(w), height(h)], + vec![], + ), + ], + ) .add_children(fragment_nodes); svg_node } fn get_defs() -> Node<()> { - defs(vec![], vec![ - Self::arrow_marker(), - Self::diamond_marker(), - Self::circle_marker(), - Self::open_circle_marker(), - Self::big_open_circle_marker(), - ]) + defs( + vec![], + vec![ + Self::arrow_marker(), + Self::diamond_marker(), + Self::circle_marker(), + Self::open_circle_marker(), + Self::big_open_circle_marker(), + ], + ) } fn arrow_marker() -> Node<()> { @@ -342,7 +369,10 @@ impl CellBuffer { markerHeight(7), orient("auto-start-reverse"), ], - vec![circle(vec![cx(4), cy(4), r(2), html::attributes::class("bg_filled")], vec![])], + vec![circle( + vec![cx(4), cy(4), r(2), html::attributes::class("bg_filled")], + vec![], + )], ) } @@ -357,7 +387,10 @@ impl CellBuffer { markerHeight(7), orient("auto-start-reverse"), ], - vec![circle(vec![cx(4), cy(4), r(2), html::attributes::class("filled")], vec![])], + vec![circle( + vec![cx(4), cy(4), r(2), html::attributes::class("filled")], + vec![], + )], ) } @@ -372,12 +405,14 @@ impl CellBuffer { markerHeight(7), orient("auto-start-reverse"), ], - vec![circle(vec![cx(4), cy(4), r(3), html::attributes::class("bg_filled")], vec![])], + vec![circle( + vec![cx(4), cy(4), r(3), html::attributes::class("bg_filled")], + vec![], + )], ) } } - impl fmt::Display for CellBuffer { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { writeln!(f, "CellBuffer dump..")?; @@ -428,7 +463,6 @@ impl From for CellBuffer { mod tests { use super::*; - #[test] fn test_simple_adjacents() { let art = r#" -- cgit v1.2.3