1 /* 2 Gri - A language for scientific graphics programming 3 Copyright (C) 2008 Daniel Kelley 4 5 This program is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published by 7 the Free Software Foundation; version 3 of the License, or 8 (at your option) any later version. 9 10 This program is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License along 16 with this program; if not, write to the Free Software Foundation, Inc., 17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 */ 19 20 // GriPath -- store PostScript path 21 #if !defined(_GriPath_hh_) 22 #define _GriPath_hh_ 23 #include "types.hh" 24 #include "gr_coll.hh" 25 class GriPath 26 { 27 public: 28 enum type {moveto, lineto}; 29 GriPath(); 30 GriPath(unsigned capacity); 31 ~GriPath(); 32 void clear(); // Allows reuse without realloc 33 void expand(); // Get more space 34 void push_back(double xx, double yy, char aa); // Append at end 35 unsigned size(); // Return length of path 36 void trim(); // remove extraneous moveto commands 37 void stroke(units u, double width = -1, bool closepath = false); // Stroke the path 38 void stroke_or_fill(char s_or_f, units u, double width = -1, bool closepath = false); // Stroke or fill 39 void fill(units u, bool closepath = false); // Fill path in 40 void print(); // Mostly for debugging 41 void translate(double dx, double dy); // Only makes sense if units_cm 42 void scale(double enlargement); // Only makes sense if units_cm 43 void rotate(double degrees); // Rotate anticlockwise get_x(unsigned offset)44 double get_x(unsigned offset) {return x[offset];} // bug: no checking get_y(unsigned offset)45 double get_y(unsigned offset) {return y[offset];} // no checking 46 rectangle bounding_box(units u); 47 private: 48 unsigned int depth; // Length of path 49 unsigned int capacity; // Max elements in path; see expand\(\) 50 double *x; // Data 51 double *y; // Data 52 type *action; // 'm' or 'l' 53 }; 54 #endif 55