1 /* 2 * multi_curve.h 3 * DIN Is Noise is copyright (c) 2006-2021 Jagannathan Sampath 4 * DIN Is Noise is released under GNU Public License 2.0 5 * For more information, please visit https://dinisnoise.org/ 6 */ 7 8 9 #ifndef __MULTICURVE__ 10 #define __MULTICURVE__ 11 12 #include <string> 13 #include <fstream> 14 #include <vector> 15 16 #include "point.h" 17 #include "curve.h" 18 #include "box.h" 19 20 typedef std::vector< point<float> > points_array; 21 22 struct multi_curve { 23 24 // multiple bezier curves 25 // 26 27 std::vector<curve> curv; // bezier curves of this multi_curve 28 29 // curve components 30 points_array vertices; 31 points_array left_tangents; 32 points_array right_tangents; 33 int num_vertices; 34 int last_vertex; 35 36 multi_curve (); 37 multi_curve (const std::string& filename); 38 39 void clear (int all = 1); // all => color & name 40 41 // vertex ops 42 void add_vertex (float x, float y); 43 int insert (float x, float y, float tx, float ty); 44 int remove (int i); 45 int set_vertex (int i, float x, float y, int carry_tangents = 0); 46 void get_vertex (int i, float& x, float& y); 47 48 // tangent ops 49 void add_left_tangent (float x, float y); 50 void add_right_tangent (float x, float y); 51 void get_left_tangent (int i, float& x, float& y); 52 void get_right_tangent (int i, float& x, float& y); 53 int set_left_tangent (int i, float x, float y); 54 int set_right_tangent (int i, float x, float y); 55 56 float limit; // same for all curves (see curve.h) 57 void set_limit (float d); 58 59 int shapeform; // shapeform? 60 void set_shapeform (int yesno); 61 void check_shapeform (); 62 void get_xy (double d, float& x, float& y); 63 64 void require_eval (); 65 void evaluate (); // compute latest profile of bezier curves 66 67 // profile 68 void get_profile_points (std::vector<crvpt>& profile); // all curves 69 std::vector<crvpt>& get_profile_points (int i); // for ith curve 70 int get_total_points (); 71 72 // xform 73 enum {SET=1, CALC}; 74 int centroid_style; 75 float scx, scy; // set centroid 76 float cx, cy; // calced centroid 77 void calc_centroid (); set_centroidmulti_curve78 inline void set_centroid (float x, float y) { cx = x; cy = y; } 79 void calc_bbox (box<float>& b); 80 void rotate (point<float>& p, float angle); 81 void rotate (float angle); 82 void scale (point<float>& p, float sx, float sy); 83 void scale (float sx, float sy); 84 85 // visual 86 float r, g, b; // color of profile 87 float rt, gt, bt; // color of tangents 88 void set_color (); // random color 89 void set_color (float rr, float gg, float bb); get_colormulti_curve90 void get_color (float& rr, float& gg, float& bb) { rr = r; gg = g; bb = b;} 91 void calc_tangent_color (); 92 93 // utils 94 std::string name; // name 95 void set_name (const std::string& name); 96 void load (const std::string& filename); 97 void load (std::ifstream& file); 98 void save (const std::string& filename); 99 void save (std::ofstream& file); 100 101 }; 102 103 104 105 void create_polyline (multi_curve& crv, const points_array& pts); 106 void convert2_polyline (multi_curve& crv); 107 void convert2_catmull_rom (multi_curve& crv, float tangent_size); 108 multi_curve* get_curve (const std::string& name); 109 multi_curve* check_list (multi_curve** lst, int n, const std::string& name); 110 111 #endif 112