1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#![allow(dead_code)]
#![allow(unused_variables)]
use crate::Point;

mod canvas;
mod fillers;
mod generator;
pub(crate) mod geometry;
mod math;
mod renderer;
mod svg;

pub use canvas::RoughCanvas;
pub use fillers::*;
pub use generator::RoughGenerator;
pub use math::*;
pub use renderer::*;
pub use svg::*;

pub const SVGNS: &str = "http://www.w3.org/2000/svg";

#[derive(Default, Clone)]
pub struct RoughConfig {
  pub options: RoughOptions
}

// export interface DrawingSurface {
//   width: f64 | SVGAnimatedLength;
//   height: f64 | SVGAnimatedLength;
// }

// extends Options
#[derive(Clone)]
pub struct RoughOptions {
  // Options
  max_randomness_offset: f64,
  roughness: f64,
  bowing: f64,
  stroke: String,
  stroke_width: f64,
  curve_fitting: f64,
  curve_tightness: f64,
  curve_step_count: f64,
  fill: String,
  fill_style: String,
  fill_weight: f64,
  hachure_angle: f64,
  hachure_gap: f64,
  simplification: f64,
  dash_offset: f64,
  dash_gap: f64,
  zigzag_offset: f64,
  seed: f64,
  combine_nested_svg_paths: bool,
  stroke_line_dash: Option<Vec<f64>>,
  stroke_line_dash_offset: f64,
  fill_line_dash: Option<Vec<f64>>,
  fill_line_dash_offset: f64,
  disable_multi_stroke: bool,
  disable_multi_stroke_fill: bool,
  // randomizer?: Random;
}

impl Default for RoughOptions {
  fn default() -> Self {
    Self {
      max_randomness_offset: 2.0,
      roughness: 1.0,
      bowing: 1.0,
      stroke: "#000".into(),
      stroke_width: 1.0,
      curve_fitting: 0.95,
      curve_tightness: 0.0,
      curve_step_count: 9.0,
      fill: "".into(),
      fill_style: "hachure".into(),
      fill_weight: -1.0,
      hachure_angle: -41.0,
      hachure_gap: -1.0,
      simplification: 0.0,
      dash_offset: -1.0,
      dash_gap: -1.0,
      zigzag_offset: -1.0,
      seed: 0.0,
      combine_nested_svg_paths: false,
      stroke_line_dash: None,
      stroke_line_dash_offset: 0.0,
      fill_line_dash: None,
      fill_line_dash_offset: 0.0,
      disable_multi_stroke: false,
      disable_multi_stroke_fill: false,
    }
  }
}

#[derive(PartialEq, Eq)]
pub enum OpType {
  Move,
  BCurveTo,
  LineTo
}

#[derive(PartialEq, Eq, Debug)]
pub enum OpSetType {
  Path,
  FillPath,
  FillSketch,
}

pub struct Op {
  op: OpType,
  data: Vec<f64>,
}

pub struct OpSet {
  pub kind: OpSetType,
  pub ops: Vec<Op>,
  pub size: Option<Point<f64>>,
  pub path: Option<String>,
}

pub enum DrawableType {
  Line,
  Rectangle,
  Ellipse,
  Circle,
  LinearPath,
  Arc,
  Curve,
  Polygon,
  Path,
}

pub struct Drawable<'a> {
  pub shape: DrawableType,
  pub options: &'a RoughOptions,
  pub sets: Vec<OpSet>,
}

pub struct PathInfo {
  pub d: String,
  pub stroke: String,
  pub stroke_width: f64,
  pub fill: Option<String>,
}