IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 20579


Ignore:
Timestamp:
Nov 7, 2008, 3:02:01 PM (18 years ago)
Author:
bills
Message:

bugfix from Paul Sydney

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/magic/remove/src/Line.c

    r20308 r20579  
    3939           (tuple->y >= line->end.y &&
    4040            tuple->y <= line->begin.y);
     41}
     42
     43double 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)
    4174}
    4275
     
    286319            for (y = yBegin; y != yEnd; ++y)
    287320            {
    288                 if ((x * x + y * y) <= halfWidth2)
     321                if (DistanceSquared (line, x, y) <= halfWidth2)
    289322                {
    290323                    pixel = psAlloc (sizeof(PixelPos));
     
    333366            for (x = xBegin; x != xEnd; ++x)
    334367            {
    335                 if ((x * x + y * y) <= halfWidth2)
     368                if (DistanceSquared (line, x, y) <= halfWidth2)
    336369                {
    337370                    pixel = psAlloc (sizeof(PixelPos));
Note: See TracChangeset for help on using the changeset viewer.