00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef COUTLN_H
00021 #define COUTLN_H
00022
00023 #include "crakedge.h"
00024 #include "mod128.h"
00025 #include "bits16.h"
00026 #include "rect.h"
00027 #include "blckerr.h"
00028 #include "scrollview.h"
00029
00030 #define INTERSECTING MAX_INT16//no winding number
00031
00032
00033 #define STEP_MASK 3
00034
00035 enum C_OUTLINE_FLAGS
00036 {
00037 COUT_INVERSE
00038 };
00039
00040 class DLLSYM C_OUTLINE;
00041
00042 ELISTIZEH_S (C_OUTLINE)
00043 class DLLSYM C_OUTLINE:public ELIST_LINK
00044 {
00045 public:
00046 C_OUTLINE() {
00047 steps = NULL;
00048 }
00049 C_OUTLINE(
00050 CRACKEDGE *startpt,
00051 ICOORD bot_left,
00052 ICOORD top_right,
00053 inT16 length);
00054 C_OUTLINE(ICOORD startpt,
00055 DIR128 *new_steps,
00056 inT16 length);
00057
00058 C_OUTLINE(C_OUTLINE *srcline, FCOORD rotation);
00059
00060
00061 static void FakeOutline(const TBOX& box, C_OUTLINE_LIST* outlines);
00062
00063 ~C_OUTLINE () {
00064 if (steps != NULL)
00065 free_mem(steps);
00066 steps = NULL;
00067 }
00068
00069 BOOL8 flag(
00070 C_OUTLINE_FLAGS mask) const {
00071 return flags.bit (mask);
00072 }
00073 void set_flag(
00074 C_OUTLINE_FLAGS mask,
00075 BOOL8 value) {
00076 flags.set_bit (mask, value);
00077 }
00078
00079 C_OUTLINE_LIST *child() {
00080 return &children;
00081 }
00082
00083
00084 const TBOX &bounding_box() const {
00085 return box;
00086 }
00087 void set_step(
00088 inT16 stepindex,
00089 inT8 stepdir) {
00090 int shift = stepindex%4 * 2;
00091 uinT8 mask = 3 << shift;
00092 steps[stepindex/4] = ((stepdir << shift) & mask) |
00093 (steps[stepindex/4] & ~mask);
00094
00095 }
00096 void set_step(
00097 inT16 stepindex,
00098 DIR128 stepdir) {
00099
00100 inT8 chaindir = stepdir.get_dir() >> (DIRBITS - 2);
00101
00102 set_step(stepindex, chaindir);
00103
00104 }
00105
00106
00107 const ICOORD &start_pos() const {
00108 return start;
00109 }
00110 inT32 pathlength() const {
00111 return stepcount;
00112 }
00113
00114 DIR128 step_dir(inT16 index) const {
00115 return DIR128((inT16)(((steps[index/4] >> (index%4 * 2)) & STEP_MASK) <<
00116 (DIRBITS - 2)));
00117 }
00118
00119 ICOORD step(inT16 index) const {
00120 return step_coords[(steps[index/4] >> (index%4 * 2)) & STEP_MASK];
00121 }
00122
00123 inT32 area();
00124 inT32 perimeter();
00125 inT32 outer_area();
00126 inT32 count_transitions(
00127 inT32 threshold);
00128
00129 BOOL8 operator< (
00130 const C_OUTLINE & other) const;
00131 BOOL8 operator> (
00132 C_OUTLINE & other) const
00133 {
00134 return other < *this;
00135 }
00136 inT16 winding_number(
00137 ICOORD testpt) const;
00138
00139 inT16 turn_direction() const;
00140 void reverse();
00141
00142 void move(
00143 const ICOORD vec);
00144
00145
00146
00147
00148
00149
00150 void RemoveSmallRecursive(int min_size, C_OUTLINE_IT* it);
00151
00152 void plot(
00153 ScrollView* window,
00154 ScrollView::Color colour) const;
00155
00156 void prep_serialise() {
00157 children.prep_serialise ();
00158 }
00159
00160 void dump(
00161 FILE *f) {
00162
00163 serialise_bytes (f, (void *) steps, step_mem());
00164 children.dump (f);
00165 }
00166
00167 void de_dump(
00168 FILE *f) {
00169 steps = (uinT8 *) de_serialise_bytes (f, step_mem());
00170 children.de_dump (f);
00171 }
00172
00173
00174 make_serialise (C_OUTLINE)
00175
00176 C_OUTLINE& operator=(const C_OUTLINE& source);
00177
00178 static C_OUTLINE* deep_copy(const C_OUTLINE* src) {
00179 C_OUTLINE* outline = new C_OUTLINE;
00180 *outline = *src;
00181 return outline;
00182 }
00183
00184 static ICOORD chain_step(int chaindir);
00185
00186 private:
00187 int step_mem() const { return (stepcount+3) / 4; }
00188
00189 TBOX box;
00190 ICOORD start;
00191 uinT8 *steps;
00192 inT16 stepcount;
00193 BITS16 flags;
00194 C_OUTLINE_LIST children;
00195 static ICOORD step_coords[4];
00196 };
00197 #endif