#include "blobs.h"
#include "chop.h"
#include <math.h>
Go to the source code of this file.
#define closest | ( | test_p, | |||
p1, | |||||
p2 | ) |
Value:
(p1 ? \ (p2 ? \ ((dist_square (test_p->pos, p1->pos) < \ dist_square (test_p->pos, p2->pos)) ? \ p1 : \ p2) : \ p1) : \ p2)
All three parameters must be of type EDGEPT.
Definition at line 66 of file outlines.h.
Referenced by near_point().
#define dist_square | ( | p1, | |||
p2 | ) |
Value:
((p2.x - p1.x) * (p2.x - p1.x) + \ (p2.y - p1.y) * (p2.y - p1.y))
Definition at line 55 of file outlines.h.
#define edgept_dist | ( | p1, | |||
p2 | ) | (dist_square ((p1)->pos, (p2)->pos)) |
Return the distance (squared) between the two edge points.
Definition at line 80 of file outlines.h.
Referenced by pick_close_point(), and vertical_projection_point().
#define is_equal | ( | p1, | |||
p2 | ) | (((p1).x == (p2).x) && ((p1).y == (p2).y)) |
Return TRUE if the POINTs are equal.
Definition at line 97 of file outlines.h.
#define is_exterior_point | ( | edge, | |||
point | ) |
Value:
(same_point (edge->prev->pos, point->pos) || \ same_point (edge->next->pos, point->pos) || \ (angle_change (edge->prev, edge, edge->next) - \ angle_change (edge->prev, edge, point) > 20))
Definition at line 87 of file outlines.h.
Referenced by pick_close_point(), and try_point_pairs().
#define is_on_line | ( | p, | |||
p0, | |||||
p1 | ) |
Value:
(within_range ((p).x, (p0).x, (p1).x) && \ within_range ((p).y, (p0).y, (p1).y))
The two end points are included as part of the line. The parameters must be of type POINT.
Definition at line 108 of file outlines.h.
Referenced by near_point().
#define LARGE_DISTANCE 100000 |
Used for closest dist
Definition at line 32 of file outlines.h.
Referenced by vertical_projection_point().
#define MAX_ASPECT_RATIO 2.5 |
Widest character
Definition at line 36 of file outlines.h.
#define MIN_BLOB_SIZE 10 |
Big units
Definition at line 34 of file outlines.h.
#define same_point | ( | p1, | |||
p2 | ) |
Value:
((abs (p1.x - p2.x) < same_distance) && \ (abs (p1.y - p2.y) < same_distance))
Definition at line 46 of file outlines.h.
Referenced by near_point(), pick_close_point(), and vertical_projection_point().
#define within_range | ( | x, | |||
x0, | |||||
x1 | ) | (((x0 <= x) && (x <= x1)) || ((x1 <= x) && (x <= x0))) |
Return TRUE if the first number is in between the second two numbers. Return FALSE otherwise.
Definition at line 118 of file outlines.h.
Check to see if this line crosses over this outline.
If it does return TRUE.
Definition at line 39 of file outlines.cpp.
References FALSE, is_crossed(), edgeptstruct::next, edgeptstruct::pos, and TRUE.
Referenced by constrained_split().
00041 { /* Outline to check */ 00042 EDGEPT *pt = outline; 00043 do { 00044 if (is_crossed (p0->pos, p1->pos, pt->pos, pt->next->pos)) 00045 return (TRUE); 00046 pt = pt->next; 00047 } 00048 while (pt != outline); 00049 return (FALSE); 00050 }
Return TRUE when the two line segments cross each other.
Find out where the projected lines would cross and then check to see if the point of intersection lies on both of the line segments. If it does then these two segments cross.
Definition at line 61 of file outlines.cpp.
References CROSS, TPOINT::x, and TPOINT::y.
Referenced by crosses_outline().
00061 { 00062 int b0a1xb0b1, b0b1xb0a0; 00063 int a1b1xa1a0, a1a0xa1b0; 00064 00065 TPOINT b0a1, b0a0, a1b1, b0b1, a1a0; 00066 00067 b0a1.x = a1.x - b0.x; 00068 b0a0.x = a0.x - b0.x; 00069 a1b1.x = b1.x - a1.x; 00070 b0b1.x = b1.x - b0.x; 00071 a1a0.x = a0.x - a1.x; 00072 b0a1.y = a1.y - b0.y; 00073 b0a0.y = a0.y - b0.y; 00074 a1b1.y = b1.y - a1.y; 00075 b0b1.y = b1.y - b0.y; 00076 a1a0.y = a0.y - a1.y; 00077 00078 b0a1xb0b1 = CROSS (b0a1, b0b1); 00079 b0b1xb0a0 = CROSS (b0b1, b0a0); 00080 a1b1xa1a0 = CROSS (a1b1, a1a0); 00081 /*a1a0xa1b0=CROSS(a1a0,a1b0); */ 00082 a1a0xa1b0 = -CROSS (a1a0, b0a1); 00083 00084 return (b0a1xb0b1 > 0 && b0b1xb0a0 > 0 00085 || b0a1xb0b1 < 0 && b0b1xb0a0 < 0) 00086 && (a1b1xa1a0 > 0 && a1a0xa1b0 > 0 || a1b1xa1a0 < 0 && a1a0xa1b0 < 0); 00087 }
Return true if the points are identical.
Definition at line 94 of file outlines.cpp.
Referenced by is_little_chunk(), and is_small_area().
Find the point on a line segment that is closest to a point not on the line segment; return that point.
Definition at line 104 of file outlines.cpp.
References closest, is_on_line, make_edgept(), edgeptstruct::pos, same_point, TPOINT::x, and TPOINT::y.
Referenced by vertical_projection_point().
00104 { 00105 TPOINT p; 00106 00107 float slope; 00108 float intercept; 00109 00110 float x0 = line_pt_0->pos.x; 00111 float x1 = line_pt_1->pos.x; 00112 float y0 = line_pt_0->pos.y; 00113 float y1 = line_pt_1->pos.y; 00114 00115 if (x0 == x1) { 00116 /* Handle vertical line */ 00117 p.x = (INT16) x0; 00118 p.y = point->pos.y; 00119 } 00120 else { 00121 /* Slope and intercept */ 00122 slope = (y0 - y1) / (x0 - x1); 00123 intercept = y1 - x1 * slope; 00124 00125 /* Find perpendicular */ 00126 p.x = (INT16) ((point->pos.x + (point->pos.y - intercept) * slope) / 00127 (slope * slope + 1)); 00128 p.y = (INT16) (slope * p.x + intercept); 00129 } 00130 00131 if (is_on_line (p, line_pt_0->pos, line_pt_1->pos) && 00132 (!same_point (p, line_pt_0->pos)) && (!same_point (p, line_pt_1->pos))) 00133 /* Intersection on line */ 00134 return (make_edgept (p.x, p.y, line_pt_1, line_pt_0)); 00135 else /* Intersection not on line */ 00136 return (closest (point, line_pt_0, line_pt_1)); 00137 }
void reverse_outline | ( | EDGEPT * | outline | ) |
Change the direction of the outline.
If it was clockwise make it counter-clockwise and vice versa. Do this by swapping each of the next and prev fields of each edge point.
Definition at line 147 of file outlines.cpp.
References edgeptstruct::next, edgeptstruct::pos, edgeptstruct::prev, edgeptstruct::vec, TPOINT::x, and TPOINT::y.
00147 { 00148 EDGEPT *edgept = outline; 00149 EDGEPT *temp; 00150 00151 do { 00152 /* Swap next and prev */ 00153 temp = edgept->prev; 00154 edgept->prev = edgept->next; 00155 edgept->next = temp; 00156 /* Set up vec field */ 00157 edgept->vec.x = edgept->next->pos.x - edgept->pos.x; 00158 edgept->vec.y = edgept->next->pos.y - edgept->pos.y; 00159 00160 edgept = edgept->prev; /* Go to next point */ 00161 } 00162 while (edgept != outline); 00163 }