Changeset 2864


Ignore:
Timestamp:
06/13/07 12:32:23 (12 years ago)
Author:
sorber
Message:

Applied style checks. Removed two print statements from last commit.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/loci/visbio/util/MathUtil.java

    r2863 r2864  
    7575   * @param v Coordinates of the second point 
    7676   */ 
    77   public static double getDistance (double[] p, double[] v) { 
     77  public static double getDistance(double[] p, double[] v){ 
    7878    int len = p.length;  // redundant with getProjection 
    7979    double sum = 0; 
     
    9292   * @param v Coordinates of the second point 
    9393   */ 
    94   public static double getDistance (float[] p, float[] v) { 
     94  public static double getDistance(float[] p, float[] v){ 
    9595    double[] pp = new double[p.length]; 
    9696    double[] vv = new double[v.length]; 
     
    170170      double ydist = y - nodes[1][0]; 
    171171      minDist = Math.sqrt(xdist * xdist + ydist * ydist); 
    172     } else { 
    173  
     172    } 
     173    else { 
    174174      for (int i=0; i<numNodes-1; i++) { 
    175          double[] a = {nodes[0][i], nodes[1][i]}; 
    176          double[] b = {nodes[0][i+1], nodes[1][i+1]}; 
    177          double[] p = {x, y}; 
    178  
    179          double[] proj = getProjection(a, b, p, true); 
    180          double dist = getDistance(p, proj); 
    181  
    182          if (dist < minDist) { 
    183            minDist = dist; 
    184            seg = i; 
    185            double segDist = getDistance (a, b); 
    186            double fracDist = getDistance (a, proj); 
    187            weight = fracDist / segDist; 
    188          } 
    189        } 
     175        double[] a = {nodes[0][i], nodes[1][i]}; 
     176        double[] b = {nodes[0][i+1], nodes[1][i+1]}; 
     177        double[] p = {x, y}; 
     178 
     179        double[] proj = getProjection(a, b, p, true); 
     180        double dist = getDistance(p, proj); 
     181 
     182        if (dist < minDist) { 
     183          minDist = dist; 
     184          seg = i; 
     185          double segDist = getDistance(a, b); 
     186          double fracDist = getDistance(a, proj); 
     187          weight = fracDist / segDist; 
     188        } 
     189      } 
    190190    } 
    191191 
     
    222222      double ydist = y - nodes[1][0]; 
    223223      minDist = Math.sqrt(xdist * xdist + ydist * ydist); 
    224     } else { 
    225  
     224    } 
     225    else { 
    226226      for (int i=0; i<numNodes-1; i++) { 
    227          double[] a = {(double) nodes[0][i], (double) nodes[1][i]}; 
    228          double[] b = {(double) nodes[0][i+1], (double) nodes[1][i+1]}; 
    229          double[] p = {(double) x, (double) y}; 
    230  
    231          double[] proj = getProjection(a, b, p, true); 
    232          double dist = getDistance(p, proj); 
    233  
    234          if (dist < minDist) { 
    235            minDist = dist; 
    236            seg = i; 
    237            double segDist = getDistance (a, b); 
    238            double fracDist = getDistance (a, proj); 
    239            weight = fracDist / segDist; 
    240          } 
    241        } 
     227        double[] a = {(double) nodes[0][i], (double) nodes[1][i]}; 
     228        double[] b = {(double) nodes[0][i+1], (double) nodes[1][i+1]}; 
     229        double[] p = {(double) x, (double) y}; 
     230 
     231        double[] proj = getProjection(a, b, p, true); 
     232        double dist = getDistance(p, proj); 
     233 
     234        if (dist < minDist) { 
     235          minDist = dist; 
     236          seg = i; 
     237          double segDist = getDistance(a, b); 
     238          double fracDist = getDistance(a, proj); 
     239          weight = fracDist / segDist; 
     240        } 
     241      } 
    242242    } 
    243243    // 'seg' is always an integer; 
     
    297297    return result; 
    298298  } 
    299    
     299 
    300300  // -- Vector Math Methods -- 
    301301 
     
    315315  } 
    316316 
    317   /** Computes the dot product of two N-D vectors */  
     317  /** Computes the dot product of two N-D vectors. */ 
    318318  public static float dot(float[] a, float[] b) { 
    319319    float sum = 0f; 
    320320    for (int i=0; i<a.length; i++) { 
    321       sum += a[i] * b[i];  
     321      sum += a[i] * b[i]; 
    322322    } 
    323323    return sum; 
     
    368368   *  b2 and b2 (i.e., in 2D, whether a is inside the box with diagonal 
    369369   *  b1-b2; in 3D, whether a is inside the cube with diagonal b1-b2). 
    370    */  
     370   */ 
    371371  public static boolean inside(float[] a, float[] b1, float[] b2) { 
    372372    // assumes a, b1, b2 have same lengths 
     
    377377      float hi = flip ? b1[i] : b2[i]; 
    378378      if (a[i] < lo || a[i] > hi) { 
    379         between = false;  
     379        between = false; 
    380380        break; 
    381381      } 
     
    385385 
    386386  /** Obtains the z-coordinate of the cross product of the 2D vectors 
    387    *  p2-p1 and p3-p2, useful for determining whether the curve  
     387   *  p2-p1 and p3-p2, useful for determining whether the curve 
    388388   *  p1->p2->p3 is curving to the right or left. */ 
    389389  public static float orient2D(float[] p1, float[] p2, float[] p3) { 
     
    391391    float x2 = p2[0]; float y2 = p2[1]; 
    392392    float x3 = p3[0]; float y3 = p3[1]; 
    393     // z coord. of cross product of p2-(minus)p1 and p3-p2  
     393    // z coord. of cross product of p2-(minus)p1 and p3-p2 
    394394    float z = x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2); 
    395395    return z; 
    396396  } 
    397397 
    398   /** Gets a vector perpendicular to the vector p2-p1, pointing to the right  
     398  /** Gets a vector perpendicular to the vector p2-p1, pointing to the right 
    399399   *  with respect to the direction of p2-p1. */ 
    400400  public static float[] getRightPerpendicularVector2D(float[] p2, float[] p1) { 
     
    407407  public static float[] getRightBisectorVector2D(float[] p1, float[] p2, 
    408408      float[] p3) 
    409   {  
     409  { 
    410410    // System.out.println("entering getBisectorVector2D ..."); //TEMP 
    411411    // Always retrieves the bisector vector on the right (as opposed to left) 
    412412    // side of the angle made by the two vectors. 
    413413 
    414     // z coord. of cross product of p2-(minus)p1 and p3-p2  
     414    // z coord. of cross product of p2-(minus)p1 and p3-p2 
    415415    float z = orient2D(p1, p2, p3); 
    416416 
     
    423423    float[] aBisector = null; // ... says what? 
    424424    if ((vAvg[0] == 0 && vAvg[1] == 0) || z == 0) { 
    425       // Sometimes, z can have a very small nonzero value even when  
     425      // Sometimes, z can have a very small nonzero value even when 
    426426      // the points have the same x=coordinate 
    427427      // (Apparently due to floating point arithmetic?) 
     
    440440    } 
    441441 
    442     System.out.println("z = " + z); 
    443     System.out.println("vAvg = " + vAvg[0] + ", " + vAvg[1]); 
    444  
    445442    float[] bisector = unit(aBisector); 
    446        
     443 
    447444    return bisector; 
    448445  } 
    449446 
    450  
    451447} 
Note: See TracChangeset for help on using the changeset viewer.