diff --git a/agg/agg_basics.java b/agg/agg_basics.java new file mode 100644 index 000000000..e856c61f2 --- /dev/null +++ b/agg/agg_basics.java @@ -0,0 +1,150 @@ +package agg; + + +public class agg_basics { + + /* + typedef unsigned char cover_type; //----cover_type + enum cover_scale_e + { + cover_shift = 8, //----cover_shift + cover_size = 1 << cover_shift, //----cover_size + cover_mask = cover_size - 1, //----cover_mask + cover_none = 0, //----cover_none + cover_full = cover_mask //----cover_full + }; + */ + public static final int cover_shift = 8; + public static final int cover_size = 1 << cover_shift; + public static final int cover_mask = cover_size - 1; + public static final int cover_none = 0; + public static final int cover_full = cover_mask; + + /* + const double pi = 3.14159265358979323846; + + inline double deg2rad(double deg) + { + return deg * pi / 180.0; + } + + inline double rad2deg(double rad) + { + return rad * 180.0 / pi; + } + */ + + public static final int path_cmd_stop = 0; + public static final int path_cmd_move_to = 1; + public static final int path_cmd_line_to = 2; + public static final int path_cmd_curve3 = 3; + public static final int path_cmd_curve4 = 4; + public static final int path_cmd_curveN = 5; + public static final int path_cmd_catrom = 6; + public static final int path_cmd_ubspline = 7; + public static final int path_cmd_end_poly = 0x0F; + public static final int path_cmd_mask = 0x0F; + + public static final int path_flags_none = 0; + public static final int path_flags_ccw = 0x10; + public static final int path_flags_cw = 0x20; + public static final int path_flags_close = 0x40; + public static final int path_flags_mask = 0xF0; + + + final static public boolean is_vertex(unsigned c) { + return c >= path_cmd_move_to && c < path_cmd_end_poly; + } + + + final static public boolean is_drawing(unsigned c) { + return c >= path_cmd_line_to && c < path_cmd_end_poly; + } + + + final static public boolean is_stop(unsigned c) { + return c == path_cmd_stop; + } + + + final static public boolean is_move_to(unsigned c) { + return c == path_cmd_move_to; + } + + + final static public boolean is_line_to(unsigned c) { + return c == path_cmd_line_to; + } + + + final static public boolean is_curve(unsigned c) { + return c == path_cmd_curve3 || c == path_cmd_curve4; + } + + + final static public boolean is_curve3(unsigned c) { + return c == path_cmd_curve3; + } + + + final static public boolean is_curve4(unsigned c) { + return c == path_cmd_curve4; + } + + + final static public boolean is_end_poly(unsigned c) { + return (c & path_cmd_mask) == path_cmd_end_poly; + } + + + final static public boolean is_close(int c) { // un + return (c & ~(path_flags_cw | path_flags_ccw)) == + (path_cmd_end_poly | path_flags_close); + } + + + final static public boolean is_next_poly(int c) { // un + return is_stop(c) || is_move_to(c) || is_end_poly(c); + } + + + final static public boolean is_cw(int c) { // un + return (c & path_flags_cw) != 0; + } + + + final static public boolean is_ccw(int c) { // un + return (c & path_flags_ccw) != 0; + } + + + final static public boolean is_oriented(int c) { // un + return (c & (path_flags_cw | path_flags_ccw)) != 0; + } + + + final static public boolean is_closed(int c) { // un + return (c & path_flags_close) != 0; + } + + + final static public int get_close_flag(int c) { // un + return c & path_flags_close; + } + + + final static public int clear_orientation(int c) { // un + return c & ~(path_flags_cw | path_flags_ccw); + } + + + final static public int get_orientation(int c) { // un + return c & (path_flags_cw | path_flags_ccw); + } + + + final static public int set_orientation(int c, int o) { // un + return clear_orientation(c) | o; + } +} + diff --git a/agg/point_type.java b/agg/point_type.java new file mode 100644 index 000000000..05cb357f1 --- /dev/null +++ b/agg/point_type.java @@ -0,0 +1,12 @@ +package agg; + +public class point_type { + float x, y; + + public point_type() { } + + public point_type(float x_, float y_) { + x = x_; + y = y_; + } +} diff --git a/agg/rect.java b/agg/rect.java new file mode 100644 index 000000000..dee1f19eb --- /dev/null +++ b/agg/rect.java @@ -0,0 +1,127 @@ +package agg; + + +public class rect { + + float x1, y1, x2, y2; + + + public rect() { + } + + + public rect(float x1_, float y1_, float x2_, float y2_) { + x1 = x1_; + y1 = y1_; + x2 = x2_; + y2 = y2_; + } + + + public rect normalize() { + if (x1 > x2) { + float t = x1; x1 = x2; x2 = t; + } + if (y1 > y2) { + float t = y1; y1 = y2; y2 = t; + } + } + + + public boolean clip(rect r) { + if (x2 > r.x2) x2 = r.x2; + if (y2 > r.y2) y2 = r.y2; + if (x1 < r.x1) x1 = r.x1; + if (y1 < r.y1) y1 = r.y1; + return x1 <= x2 && y1 <= y2; + } + + + public boolean is_valid() { + return x1 <= x2 && y1 <= y2; + } + + + /* + template struct rect_base + { + typedef rect_base self_type; + T x1; + T y1; + T x2; + T y2; + + rect_base() {} + rect_base(T x1_, T y1_, T x2_, T y2_) : + x1(x1_), y1(y1_), x2(x2_), y2(y2_) {} + + const self_type& normalize() + { + T t; + if(x1 > x2) { t = x1; x1 = x2; x2 = t; } + if(y1 > y2) { t = y1; y1 = y2; y2 = t; } + return *this; + } + + bool clip(const self_type& r) + { + if(x2 > r.x2) x2 = r.x2; + if(y2 > r.y2) y2 = r.y2; + if(x1 < r.x1) x1 = r.x1; + if(y1 < r.y1) y1 = r.y1; + return x1 <= x2 && y1 <= y2; + } + + bool is_valid() const + { + return x1 <= x2 && y1 <= y2; + } + }; + */ + + + static final public rect intersect_rectangles(rect r1, rect r2) { + rect r = new rect(r1); + + if (r.x2 > r2.x2) r.x2 = r2.x2; + if (r.y2 > r2.y2) r.y2 = r2.y2; + if (r.x1 < r2.x1) r.x1 = r2.x1; + if (r.y1 < r2.y1) r.y1 = r2.y1; + return r; + } + + + /* + template + inline Rect intersect_rectangles(const Rect& r1, const Rect& r2) + { + Rect r = r1; + + // First process x2,y2 because the other order + // results in Internal Compiler Error under + // Microsoft Visual C++ .NET 2003 69462-335-0000007-18038 in + // case of "Maximize Speed" optimization option. + //----------------- + if(r.x2 > r2.x2) r.x2 = r2.x2; + if(r.y2 > r2.y2) r.y2 = r2.y2; + if(r.x1 < r2.x1) r.x1 = r2.x1; + if(r.y1 < r2.y1) r.y1 = r2.y1; + return r; + } + */ + + + static final public rect unite_rectangles(rect r1, rect r2) { + rect r = new rect(r1); + if(r.x2 < r2.x2) r.x2 = r2.x2; + if(r.y2 < r2.y2) r.y2 = r2.y2; + if(r.x1 > r2.x1) r.x1 = r2.x1; + if(r.y1 > r2.y1) r.y1 = r2.y1; + return r; + } + + /* + typedef rect_base rect; //----rect + typedef rect_base rect_d; //----rect_d + */ +} \ No newline at end of file diff --git a/agg/vertex_type.java b/agg/vertex_type.java new file mode 100644 index 000000000..626c5f644 --- /dev/null +++ b/agg/vertex_type.java @@ -0,0 +1,15 @@ +package agg; + + +public class vertex_type { + float x, y; + int cmd; // un + + public vertex_type() { } + + public vertex_type(double x_, double y_, unsigned cmd_) { + x = x_; + y = y_; + cmd = cmd_; + } +}