tuanchauict / MonoSketch

An ASCII graph drawing app
https://monosketch.io
Apache License 2.0
367 stars 9 forks source link

Simplify crossing point algorithm and allow complex combination to joinable #588

Closed tuanchauict closed 5 months ago

tuanchauict commented 5 months ago

Instead of having a database of combinable characters, the new algorithm uses bit-wise to detect the crossing characters.

A character is converted into 12-bit number of 3 groups of format (single, bold, double). Each group contains 4 bits representing 4 directions: [bottom, top, right, left]

 DOUBLE          SINGLE             
╠═══════╣       ├───────┤  B: Bottom
┌─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┐  T: Top   
│B│T│R│L│B│T│R│L│B│T│R│L│  R: Right 
└─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┘  L: Left  
        ┣━━━━━━━┫                   
          BOLD                      

This also allows complex combinations of single-bold and single-double chars to connect

╓───────┒
║       ┃
╟───────┨
║       ┃
╙───────┚

TODO: new complex combination characters (such as ) are not used as possible surrounding yet.

tuanchauict commented 5 months ago

Deployed to alpha https://alpha.monosketch.io/