Changeset 20579 for trunk/magic/remove/src/Line.c
- Timestamp:
- Nov 7, 2008, 3:02:01 PM (18 years ago)
- File:
-
- 1 edited
-
trunk/magic/remove/src/Line.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/magic/remove/src/Line.c
r20308 r20579 39 39 (tuple->y >= line->end.y && 40 40 tuple->y <= line->begin.y); 41 } 42 43 double DistanceSquared (Line* line, double x, double y) 44 { 45 // Define U as the vector from the line segment start to end 46 // Define V as the vector from the line segment start to the tuple 47 // Define W as the vector from the line segment end to the tuple 48 49 double ux, uy, vx, vy, b, px, py; 50 ux = line->end.x - line->begin.x; 51 uy = line->end.y - line->begin.y; 52 53 vx = x - line->begin.x; 54 vy = y - line->begin.y; 55 56 double u_u = ux * ux + uy * uy; // (u . u) 57 double u_v = ux * vx + uy * vy; // (u . v) 58 59 if (u_v <= 0) return vx * vx + vy * vy; // (v . v) 60 if (u_u <= u_v) 61 { 62 double wx = x - line->end.x; 63 double wy = y - line->end.y; 64 return wx * wx + wy * wy; // (w . w) 65 } 66 67 // Compute P(b) is the base of the perpendicular dropped from tuple to 68 // the line 69 70 b = u_v / u_u; 71 px = vx - b * ux; 72 py = vy - b * uy; 73 return px * px + py * py; // norm (p) 41 74 } 42 75 … … 286 319 for (y = yBegin; y != yEnd; ++y) 287 320 { 288 if ( (x * x + y *y) <= halfWidth2)321 if (DistanceSquared (line, x, y) <= halfWidth2) 289 322 { 290 323 pixel = psAlloc (sizeof(PixelPos)); … … 333 366 for (x = xBegin; x != xEnd; ++x) 334 367 { 335 if ( (x * x + y *y) <= halfWidth2)368 if (DistanceSquared (line, x, y) <= halfWidth2) 336 369 { 337 370 pixel = psAlloc (sizeof(PixelPos));
Note:
See TracChangeset
for help on using the changeset viewer.
