signature:
public class UtilEllipse_F64 { /** * Computes the value of the quadratic ellipse function at point ( x , y ) . Should equal 1 if the point is on the
 * ellipse .
 * @ param x x - coordinate
 * @ param y y - coordinate
 * @ param ellipse Ellipse equation being evaluated .
 * @ return value of ellipse equation at point ( x , y ) */
public static double evaluate ( double x , double y , EllipseRotated_F64 ellipse ) { } }

implementation: double cphi = Math . cos ( ellipse . phi ) ; double sphi = Math . sin ( ellipse . phi ) ; x -= ellipse . center . x ; y -= ellipse . center . y ; double left = ( x * cphi + y * sphi ) ; double right = ( - x * sphi + y * cphi ) ; double ll = left / ellipse . a ; double rr = right / ellipse . b ; return ll * ll + rr * rr ;


signature:
public class UtilEllipse_F64 { /** * Computes the point on the ellipse at location ' t ' , where t is an angle in radians
 * @ param t An angle in radians from 0 to 2 * PI
 * @ param ellipse Ellipse
 * @ param output ( Optional ) point on the ellipse . Can be null .
 * @ return Point on the ellipse */
public static Point2D_F64 computePoint ( double t , EllipseRotated_F64 ellipse , Point2D_F64 output ) { } }

implementation:
if ( output == null ) output = new Point2D_F64 ( ) ; double ct = Math . cos ( t ) ; double st = Math . sin ( t ) ; double cphi = Math . cos ( ellipse . phi ) ; double sphi = Math . sin ( ellipse . phi ) ; // coordinate in ellipse frame
double x = ellipse . a * ct ; double y = ellipse . b * st ; // put into global frame
output . x = ellipse . center . x + x * cphi - y * sphi ; output . y = ellipse . center . y + x * sphi + y * cphi ; return output ;


signature:
public class UtilEllipse_F64 { /** * Computes the value of ' t ' used to specify a point ' s location
 * @ param p Point on the ellipse
 * @ param ellipse Ellipse
 * @ return Angle from - pi to pi */
public static double computeAngle ( Point2D_F64 p , EllipseRotated_F64 ellipse ) { } }

implementation:
// put point into ellipse ' s reference frame
double ce = Math . cos ( ellipse . phi ) ; double se = Math . sin ( ellipse . phi ) ; // world into ellipse frame
double xc = p . x - ellipse . center . x ; double yc = p . y - ellipse . center . y ; double x = ce * xc + se * yc ; double y = - se * xc + ce * yc ; return Math . atan2 ( y / ellipse . b , x / ellipse . a ) ;


signature:
public class UtilEllipse_F64 { /** * Computes the tangent to the ellipse at the specified location
 * @ param t Location on the ellipse . Radians
 * @ param ellipse Ellipse equation
 * @ param output Optional storage for tangent
 * @ return The tangent */
public static Vector2D_F64 computeTangent ( double t , EllipseRotated_F64 ellipse , Vector2D_F64 output ) { } }

implementation:
if ( output == null ) output = new Vector2D_F64 ( ) ; double ct = Math . cos ( t ) ; double st = Math . sin ( t ) ; double cphi = Math . cos ( ellipse . phi ) ; double sphi = Math . sin ( ellipse . phi ) ; // point in ellipse frame multiplied by b ^ 2 and a ^ 2
double x = ellipse . a * ct * ellipse . b * ellipse . b ; double y = ellipse . b * st * ellipse . a * ellipse . a ; // rotate vector normal into world frame
double rx = x * cphi - y * sphi ; double ry = x * sphi + y * cphi ; // normalize and change into tangent
double r = Math . sqrt ( rx * rx + ry * ry ) ; output . x = - ry / r ; output . y = rx / r ; return output ;


signature:
public class UtilEllipse_F64 { /** * < p > Finds two points on the ellipse that in combination with point ' pt ' each define
 * a line that is tangent to the ellipse . < / p >
 * Notes : < br >
 * Point ' pt ' is assumed to be outside of the ellipse .
 * @ param pt Point which the lines will pass though
 * @ param ellipse The ellipse which the lines will be tangent to
 * @ param tangentA ( output ) Point on the ellipse where tangent line A hits it
 * @ param tangentB ( output ) Point on the ellipse where tangent line B hits it */
public static boolean tangentLines ( Point2D_F64 pt , EllipseRotated_F64 ellipse , Point2D_F64 tangentA , Point2D_F64 tangentB ) { } }

implementation:
// Derivation :
// Compute the tangent at only point along the ellipse by computing dy / dx
// x * b ^ 2 / ( y * a ^ 2 ) or - x * b ^ 2 / ( y * a ^ 2 ) are the possible solutions for the tangent
// The slope of the line and the gradient are the same , so this is true :
// y - y ' - x * b ^ 2
// x - x ' y * a ^ 2
// ( x , y ) is point on ellipse , ( x ' , y ' ) is pt that lines pass through
// that becomes
// y ^ 2 * a ^ 2 + x ^ 2 * b ^ 2 = x ' * x * b ^ 2 + y ' * y * a ^ 2
// use the equation for the ellipse ( centered and aligned at origin )
// a ^ 2 * b ^ 2 = x ' * x * b ^ 2 + y ' * y * a ^ 2
// solve for y
// plug into ellipse equation
// solve for x , which is a quadratic equation
// translate and rotate into ellipse reference frame
double cphi = Math . cos ( ellipse . phi ) ; double sphi = Math . sin ( ellipse . phi ) ; double tmpx = pt . x - ellipse . center . x ; double tmpy = pt . y - ellipse . center . y ; double xt = tmpx * cphi + tmpy * sphi ; double yt = - tmpx * sphi + tmpy * cphi ; // solve
double a2 = ellipse . a * ellipse . a ; double b2 = ellipse . b * ellipse . b ; // quadratic equation for the two variants .
// solving for x
double aa0 = yt * yt / b2 + xt * xt / a2 ; double bb0 = - 2.0 * xt ; double cc0 = a2 * ( 1.0 - yt * yt / b2 ) ; double descriminant0 = bb0 * bb0 - 4.0 * aa0 * cc0 ; // solving for y
double aa1 = xt * xt / a2 + yt * yt / b2 ; double bb1 = - 2.0 * yt ; double cc1 = b2 * ( 1.0 - xt * xt / a2 ) ; double descriminant1 = bb1 * bb1 - 4.0 * aa1 * cc1 ; double x0 , y0 , x1 , y1 ; if ( descriminant0 < 0 && descriminant1 < 0 ) { return false ; } else if ( descriminant0 > descriminant1 ) { if ( yt == 0 ) return false ; double right = Math . sqrt ( descriminant0 ) ; x0 = ( - bb0 + right ) / ( 2.0 * aa0 ) ; x1 = ( - bb0 - right ) / ( 2.0 * aa0 ) ; y0 = b2 / yt - xt * x0 * b2 / ( yt * a2 ) ; y1 = b2 / yt - xt * x1 * b2 / ( yt * a2 ) ; } else { if ( xt == 0 ) return false ; double right = Math . sqrt ( descriminant1 ) ; y0 = ( - bb1 + right ) / ( 2.0 * aa1 ) ; y1 = ( - bb1 - right ) / ( 2.0 * aa1 ) ; x0 = a2 / xt - yt * y0 * a2 / ( xt * b2 ) ; x1 = a2 / xt - yt * y1 * a2 / ( xt * b2 ) ; } // convert the lines back into world space
tangentA . x = x0 * cphi - y0 * sphi + ellipse . center . x ; tangentA . y = x0 * sphi + y0 * cphi + ellipse . center . y ; tangentB . x = x1 * cphi - y1 * sphi + ellipse . center . x ; tangentB . y = x1 * sphi + y1 * cphi + ellipse . center . y ; return true ;


signature:
public class UtilEllipse_F64 { /** * < p > Finds four lines which are tangent to both ellipses . Both ellipses must not intersect . Line 0
 * and line 3 will not intersect the line joining the center of the two ellipses while line 1 and 2 will . < / p >
 * @ see TangentLinesTwoEllipses _ F64
 * @ param ellipseA ( Input ) First ellipse
 * @ param ellipseB ( Input ) Second ellipse
 * @ param tangentA0 ( Output ) Point on ellipseA in which tangent line0 passes through
 * @ param tangentA1 ( Output ) Point on ellipseA in which tangent line1 passes through
 * @ param tangentA2 ( Output ) Point on ellipseA in which tangent line2 passes through
 * @ param tangentA3 ( Output ) Point on ellipseA in which tangent line3 passes through
 * @ param tangentB0 ( Output ) Point on ellipseB in which tangent line0 passes through
 * @ param tangentB1 ( Output ) Point on ellipseB in which tangent line1 passes through
 * @ param tangentB2 ( Output ) Point on ellipseB in which tangent line2 passes through
 * @ param tangentB3 ( Output ) Point on ellipseB in which tangent line3 passes through
 * @ return true if a solution was found or false if it failed */
public static boolean tangentLines ( EllipseRotated_F64 ellipseA , EllipseRotated_F64 ellipseB , Point2D_F64 tangentA0 , Point2D_F64 tangentA1 , Point2D_F64 tangentA2 , Point2D_F64 tangentA3 , Point2D_F64 tangentB0 , Point2D_F64 tangentB1 , Point2D_F64 tangentB2 , Point2D_F64 tangentB3 ) { } }

implementation: TangentLinesTwoEllipses_F64 alg = new TangentLinesTwoEllipses_F64 ( GrlConstants . TEST_F64 , 10 ) ; return alg . process ( ellipseA , ellipseB , tangentA0 , tangentA1 , tangentA2 , tangentA3 , tangentB0 , tangentB1 , tangentB2 , tangentB3 ) ;


signature:
public class TangentLinesTwoEllipses_F64 { /** * < p > Selects 4 pairs of points . Each point in the pair represents an end point in a line segment which is tangent
 * to both ellipseA and ellipseB . Both ellipses are assumed to not intersect each other . If a fatal error
 * occurs the function will return false . However it can return true and did not converge . To check for
 * convergence call { @ link # isConverged ( ) } . < / p >
 * < p > Line 0 and line 3 will not intersect the line joining the center of the two ellipses while line 1 and 2 will . < / p >
 * @ param ellipseA ( Input ) An ellipse
 * @ param ellipseB ( Input ) An ellipse
 * @ param tangentA0 ( Output ) Tangent point on A for line segment 0
 * @ param tangentA1 ( Output ) Tangent point on A for line segment 1
 * @ param tangentA2 ( Output ) Tangent point on A for line segment 2
 * @ param tangentA3 ( Output ) Tangent point on A for line segment 3
 * @ param tangentB0 ( Output ) Tangent point on B for line segment 0
 * @ param tangentB1 ( Output ) Tangent point on B for line segment 1
 * @ param tangentB2 ( Output ) Tangent point on B for line segment 2
 * @ param tangentB3 ( Output ) Tangent point on B for line segment 3
 * @ return true if no fatal error , false if one happened . */
public boolean process ( EllipseRotated_F64 ellipseA , EllipseRotated_F64 ellipseB , Point2D_F64 tangentA0 , Point2D_F64 tangentA1 , Point2D_F64 tangentA2 , Point2D_F64 tangentA3 , Point2D_F64 tangentB0 , Point2D_F64 tangentB1 , Point2D_F64 tangentB2 , Point2D_F64 tangentB3 ) { } }

implementation:
converged = false ; // initialize by picking an arbitrary point on A and then finding the points on B in which
// a line is tangent to B and passes through the point on A
if ( ! initialize ( ellipseA , ellipseB , tangentA0 , tangentA1 , tangentA2 , tangentA3 , tangentB0 , tangentB1 , tangentB2 , tangentB3 ) ) return false ; // update the location of each point until it converges or the maximum number of iterations has been exceeded
int iteration = 0 ; for ( ; iteration < maxIterations ; iteration ++ ) { boolean allGood = false ; sumDifference = 0 ; if ( ! selectTangent ( tangentA0 , tangentB0 , ellipseB , tangentB0 , false ) ) return false ; if ( ! selectTangent ( tangentA1 , tangentB1 , ellipseB , tangentB1 , true ) ) return false ; if ( ! selectTangent ( tangentA2 , tangentB2 , ellipseB , tangentB2 , true ) ) return false ; if ( ! selectTangent ( tangentA3 , tangentB3 , ellipseB , tangentB3 , false ) ) return false ; if ( Math . sqrt ( sumDifference ) / 4.0 <= convergenceTol ) { allGood = true ; } sumDifference = 0 ; if ( ! selectTangent ( tangentB0 , tangentA0 , ellipseA , tangentA0 , false ) ) return false ; if ( ! selectTangent ( tangentB1 , tangentA1 , ellipseA , tangentA1 , true ) ) return false ; if ( ! selectTangent ( tangentB2 , tangentA2 , ellipseA , tangentA2 , true ) ) return false ; if ( ! selectTangent ( tangentB3 , tangentA3 , ellipseA , tangentA3 , false ) ) return false ; if ( allGood && Math . sqrt ( sumDifference ) / 4.0 <= convergenceTol ) { break ; } } converged = iteration < maxIterations ; return true ;


signature:
public class TangentLinesTwoEllipses_F64 { /** * Select the initial tangent points on the ellipses . This is done by :
 * 1 ) picking an arbitrary point on ellipseA .
 * 2 ) Find tangent points on B using point from step 1
 * 3 ) Use those two tangent points on B to find 4 points on ellipse A
 * 4 ) Use those 4 points to select 4 points on B . */
boolean initialize ( EllipseRotated_F64 ellipseA , EllipseRotated_F64 ellipseB , Point2D_F64 tangentA0 , Point2D_F64 tangentA1 , Point2D_F64 tangentA2 , Point2D_F64 tangentA3 , Point2D_F64 tangentB0 , Point2D_F64 tangentB1 , Point2D_F64 tangentB2 , Point2D_F64 tangentB3 ) { } }

implementation:
centerLine . set ( ellipseA . center , ellipseB . center ) ; UtilLine2D_F64 . convert ( centerLine , lineGeneral ) ; Intersection2D_F64 . intersection ( lineGeneral , ellipseA , temp0 , temp1 , - 1 ) ; if ( temp0 . distance2 ( ellipseB . center ) < temp1 . distance2 ( ellipseB . center ) ) { tangentA0 . set ( temp0 ) ; } else { tangentA0 . set ( temp1 ) ; } // Two seed points for B . This points will be on two different sides of center line
if ( ! tangentLines ( tangentA0 , ellipseB , tangentB0 , tangentB1 ) ) return false ; // Find initial seed of 4 points on ellipse A . Careful which pairs of points cross or
// don ' t cross the center line
if ( ! selectTangent ( tangentB0 , tangentA0 , ellipseA , tangentA0 , false ) ) return false ; if ( ! selectTangent ( tangentB0 , tangentA0 , ellipseA , tangentA1 , true ) ) return false ; if ( ! selectTangent ( tangentB1 , tangentA0 , ellipseA , tangentA2 , true ) ) return false ; if ( ! selectTangent ( tangentB1 , tangentA0 , ellipseA , tangentA3 , false ) ) return false ; // not all of the B ' s have been initialized . That ' s ok . It will just have a large error
// the first iteration
return true ;


signature:
public class TangentLinesTwoEllipses_F64 { /** * Selects a tangent point on the ellipse which is closest to the original source point of A .
 * @ param a Point that the tangent lines pass through
 * @ param previousTangent Source point which generated ' a '
 * @ param ellipse Ellipse which the lines will be tangent to
 * @ param tangent ( Output ) Storage for the selected tangent point
 * @ return true if everything went well or false if finding tangent lines barfed */
boolean selectTangent ( Point2D_F64 a , Point2D_F64 previousTangent , EllipseRotated_F64 ellipse , Point2D_F64 tangent , boolean cross ) { } }

implementation: if ( ! tangentLines ( a , ellipse , temp0 , temp1 ) ) return false ; tempLine . a = a ; tempLine . b = temp0 ; boolean crossed0 = Intersection2D_F64 . intersection ( centerLine , tempLine , junk ) != null ; tempLine . b = temp1 ; boolean crossed1 = Intersection2D_F64 . intersection ( centerLine , tempLine , junk ) != null ; if ( crossed0 == crossed1 ) throw new RuntimeException ( "Well this didn't work" ) ; if ( cross == crossed0 ) { sumDifference += previousTangent . distance2 ( temp0 ) ; tangent . set ( temp0 ) ; } else { sumDifference += previousTangent . distance2 ( temp1 ) ; tangent . set ( temp1 ) ; } return true ;


signature:
public class Rectangle2D_I32 { /** * Makes sure x0 , y0 is the lower extent and x1 , y1 is the upper extent */
public void enforceExtents ( ) { } }

implementation: if ( x1 < x0 ) { int tmp = x1 ; x1 = x0 ; x0 = tmp ; } if ( y1 < y0 ) { int tmp = y1 ; y1 = y0 ; y0 = tmp ; }


signature:
public class Point2D_I32 { /** * Returns the Euclidean distance squared from ' this ' to ' a ' . No floating point
 * operations are used .
 * d < sup > 2 < / sup > = ( this . x - a . x ) < sup > 2 < / sup > + ( this . y - a . y ) < sup > 2 < / sup >
 * @ param a Point that distance is computed from .
 * @ return Euclidean distance squared . */
public int distance2 ( Point2D_I32 a ) { } }

implementation: int dx = x - a . x ; int dy = y - a . y ; return dx * dx + dy * dy ;


signature:
public class SpecialOrthogonalOps_F64 { /** * Finds the best fit matrix in SO ( 3 ) for the input matrix .
 * @ param A 3x3 matrix . Modified . */
public static void bestFit ( DMatrixRMaj A ) { } }

implementation:
SingularValueDecomposition_F64 < DMatrixRMaj > svd = DecompositionFactory_DDRM . svd ( true , true , true ) ; if ( ! svd . decompose ( A ) ) throw new RuntimeException ( "SVD Failed" ) ; CommonOps_DDRM . multTransB ( svd . getU ( null , false ) , svd . getV ( null , false ) , A ) ; // determinant should be + 1
double det = CommonOps_DDRM . det ( A ) ; if ( det < 0 ) CommonOps_DDRM . scale ( - 1 , A ) ;


signature:
public class BoxLength3D_F64 { /** * Used to retrieve the corners of the box .
 * @ param index A value from 0 to 7
 * @ param corner ( Optional ) storage for the corner . If null a new point will be declared
 * @ return The corner . */
public Point3D_F64 getCorner ( int index , Point3D_F64 corner ) { } }

implementation: if ( corner == null ) corner = new Point3D_F64 ( ) ; corner . set ( p ) ; if ( ( index & 0x01 ) != 0 ) { corner . x += lengthX ; } if ( ( index & 0x02 ) != 0 ) { corner . y += lengthY ; } if ( ( index & 0x04 ) != 0 ) { corner . z += lengthZ ; } return corner ;


signature:
public class Distance3D_F64 { /** * Distance of the closest point between two lines . Parallel lines are correctly
 * handled .
 * @ param l0 First line . Not modified .
 * @ param l1 Second line . Not modified .
 * @ return Distance between the closest point on both lines . */
public static double distance ( LineParametric3D_F64 l0 , LineParametric3D_F64 l1 ) { } }

implementation:
double x = l0 . p . x - l1 . p . x ; double y = l0 . p . y - l1 . p . y ; double z = l0 . p . z - l1 . p . z ; // this solution is from : http : / / local . wasp . uwa . edu . au / ~ pbourke / geometry / lineline3d /
double dv01v1 = MiscOps . dot ( x , y , z , l1 . slope ) ; double dv1v0 = MiscOps . dot ( l1 . slope , l0 . slope ) ; double dv1v1 = MiscOps . dot ( l1 . slope , l1 . slope ) ; double bottom = MiscOps . dot ( l0 . slope , l0 . slope ) * dv1v1 - dv1v0 * dv1v0 ; double t0 ; if ( bottom == 0 ) { // handle parallel lines
t0 = 0 ; } else { t0 = ( dv01v1 * dv1v0 - MiscOps . dot ( x , y , z , l0 . slope ) * dv1v1 ) / bottom ; } // ( d1343 + mua d4321 ) / d4343
double t1 = ( dv01v1 + t0 * dv1v0 ) / dv1v1 ; double dx = ( l0 . p . x + t0 * l0 . slope . x ) - ( l1 . p . x + t1 * l1 . slope . x ) ; double dy = ( l0 . p . y + t0 * l0 . slope . y ) - ( l1 . p . y + t1 * l1 . slope . y ) ; double dz = ( l0 . p . z + t0 * l0 . slope . z ) - ( l1 . p . z + t1 * l1 . slope . z ) ; // round off error can make distanceSq go negative when it is very close to zero
double distanceSq = dx * dx + dy * dy + dz * dz ; if ( distanceSq < 0 ) return 0 ; else return Math . sqrt ( distanceSq ) ;


signature:
public class Distance3D_F64 { /** * Distance from the point to the closest point on the line .
 * @ param l Line . Not modified .
 * @ param p Point . Not modified .
 * @ return distance . */
public static double distance ( LineParametric3D_F64 l , Point3D_F64 p ) { } }

implementation:
double x = l . p . x - p . x ; double y = l . p . y - p . y ; double z = l . p . z - p . z ; double cc = x * x + y * y + z * z ; // could avoid a square root here by computing b * b directly
// however that is most likely more prone to numerical overflow since the numerator will need to be squared
// before division can reduce its " power "
double b = MiscOps . dot ( x , y , z , l . slope ) / l . slope . norm ( ) ; double distanceSq = cc - b * b ; // round off error can make distanceSq go negative when it is very close to zero
if ( distanceSq < 0 ) { return 0 ; } else { return Math . sqrt ( distanceSq ) ; }


signature:
public class Distance3D_F64 { /** * Distance from the point to the closest point on the line segment .
 * @ param l Line . Not modified .
 * @ param p Point . Not modified .
 * @ return distance . */
public static double distance ( LineSegment3D_F64 l , Point3D_F64 p ) { } }

implementation:
double dx = p . x - l . a . x ; double dy = p . y - l . a . y ; double dz = p . z - l . a . z ; double cc = dx * dx + dy * dy + dz * dz ; double slope_x = l . b . x - l . a . x ; double slope_y = l . b . y - l . a . y ; double slope_z = l . b . z - l . a . z ; double n = ( double ) Math . sqrt ( slope_x * slope_x + slope_y * slope_y + slope_z * slope_z ) ; double d = ( slope_x * dx + slope_y * dy + slope_z * dz ) / n ; // check end points
if ( d <= 0 ) return p . distance ( l . a ) ; else if ( d >= n ) return p . distance ( l . b ) ; double distanceSq = cc - d * d ; // round off error can make distanceSq go negative when it is very close to zero
if ( distanceSq < 0 ) { return 0 ; } else { return Math . sqrt ( distanceSq ) ; }


signature:
public class Distance3D_F64 { /** * Distance between a plane and a point . A signed distance is returned , where a positive value is returned if
 * the point is on the same side of the plane as the normal and the opposite if it ' s on the other .
 * @ param plane The plane
 * @ param point The point
 * @ return Signed distance */
public static double distance ( PlaneGeneral3D_F64 plane , Point3D_F64 point ) { } }

implementation: double top = plane . A * point . x + plane . B * point . y + plane . C * point . z - plane . D ; return top / Math . sqrt ( plane . A * plane . A + plane . B * plane . B + plane . C * plane . C ) ;


signature:
public class Distance3D_F64 { /** * Returns the signed distance a point is from the sphere ' s surface . If the point is outside of the sphere
 * it ' s distance will be positive . If it is inside it will be negative .
 * < p > < / p >
 * distance = | | sphere . center - point | | - r
 * @ param sphere The sphere
 * @ param point The point
 * @ return Signed distance */
public static double distance ( Sphere3D_F64 sphere , Point3D_F64 point ) { } }

implementation: double r = point . distance ( sphere . center ) ; return r - sphere . radius ;


signature:
public class Distance3D_F64 { /** * Returns the signed distance a point is from the cylinder ' s surface . If the point is outside of the cylinder
 * it ' s distance will be positive . If it is inside it will be negative .
 * @ param cylinder The cylinder
 * @ param point The point
 * @ return Signed distance */
public static double distance ( Cylinder3D_F64 cylinder , Point3D_F64 point ) { } }

implementation: double r = Distance3D_F64 . distance ( cylinder . line , point ) ; return r - cylinder . radius ;


signature:
public class Distance3D_F64 { /** * Signed distance from a 3D point to 3D triangle . The sign indicates which side of the triangle the point
 * is on . See { @ link georegression . metric . alg . DistancePointTriangle3D _ F64 } for the details .
 * @ param triangle 3D triangle
 * @ param point Point for which the closest point on the triangle is found
 * @ return The closest point */
public static double distance ( Triangle3D_F64 triangle , Point3D_F64 point ) { } }

implementation: DistancePointTriangle3D_F64 alg = new DistancePointTriangle3D_F64 ( ) ; alg . setTriangle ( triangle . v0 , triangle . v1 , triangle . v2 ) ; Point3D_F64 cp = new Point3D_F64 ( ) ; alg . closestPoint ( point , cp ) ; double d = point . distance ( cp ) ; return alg . sign ( point ) * d ;


signature:
public class LineParametric3D_F64 { /** * where = p + t * slope . */
public void setPointOnLine ( double t , Point3D_F64 where ) { } }

implementation: where . x = p . x + t * slope . x ; where . y = p . y + t * slope . y ; where . z = p . z + t * slope . z ;


signature:
public class LineParametric3D_F64 { /** * Returns a point along the line . See parametric equation in class description .
 * @ param t Location along the line .
 * @ return Point on the line . */
public Point3D_F64 getPointOnLine ( double t ) { } }

implementation: return new Point3D_F64 ( slope . x * t + p . x , slope . y * t + p . y , slope . z * t + p . z ) ;


signature:
public class Distance2D_F64 { /** * Returns the Euclidean distance of the closest point on the line from a point .
 * @ param line A line segment . Not modified .
 * @ param p The point . Not modified .
 * @ return Distance the closest point on the line is away from the point . */
public static double distance ( LineParametric2D_F64 line , Point2D_F64 p ) { } }

implementation: return Math . sqrt ( distanceSq ( line , p ) ) ;


signature:
public class Distance2D_F64 { /** * Returns the Euclidean distance of the closest point on the line from a point .
 * @ param line A line segment . Not modified .
 * @ param x Point ' s x - coordinate
 * @ param y Point ' s y - coordinate
 * @ return Distance the closest point on the line is away from the point . */
public static double distance ( LineParametric2D_F64 line , double x , double y ) { } }

implementation: return Math . sqrt ( distanceSq ( line , x , y ) ) ;


signature:
public class Distance2D_F64 { /** * Returns the Euclidean distance squared of the closest point on the line from a point .
 * @ param line A line segment . Not modified .
 * @ param p The point . Not modified .
 * @ return Euclidean distance squared to the closest point on the line is away from the point . */
public static double distanceSq ( LineParametric2D_F64 line , Point2D_F64 p ) { } }

implementation: double scale = Math . max ( Math . abs ( line . slope . x ) , Math . abs ( line . slope . y ) ) ; double t = ClosestPoint2D_F64 . closestPointT ( line , p , scale ) ; double a = ( line . slope . x / scale ) * t + line . p . x ; double b = ( line . slope . y / scale ) * t + line . p . y ; double dx = p . x - a ; double dy = p . y - b ; return dx * dx + dy * dy ;


signature:
public class Distance2D_F64 { /** * Returns the Euclidean distance of the closest point on a line segment to the specified point .
 * @ param line A line segment . Not modified .
 * @ param p The point . Not modified .
 * @ return Euclidean distance of the closest point on a line is away from a point . */
public static double distance ( LineSegment2D_F64 line , Point2D_F64 p ) { } }


signature:
public class Distance2D_F64 { /** * Returns the Euclidean distance of the closest point on a line segment to the specified point .
 * @ param line A line segment . Not modified .
 * @ param x Point ' s x - coordinate
 * @ param y Point ' s y - coordinate
 * @ return Euclidean distance of the closest point on a line is away from a point . */
public static double distance ( LineSegment2D_F64 line , double x , double y ) { } }


signature:
public class Distance2D_F64 { /** * Returns the Euclidean distance squared of the closest point on a line segment to the specified point .
 * @ param line A line segment . Not modified .
 * @ param p The point . Not modified .
 * @ return Euclidean distance squared of the closest point on a line is away from a point . */
public static double distanceSq ( LineSegment2D_F64 line , Point2D_F64 p ) { } }

implementation:
double a = line . b . x - line . a . x ; double b = line . b . y - line . a . y ; double t = a * ( p . x - line . a . x ) + b * ( p . y - line . a . y ) ; t /= ( a * a + b * b ) ; // if the point of intersection is past the end points return the distance
// from the closest end point
if ( t < 0 ) { return UtilPoint2D_F64 . distanceSq ( line . a . x , line . a . y , p . x , p . y ) ; } else if ( t > 1.0 ) return UtilPoint2D_F64 . distanceSq ( line . b . x , line . b . y , p . x , p . y ) ; // return the distance of the closest point on the line
return UtilPoint2D_F64 . distanceSq ( line . a . x + t * a , line . a . y + t * b , p . x , p . y ) ;


signature:
public class Distance2D_F64 { /** * Finds the distance between the two line segments
 * @ param segmentA Line segment . Not modified .
 * @ param segmentB Line segment . Not modified .
 * @ return Euclidean distance of the closest point between the two line segments . */
public static double distance ( LineSegment2D_F64 segmentA , LineSegment2D_F64 segmentB ) { } }

implementation: return Math . sqrt ( distanceSq ( segmentA , segmentB ) ) ;


signature:
public class Distance2D_F64 { /** * Finds the distance squared between the two line segments
 * @ param segmentA Line segment . Not modified .
 * @ param segmentB Line segment . Not modified .
 * @ return Euclidean distance squared of the closest point between the two line segments . */
public static double distanceSq ( LineSegment2D_F64 segmentA , LineSegment2D_F64 segmentB ) { } }

implementation:
// intersection of the two lines relative to A
double slopeAX = segmentA . slopeX ( ) ; double slopeAY = segmentA . slopeY ( ) ; double slopeBX = segmentB . slopeX ( ) ; double slopeBY = segmentB . slopeY ( ) ; double ta = slopeBX * ( segmentA . a . y - segmentB . a . y ) - slopeBY * ( segmentA . a . x - segmentB . a . x ) ; double bottom = slopeBY * slopeAX - slopeAY * slopeBX ; // see they intersect
if ( bottom != 0 ) { // see if the intersection is inside of lineA
ta /= bottom ; if ( ta >= 0 && ta <= 1.0 ) { // see if the intersection is inside of lineB
double tb = slopeAX * ( segmentB . a . y - segmentA . a . y ) - slopeAY * ( segmentB . a . x - segmentA . a . x ) ; tb /= slopeAY * slopeBX - slopeBY * slopeAX ; if ( tb >= 0 && tb <= 1.0 ) return 0 ; } } double closest = Double . MAX_VALUE ; closest = Math . min ( closest , distanceSq ( segmentA , segmentB . a ) ) ; closest = Math . min ( closest , distanceSq ( segmentA , segmentB . b ) ) ; closest = Math . min ( closest , distanceSq ( segmentB , segmentA . a ) ) ; closest = Math . min ( closest , distanceSq ( segmentB , segmentA . b ) ) ; return closest ;


signature:
public class Distance2D_F64 { /** * Returns the Euclidean distance of the closest point on the quadrilateral to the provided point .
 * @ param quad Quadrilateral
 * @ param p Point
 * @ return Distance apart */
public static double distance ( Quadrilateral_F64 quad , Point2D_F64 p ) { } }

implementation: return Math . sqrt ( distanceSq ( quad , p ) ) ;


signature:
public class Distance2D_F64 { /** * Returns the Euclidean distance squared of the closest point on the quadrilateral to the provided point .
 * @ param quad Quadrilateral
 * @ param p Point
 * @ return Distance squared apart */
public static double distanceSq ( Quadrilateral_F64 quad , Point2D_F64 p ) { } }

implementation: LineSegment2D_F64 seg = LineSegment2D_F64 . wrap ( quad . a , quad . b ) ; double a = distanceSq ( seg , p ) ; seg . a = quad . b ; seg . b = quad . c ; a = Math . min ( a , distanceSq ( seg , p ) ) ; seg . a = quad . c ; seg . b = quad . d ; a = Math . min ( a , distanceSq ( seg , p ) ) ; seg . a = quad . d ; seg . b = quad . a ; return Math . min ( a , distanceSq ( seg , p ) ) ;


signature:
public class Distance2D_F64 { /** * Returns the Euclidean distance of the closest point on the Polygon to the provided point .
 * @ param poly Polygon2D
 * @ param p Point
 * @ return Distance squared apart */
public static double distance ( Polygon2D_F64 poly , Point2D_F64 p ) { } }

implementation: return Math . sqrt ( distanceSq ( poly , p , null ) ) ;


signature:
public class Distance2D_F64 { /** * Returns the Euclidean distance squared of the closest point on the Polygon to the provided point .
 * @ param poly Polygon2D
 * @ param p Point
 * @ param storage Optional storage for linesegment which is used internally to compute the distance
 * @ return Distance squared apart */
public static double distanceSq ( Polygon2D_F64 poly , Point2D_F64 p , LineSegment2D_F64 storage ) { } }

implementation: if ( storage == null ) storage = LineSegment2D_F64 . wrap ( null , null ) ; double minimum = Double . MAX_VALUE ; for ( int i = 0 ; i < poly . size ( ) ; i ++ ) { int j = ( i + 1 ) % poly . size ( ) ; storage . a = poly . vertexes . data [ i ] ; storage . b = poly . vertexes . data [ j ] ; double d = distanceSq ( storage , p ) ; if ( d < minimum ) minimum = d ; } return minimum ;


signature:
public class Distance2D_F64 { /** * Returns the Euclidean distance of the closest point on the line to the specified point .
 * @ param line A line . Not modified .
 * @ param p The point . Not modified .
 * @ return Euclidean distance of the closest point on the line to the specified point . */
public static double distance ( LineGeneral2D_F64 line , Point2D_F64 p ) { } }

implementation: return Math . abs ( line . A * p . x + line . B * p . y + line . C ) / Math . sqrt ( line . A * line . A + line . B * line . B ) ;


signature:
public class Distance2D_F64 { /** * Returns the signed Euclidean distance of the closest point on the line to the specified point .
 * The line is assumed be normalized . See { @ link LineGeneral2D _ F64 } for details on normalization .
 * @ param line A normalized line . Not modified .
 * @ param p The point . Not modified .
 * @ return Euclidean distance of the closest point on the line to the specified point . */
public static double distanceNorm ( LineGeneral2D_F64 line , Point2D_F64 p ) { } }

implementation: return Math . abs ( line . A * p . x + line . B * p . y + line . C ) ;


signature:
public class Distance2D_F64 { /** * Returns the distance of the closest point on the line from the origin
 * @ param line Line
 * @ return Euclidean distance */
public static double distanceOrigin ( LineParametric2D_F64 line ) { } }

implementation: double top = line . slope . y * line . p . x - line . slope . x * line . p . y ; return Math . abs ( top ) / line . slope . norm ( ) ;


signature:
public class Distance2D_F64 { /** * Euclidean distance of closest point on ellipse to point ' p ' .
 * @ param ellipse Ellipse
 * @ param p Point
 * @ return Euclidean distance */
public static double distance ( EllipseRotated_F64 ellipse , Point2D_F64 p ) { } }

implementation: return Math . sqrt ( distance2 ( ellipse , p ) ) ;


signature:
public class Distance2D_F64 { /** * Euclidean distance squared of closest point on ellipse to point ' p ' .
 * @ param ellipse Ellipse
 * @ param p Point
 * @ return Euclidean distance squared */
public static double distance2 ( EllipseRotated_F64 ellipse , Point2D_F64 p ) { } }

implementation:
// put point into ellipse ' s reference frame
double cphi = Math . cos ( ellipse . phi ) ; double sphi = Math . sin ( ellipse . phi ) ; double xc = p . x - ellipse . center . x ; double yc = p . y - ellipse . center . y ; double r = Math . sqrt ( xc * xc + yc * yc ) ; double x = cphi * xc + sphi * yc ; double y = - sphi * xc + cphi * yc ; double ct = x / r ; double st = y / r ; x = ellipse . center . x + ellipse . a * ct * cphi - ellipse . b * st * sphi ; y = ellipse . center . y + ellipse . a * ct * sphi + ellipse . b * st * cphi ; return p . distance2 ( x , y ) ;


signature:
public class InvertibleTransformSequence { /** * Adds the next transform in the sequence .
 * @ param forward Does the transform work in the forward or reverse direction .
 * @ param tranThe transform . */
public void addTransform ( boolean forward , T tran ) { } }

implementation: path . add ( new Node < T > ( tran , forward ) ) ;


signature:
public class ClosestPoint2D_F64 { /** * Finds the closest point on ' line ' to the specified point .
 * @ param line Line along which the closest point is to be found .
 * @ param p Point .
 * @ param output Where the solution is stored . If null a new instance is created . Modified .
 * @ return Closest point on the line . */
public static Point2D_F64 closestPoint ( LineGeneral2D_F64 line , Point2D_F64 p , Point2D_F64 output ) { } }

implementation: if ( output == null ) output = new Point2D_F64 ( ) ; double AA = line . A * line . A ; double AB = line . A * line . B ; double BB = line . B * line . B ; output . y = AA * p . y - AB * p . x - line . B * line . C ; output . y /= AA + BB ; output . x = BB * p . x - AB * p . y - line . A * line . C ; output . x /= AA + BB ; return output ;


signature:
public class ClosestPoint2D_F64 { /** * Finds the closest point on ' line ' to the specified point .
 * @ param lineLine along which the closest point is being found .
 * @ param p Point .
 * @ param output Where the solution is stored . If null a new instance is created . Modified .
 * @ return Closest point on the line . */
public static Point2D_F64 closestPoint ( LineParametric2D_F64 line , Point2D_F64 p , Point2D_F64 output ) { } }

implementation: if ( output == null ) output = new Point2D_F64 ( ) ; double t = closestPointT ( line , p ) ; output . x = line . p . x + line . slope . x * t ; output . y = line . p . y + line . slope . y * t ; return output ;


signature:
public class ClosestPoint2D_F64 { /** * Computes the closest point along the line as a function of ' t ' : < br >
 * [ x , y ] = [ x _ 0 , y _ 0 ] + t · [ slopeX , slopeY ]
 * @ param line The line along which the closest point is being found . Not modified .
 * @ param pA point . Not modified .
 * @ return Distance as a function of ' t ' */
public static double closestPointT ( LineParametric2D_F64 line , Point2D_F64 p ) { } }

implementation: double t = line . slope . x * ( p . x - line . p . x ) + line . slope . y * ( p . y - line . p . y ) ; t /= line . slope . x * line . slope . x + line . slope . y * line . slope . y ; return t ;


signature:
public class ClosestPoint2D_F64 { /** * Computes the closest point along the line as a function of ' t ' : < br >
 * [ x , y ] = [ x _ 0 , y _ 0 ] + t · [ slopeX , slopeY ]
 * @ param line The line along which the closest point is being found . Not modified .
 * @ param scale Scale factor . used to avoid numerical issues
 * @ param x Point ' s x - coordinate
 * @ param y Point ' s y - coordinate
 * @ return Distance as a function of ' t ' */
public static double closestPointT ( LineParametric2D_F64 line , double x , double y , double scale ) { } }

implementation: double sx = line . slope . x / scale ; double sy = line . slope . y / scale ; double t = sx * ( x - line . p . x ) + sy * ( y - line . p . y ) ; t /= sx * sx + sy * sy ; return t ;


signature:
public class ClosestPoint2D_F64 { /** * Finds the closest point on the line segment to the provided point ' p ' .
 * @ param line Line segment
 * @ param p Point `
 * @ param output Optional storage for the closet point on the line to p . If null a new instance is created .
 * @ return Closest point on the line to the point */
public static Point2D_F64 closestPoint ( LineSegment2D_F64 line , Point2D_F64 p , Point2D_F64 output ) { } }

implementation: if ( output == null ) output = new Point2D_F64 ( ) ; double slopeX = line . b . x - line . a . x ; double slopeY = line . b . y - line . a . y ; double t = slopeX * ( p . x - line . a . x ) + slopeY * ( p . y - line . a . y ) ; t /= slopeX * slopeX + slopeY * slopeY ; if ( t < 0 ) t = 0 ; else if ( t > 1 ) t = 1 ; output . x = line . a . x + slopeX * t ; output . y = line . a . y + slopeY * t ; return output ;


signature:
public class ClosestPoint2D_F64 { /** * Computes the closest point on an ellipse to the provided point . If there are multiple solutions then one
 * is arbitrarily chosen .
 * NOTE : When optimizing consider calling { @ link ClosestPointEllipseAngle _ F64 } directly instead .
 * @ param ellipse Ellipse
 * @ param p Point
 * @ return Closest point on the ellipse */
public static Point2D_F64 closestPoint ( EllipseRotated_F64 ellipse , Point2D_F64 p ) { } }

implementation: ClosestPointEllipseAngle_F64 alg = new ClosestPointEllipseAngle_F64 ( GrlConstants . TEST_F64 , 30 ) ; alg . setEllipse ( ellipse ) ; alg . process ( p ) ; return alg . getClosest ( ) ;


signature:
public class FitPolynomialSolverTall_F64 { /** * Fits the polynomial curve to the data .
 * @ param data interleaved input output
 * @ param offset first element in data
 * @ param length number of elements to read in data
 * @ param output The fitted polynomial
 * @ return true if solver worked or false if it didn ' t */
public boolean process ( double [ ] data , int offset , int length , PolynomialCurve_F64 output ) { } }

implementation: int N = length / 2 ; int numCoefs = output . size ( ) ; A . reshape ( N , numCoefs ) ; b . reshape ( N , 1 ) ; x . reshape ( numCoefs , 1 ) ; int end = offset + length ; for ( int i = offset , idxA = 0 ; i < end ; i += 2 ) { double x = data [ i ] ; double y = data [ i + 1 ] ; double pow = 1.0 ; for ( int j = 0 ; j < numCoefs ; j ++ ) { A . data [ idxA ++ ] = pow ; pow *= x ; } b . data [ i / 2 ] = y ; } if ( ! solver . setA ( A ) ) return false ; solver . solve ( b , x ) ; for ( int i = 0 ; i < numCoefs ; i ++ ) { output . set ( i , x . data [ i ] ) ; } return true ;


signature:
public class FitConicAtA_F64 { /** * Fits the conic to the points . Strongly recommended that you transform the points such that they have
 * zero mean and a standard deviation along x and y axis , independently .
 * @ param points ( Input ) points
 * @ param output ( Output ) found conic
 * @ return true if successful or false if it failed */
@ Override public boolean process ( List < Point2D_F64 > points , ConicGeneral_F64 output ) { } }

implementation:
final int N = points . size ( ) ; if ( N < 3 ) throw new IllegalArgumentException ( "At least 3 points required" ) ; CommonOps_DDF6 . fill ( ATA , 0 ) ; for ( int i = 0 ; i < N ; i ++ ) { Point2D_F64 p = points . get ( i ) ; double x = p . x ; double y = p . y ; double xx = x * x ; double xxx = xx * x ; double yy = y * y ; double yyy = yy * y ; ATA . a11 += xx * xx ; ATA . a12 += xxx * y ; ATA . a13 += xx * yy ; ATA . a14 += xxx ; ATA . a15 += xx * y ; ATA . a16 += xx ; ATA . a22 += xx * yy ; ATA . a23 += x * yyy ; // ATA . a24 + = xx * y ;
ATA . a25 += x * yy ; ATA . a26 += x * y ; ATA . a33 += yyy * y ; // ATA . a34 + = x * yy ;
ATA . a35 += yyy ; ATA . a36 += yy ; // ATA . a44 + = xx ;
ATA . a45 += x * y ; ATA . a46 += x ; // ATA . a55 + = yy ;
ATA . a56 += y ; } ATA . a21 = ATA . a12 ; ATA . a24 = ATA . a15 ; ATA . a31 = ATA . a13 ; ATA . a32 = ATA . a23 ; ATA . a34 = ATA . a25 ; ATA . a41 = ATA . a14 ; ATA . a42 = ATA . a24 ; ATA . a43 = ATA . a34 ; ATA . a44 = ATA . a16 ; ATA . a51 = ATA . a15 ; ATA . a52 = ATA . a25 ; ATA . a53 = ATA . a35 ; ATA . a54 = ATA . a45 ; ATA . a55 = ATA . a36 ; ATA . a61 = ATA . a16 ; ATA . a62 = ATA . a26 ; ATA . a63 = ATA . a36 ; ATA . a64 = ATA . a56 ; ATA . a65 = ATA . a56 ; ATA . a66 = N ; ConvertDMatrixStruct . convert ( ATA , tmp ) ; if ( ! solver . process ( tmp , 1 , nullspace ) ) return false ; output . A = nullspace . data [ 0 ] ; output . B = nullspace . data [ 1 ] ; output . C = nullspace . data [ 2 ] ; output . D = nullspace . data [ 3 ] ; output . E = nullspace . data [ 4 ] ; output . F = nullspace . data [ 5 ] ; return true ;


signature:
public class UtilVector3D_F64 { /** * Creates a random vector where each axis is selected from a uniform distribution .
 * @ param min minimum value
 * @ param max maximum value
 * @ param rand random number generator
 * @ return the new random vector */
public static Vector3D_F64 createRandom ( double min , double max , Random rand ) { } }

implementation: double range = max - min ; Vector3D_F64 a = new Vector3D_F64 ( ) ; a . x = range * rand . nextDouble ( ) + min ; a . y = range * rand . nextDouble ( ) + min ; a . z = range * rand . nextDouble ( ) + min ; return a ;


signature:
public class UtilVector3D_F64 { /** * Selects a vector which will be perpendicular .
 * @ param A ( Input ) A vector
 * @ param output ( Optional ) storage for output
 * @ return Perpendicular vector */
public static Vector3D_F64 perpendicularCanonical ( Vector3D_F64 A , Vector3D_F64 output ) { } }

implementation:
if ( output == null ) output = new Vector3D_F64 ( ) ; // normalize for scaling
double scale = Math . abs ( A . x ) + Math . abs ( A . y ) + Math . abs ( A . z ) ; if ( scale == 0 ) { output . set ( 0 , 0 , 0 ) ; } else { double x = A . x / scale ; double y = A . y / scale ; double z = A . z / scale ; // For numerical stability ensure that the largest variable is swapped
if ( Math . abs ( x ) > Math . abs ( y ) ) { output . set ( z , 0 , - x ) ; } else { output . set ( 0 , z , - y ) ; } } return output ;


signature:
public class UtilVector3D_F64 { /** * Checks to see if the two vectors are identical to within tolerance . Each axis is checked
 * individually .
 * @ param a First vector .
 * @ param b Second vector .
 * @ param tol Tolerance for equality .
 * @ return true if identical and false if not . */
public static boolean isIdentical ( Vector3D_F64 a , Vector3D_F64 b , double tol ) { } }

implementation: if ( Math . abs ( a . x - b . x ) > tol ) return false ; if ( Math . abs ( a . y - b . y ) > tol ) return false ; return Math . abs ( a . z - b . z ) <= tol ;


signature:
public class UtilVector3D_F64 { /** * Rescales the vector such that its normal is equal to one .
 * @ param v Vector being normalized . */
public static void normalize ( Vector3D_F64 v ) { } }

implementation: double a = v . norm ( ) ; v . x /= a ; v . y /= a ; v . z /= a ;


signature:
public class UtilVector3D_F64 { /** * Creates a matrix from the set of column vectors . Each vector is a column in the new matrix .
 * @ param v Set of vectors . Not modified .
 * @ param R If not null the vectors are stored here .
 * @ return Matrix . */
public static DMatrixRMaj createMatrix ( DMatrixRMaj R , Vector3D_F64 ... v ) { } }

implementation: if ( R == null ) { R = new DMatrixRMaj ( 3 , v . length ) ; } for ( int i = 0 ; i < v . length ; i ++ ) { R . set ( 0 , i , v [ i ] . x ) ; R . set ( 1 , i , v [ i ] . y ) ; R . set ( 2 , i , v [ i ] . z ) ; } return R ;


signature:
public class UtilVector3D_F64 { /** * Converts matrices into vectors . All matrices must be vectors with 3 elements .
 * @ param m A 3x1 or 1x3 matrix
 * @ return Equivalent 3D vector */
public static Vector3D_F64 convert ( DMatrixRMaj m ) { } }

implementation: Vector3D_F64 v = new Vector3D_F64 ( ) ; v . x = ( double ) m . data [ 0 ] ; v . y = ( double ) m . data [ 1 ] ; v . z = ( double ) m . data [ 2 ] ; return v ;


signature:
public class UtilVector3D_F64 { /** * Returns the acute angle between the two vectors . Computed using the dot product .
 * @ param a vector
 * @ param b vector
 * @ return acute angle */
public static double acute ( GeoTuple3D_F64 a , GeoTuple3D_F64 b ) { } }

implementation: double dot = a . x * b . x + a . y * b . y + a . z * b . z ; double value = dot / ( a . norm ( ) * b . norm ( ) ) ; if ( value > 1.0 ) value = 1.0 ; else if ( value < - 1.0 ) value = - 1.0 ; return Math . acos ( value ) ;


signature:
public class GeoTuple3D_F64 { /** * < p > In - place addition < / p >
 * this . x = this . x + a . x ;
 * @ param a value which is to be added */
public void plusIP ( GeoTuple3D_F64 a ) { } }


signature:
public class GeoTuple3D_F64 { /** * < p > Addition < / p >
 * ret . x = this . x + a . x ;
 * @ param a value which is to be added */
public T plus ( GeoTuple3D_F64 a ) { } }

implementation: T ret = createNewInstance ( ) ; ret . x = x + a . x ; ret . y = y + a . y ; ret . z = z + a . z ; return ret ;


signature:
public class GeoTuple3D_F64 { /** * Scalar multiplication
 * @ param scalar value which is it multiplied by
 * @ return new matrix which is the original scaled */
public T times ( double scalar ) { } }

implementation: T ret = createNewInstance ( ) ; ret . x = x * scalar ; ret . y = y * scalar ; ret . z = z * scalar ; return ret ;


signature:
public class Intersection2D_I32 { /** * Checks to see if the two rectangles intersect each other
 * @ param a Rectangle
 * @ param b Rectangle
 * @ return true if intersection */
public static boolean intersects ( Rectangle2D_I32 a , Rectangle2D_I32 b ) { } }


signature:
public class Intersection2D_I32 { /** * Finds the intersection between two rectangles . If the rectangles don ' t intersect then false is returned .
 * @ param a Rectangle
 * @ param b Rectangle
 * @ param result Storage for the found intersection
 * @ return true if intersection */
public static boolean intersection ( Rectangle2D_I32 a , Rectangle2D_I32 b , Rectangle2D_I32 result ) { } }

implementation: if ( ! intersects ( a , b ) ) return false ; result . x0 = Math . max ( a . x0 , b . x0 ) ; result . x1 = Math . min ( a . x1 , b . x1 ) ; result . y0 = Math . max ( a . y0 , b . y0 ) ; result . y1 = Math . min ( a . y1 , b . y1 ) ; return true ;


signature:
public class Intersection2D_I32 { /** * http : / / www . ecse . rpi . edu / Homepages / wrf / Research / Short _ Notes / pnpoly . html */
public static boolean containConvex ( Polygon2D_I32 polygon , Point2D_I32 pt ) { } }

implementation: final int N = polygon . size ( ) ; boolean c = false ; for ( int i = 0 , j = N - 1 ; i < N ; j = i ++ ) { Point2D_I32 a = polygon . vertexes . data [ i ] ; Point2D_I32 b = polygon . vertexes . data [ j ] ; if ( ( ( a . y > pt . y ) != ( b . y > pt . y ) ) && ( pt . x < ( b . x - a . x ) * ( pt . y - a . y ) / ( b . y - a . y ) + a . x ) ) c = ! c ; } return c ;


signature:
public class Intersection2D_I32 { /** * Checks to see if the point is contained inside the concave polygon .
 * NOTE : Points which lie along the perimeter may or may not be considered as inside
 * @ param polygon Convex polygon . Not modified .
 * @ param pt Point . Not modified .
 * @ return True if the point is contained inside the polygon . */
public static boolean containConcave ( Polygon2D_I32 polygon , Point2D_I32 pt ) { } }

implementation:
final int N = polygon . size ( ) ; int left = 0 ; int right = 0 ; for ( int i = 0 ; i < N - 1 ; i ++ ) { Point2D_I32 a = polygon . vertexes . data [ i ] ; Point2D_I32 b = polygon . vertexes . data [ i + 1 ] ; if ( ( pt . y >= a . y && pt . y < b . y ) || ( pt . y >= b . y && pt . y < a . y ) ) { // location of line segment along x - axis at y = pt . y
double x = b . y == a . y ? pt . x : ( pt . y - a . y ) * ( b . x - a . x ) / ( double ) ( b . y - a . y ) + a . x ; if ( x <= pt . x ) left ++ ; else if ( x > pt . x ) right ++ ; } } Point2D_I32 a = polygon . vertexes . data [ N - 1 ] ; Point2D_I32 b = polygon . vertexes . data [ 0 ] ; if ( ( pt . y >= a . y && pt . y < b . y ) || ( pt . y >= b . y && pt . y < a . y ) ) { // location of line segment along x - axis at y = pt . y
double x = b . y == a . y ? pt . x : ( pt . y - pt . y ) * ( b . x - a . x ) / ( double ) ( b . y - a . y ) + a . x ; if ( x <= pt . x ) left ++ ; else if ( x > pt . x ) right ++ ; } return ( left % 2 == 1 && right % 2 == 1 ) ;


signature:
public class Intersection2D_I32 { /** * True if the point is contained inside the rectangle
 * @ param a Rectangle
 * @ param x x - coordinate of point
 * @ param y y - coordinate of point
 * @ return true if the point is inside and false it is not */
public static boolean contains ( RectangleLength2D_I32 a , int x , int y ) { } }

implementation: if ( a . getX ( ) <= x && a . getX ( ) + a . getWidth ( ) > x ) { return a . getY ( ) <= y && a . getY ( ) + a . getHeight ( ) > y ; } return false ;


signature:
public class Intersection2D_I32 { /** * True if the point is contained inside the rectangle
 * @ param a Rectangle
 * @ param x x - coordinate of point
 * @ param y y - coordinate of point
 * @ return true if the point is inside and false it is not */
public static boolean contains ( Rectangle2D_I32 a , int x , int y ) { } }


signature:
public class GeoTuple2D_F64 { /** * < p > Addition < / p >
 * ret . x = this . x + a . x ;
 * @ param a value which is to be added */
public T plus ( GeoTuple2D_F64 a ) { } }

implementation: T ret = createNewInstance ( ) ; ret . x = x + a . x ; ret . y = y + a . y ; return ret ;


signature:
public class GeoTuple2D_F64 { /** * Euclidean distance from the point
 * @ param x x - coordinate
 * @ param y y - coordinate
 * @ return distance */
public double distance ( double x , double y ) { } }

implementation: double dx = x - this . x ; double dy = y - this . y ; return Math . sqrt ( dx * dx + dy * dy ) ;


signature:
public class ClosestPointEllipseAngle_F64 { /** * Specifies the ellipse which point distance is going to be found from
 * @ param ellipse Ellipse description */
public void setEllipse ( EllipseRotated_F64 ellipse ) { } }

implementation: this . ellipse = ellipse ; ce = Math . cos ( ellipse . phi ) ; se = Math . sin ( ellipse . phi ) ;


signature:
public class ClosestPointEllipseAngle_F64 { /** * Find the closest point on the ellipse to the specified point . To get the solution call { @ link # getClosest ( ) }
 * @ param point Point which it is being fit to */
public void process ( Point2D_F64 point ) { } }

implementation:
// put point into ellipse ' s coordinate system
double xc = point . x - ellipse . center . x ; double yc = point . y - ellipse . center . y ; double x = ce * xc + se * yc ; double y = - se * xc + ce * yc ; // initial guess for the angle
theta = Math . atan2 ( ellipse . a * y , ellipse . b * x ) ; double a2_m_b2 = ellipse . a * ellipse . a - ellipse . b * ellipse . b ; // use Newton ' s Method to find the solution
int i = 0 ; for ( ; i < maxIterations ; i ++ ) { double c = Math . cos ( theta ) ; double s = Math . sin ( theta ) ; double f = a2_m_b2 * c * s - x * ellipse . a * s + y * ellipse . b * c ; if ( Math . abs ( f ) < tol ) break ; double d = a2_m_b2 * ( c * c - s * s ) - x * ellipse . a * c - y * ellipse . b * s ; theta = theta - f / d ; } // compute solution in ellipse coordinate frame
x = ellipse . a * ( double ) Math . cos ( theta ) ; y = ellipse . b * ( double ) Math . sin ( theta ) ; // put back into original coordinate system
closest . x = ce * x - se * y + ellipse . center . x ; closest . y = se * x + ce * y + ellipse . center . y ;


signature:
public class Quaternion_F64 { /** * Converts the quaternion into a unit quaternion . */
public void normalize ( ) { } }

implementation: double n = Math . sqrt ( w * w + x * x + y * y + z * z ) ; w /= n ; x /= n ; y /= n ; z /= n ;


signature:
public class FitConicA_F64 { /** * Fits the conic to the points . Strongly recommended that you transform the points such that they have
 * zero mean and a standard deviation along x and y axis , independently .
 * @ param points ( Input ) points
 * @ param output ( Output ) found conic
 * @ return true if successful or false if it failed */
@ Override public boolean process ( List < Point2D_F64 > points , ConicGeneral_F64 output ) { } }

implementation: final int N = points . size ( ) ; if ( N < 3 ) throw new IllegalArgumentException ( "At least 3 points required" ) ; A . reshape ( N , 6 ) ; for ( int i = 0 , index = 0 ; i < N ; i ++ ) { Point2D_F64 p = points . get ( i ) ; double x = p . x ; double y = p . y ; A . data [ index ++ ] = x * x ; A . data [ index ++ ] = x * y ; A . data [ index ++ ] = y * y ; A . data [ index ++ ] = x ; A . data [ index ++ ] = y ; A . data [ index ++ ] = 1 ; } if ( ! solver . process ( A , 1 , nullspace ) ) return false ; output . A = nullspace . data [ 0 ] ; output . B = nullspace . data [ 1 ] ; output . C = nullspace . data [ 2 ] ; output . D = nullspace . data [ 3 ] ; output . E = nullspace . data [ 4 ] ; output . F = nullspace . data [ 5 ] ; return true ;


signature:
public class Area2D_F64 { /** * Computes the area of an arbitrary triangle from 3 - vertices .
 * area = | a . x * ( b . y - c . y ) + b . x * ( c . y - a . y ) + c . x * ( a . y - b . y ) | / 2
 * @ param a Corner point 1
 * @ param b Corner point 2
 * @ param c Corner point 3
 * @ return area */
public static double triangle ( Point2D_F64 a , Point2D_F64 b , Point2D_F64 c ) { } }

implementation: double inner = a . x * ( b . y - c . y ) + b . x * ( c . y - a . y ) + c . x * ( a . y - b . y ) ; return Math . abs ( inner / 2.0 ) ;


signature:
public class Area2D_F64 { /** * Area of a quadrilateral computed from two triangles .
 * @ param quad quadrilateral
 * @ return area */
public static double quadrilateral ( Quadrilateral_F64 quad ) { } }

implementation: double bx = quad . b . x - quad . a . x ; double by = quad . b . y - quad . a . y ; double cx = quad . c . x - quad . a . x ; double cy = quad . c . y - quad . a . y ; double dx = quad . d . x - quad . a . x ; double dy = quad . d . y - quad . a . y ; if ( ( bx * cy - by * cx >= 0 ) == ( cx * dy - cy * dx >= 0 ) ) { return triangle ( quad . a , quad . b , quad . c ) + triangle ( quad . a , quad . c , quad . d ) ; } else { return triangle ( quad . a , quad . b , quad . d ) + triangle ( quad . b , quad . c , quad . d ) ; }


signature:
public class Area2D_F64 { /** * Area of a simple polygon . Meaning it can be concave or convex , but can ' t have self intersections
 * @ param poly Simple polygon
 * @ return area */
public static double polygonSimple ( Polygon2D_F64 poly ) { } }

implementation: double total = 0 ; Point2D_F64 v0 = poly . get ( 0 ) ; Point2D_F64 v1 = poly . get ( 1 ) ; for ( int i = 2 ; i < poly . size ( ) ; i ++ ) { Point2D_F64 v2 = poly . get ( i ) ; total += v1 . x * ( v2 . y - v0 . y ) ; v0 = v1 ; v1 = v2 ; } Point2D_F64 v2 = poly . get ( 0 ) ; total += v1 . x * ( v2 . y - v0 . y ) ; v0 = v1 ; v1 = v2 ; v2 = poly . get ( 1 ) ; total += v1 . x * ( v2 . y - v0 . y ) ; return Math . abs ( total / 2.0 ) ;


signature:
public class UtilPoint2D_F64 { /** * Finds the point which has the mean location of all the points in the list . This is also known
 * as the centroid .
 * @ param list List of points
 * @ param mean Storage for mean point . If null then a new instance will be declared
 * @ return The found mean */
public static Point2D_F64 mean ( List < Point2D_F64 > list , Point2D_F64 mean ) { } }

implementation: if ( mean == null ) mean = new Point2D_F64 ( ) ; double x = 0 ; double y = 0 ; for ( Point2D_F64 p : list ) { x += p . getX ( ) ; y += p . getY ( ) ; } x /= list . size ( ) ; y /= list . size ( ) ; mean . set ( x , y ) ; return mean ;


signature:
public class UtilPoint2D_F64 { /** * Finds the point which has the mean location of all the points in the array . This is also known
 * as the centroid .
 * @ param list List of points
 * @ param offset First index in list
 * @ param length Length of elements in list
 * @ param mean Storage for mean point . If null then a new instance will be declared
 * @ return The found mean */
public static Point2D_F64 mean ( Point2D_F64 [ ] list , int offset , int length , Point2D_F64 mean ) { } }

implementation: if ( mean == null ) mean = new Point2D_F64 ( ) ; double x = 0 ; double y = 0 ; for ( int i = 0 ; i < length ; i ++ ) { Point2D_F64 p = list [ offset + i ] ; x += p . getX ( ) ; y += p . getY ( ) ; } x /= length ; y /= length ; mean . set ( x , y ) ; return mean ;


signature:
public class UtilPoint2D_F64 { /** * Computes the mean / average of two points .
 * @ param a ( input ) Point A
 * @ param b ( input ) Point B
 * @ param mean ( output ) average of ' a ' and ' b ' */
public static Point2D_F64 mean ( Point2D_F64 a , Point2D_F64 b , Point2D_F64 mean ) { } }

implementation: if ( mean == null ) mean = new Point2D_F64 ( ) ; mean . x = ( a . x + b . x ) / 2.0 ; mean . y = ( a . y + b . y ) / 2.0 ; return mean ;


signature:
public class UtilPoint2D_F64 { /** * Finds the minimal volume { @ link georegression . struct . shapes . RectangleLength2D _ F64 } which contains all the points .
 * @ param points Input : List of points .
 * @ param bounding Output : Bounding rectangle */
public static RectangleLength2D_F64 bounding ( List < Point2D_F64 > points , RectangleLength2D_F64 bounding ) { } }

implementation:
if ( bounding == null ) bounding = new RectangleLength2D_F64 ( ) ; double minX = Double . MAX_VALUE , maxX = - Double . MAX_VALUE ; double minY = Double . MAX_VALUE , maxY = - Double . MAX_VALUE ; for ( int i = 0 ; i < points . size ( ) ; i ++ ) { Point2D_F64 p = points . get ( i ) ; if ( p . x < minX ) minX = p . x ; if ( p . x > maxX ) maxX = p . x ; if ( p . y < minY ) minY = p . y ; if ( p . y > maxY ) maxY = p . y ; } bounding . x0 = minX ; bounding . y0 = minY ; bounding . width = maxX - minX ; bounding . height = maxY - minY ; // make sure rounding doesn ' t cause a point to be out of bounds
bounding . width += Math . max ( 0 , ( maxX - ( bounding . x0 + bounding . width ) ) * 10.0 ) ; bounding . height += Math . max ( 0 , ( maxY - ( bounding . y0 + bounding . height ) ) * 10.0 ) ; return bounding ;


signature:
public class UtilPoint2D_F64 { /** * Finds the minimal volume { @ link georegression . struct . shapes . RectangleLength2D _ F64 } which contains all the points .
 * @ param points Input : List of points .
 * @ param bounding Output : Bounding rectangle */
public static Rectangle2D_F64 bounding ( List < Point2D_F64 > points , Rectangle2D_F64 bounding ) { } }

implementation: if ( bounding == null ) bounding = new Rectangle2D_F64 ( ) ; double minX = Double . MAX_VALUE , maxX = - Double . MAX_VALUE ; double minY = Double . MAX_VALUE , maxY = - Double . MAX_VALUE ; for ( int i = 0 ; i < points . size ( ) ; i ++ ) { Point2D_F64 p = points . get ( i ) ; if ( p . x < minX ) minX = p . x ; if ( p . x > maxX ) maxX = p . x ; if ( p . y < minY ) minY = p . y ; if ( p . y > maxY ) maxY = p . y ; } bounding . set ( minX , minY , maxX , maxY ) ; return bounding ;


signature:
public class UtilPoint2D_F64 { /** * Puts the points into counter - clockwise order around their center .
 * @ param points List of points . Not modified .
 * @ return ordered list */
public static List < Point2D_F64 > orderCCW ( List < Point2D_F64 > points ) { } }

implementation: Point2D_F64 center = mean ( points , null ) ; double angles [ ] = new double [ points . size ( ) ] ; for ( int i = 0 ; i < angles . length ; i ++ ) { Point2D_F64 p = points . get ( i ) ; double dx = p . x - center . x ; double dy = p . y - center . y ; angles [ i ] = Math . atan2 ( dy , dx ) ; } int order [ ] = new int [ points . size ( ) ] ; QuickSort_F64 sorter = new QuickSort_F64 ( ) ; sorter . sort ( angles , 0 , points . size ( ) , order ) ; List < Point2D_F64 > out = new ArrayList < Point2D_F64 > ( points . size ( ) ) ; for ( int i = 0 ; i < points . size ( ) ; i ++ ) { out . add ( points . get ( order [ i ] ) ) ; } return out ;


signature:
public class UtilPoint2D_F64 { /** * Computes the mean and covariance matrix from the set of points . This describes a normal distribution
 * @ param points ( Input ) points
 * @ param mean ( Output ) mean of the points
 * @ param covariance ( Output ) 2x2 covariance matrix */
public static void computeNormal ( List < Point2D_F64 > points , Point2D_F64 mean , DMatrix covariance ) { } }

implementation: if ( covariance . getNumCols ( ) != 2 || covariance . getNumRows ( ) != 2 ) { if ( covariance instanceof ReshapeMatrix ) { ( ( ReshapeMatrix ) covariance ) . reshape ( 2 , 2 ) ; } else { throw new IllegalArgumentException ( "Must be a 2x2 matrix" ) ; } } mean ( points , mean ) ; double xx = 0 , xy = 0 , yy = 0 ; for ( int i = 0 ; i < points . size ( ) ; i ++ ) { Point2D_F64 p = points . get ( i ) ; double dx = p . x - mean . x ; double dy = p . y - mean . y ; xx += dx * dx ; xy += dx * dy ; yy += dy * dy ; } xx /= points . size ( ) ; xy /= points . size ( ) ; yy /= points . size ( ) ; covariance . unsafe_set ( 0 , 0 , xx ) ; covariance . unsafe_set ( 0 , 1 , xy ) ; covariance . unsafe_set ( 1 , 0 , xy ) ; covariance . unsafe_set ( 1 , 1 , yy ) ;


signature:
public class UtilPoint2D_F64 { /** * Randomly generates points from the specified normal distribution
 * @ param mean ( Input ) mean
 * @ param covariance ( Output ) 2x2 covariance matrix
 * @ param count ( Input ) Number of points to create
 * @ param rand ( Input ) Random number generator
 * @ param output ( Output ) Optional storage for points . If null a new list is created
 * @ return List containing points . */
public static List < Point2D_F64 > randomNorm ( Point2D_F64 mean , DMatrix covariance , int count , Random rand , @ Nullable List < Point2D_F64 > output ) { } }

implementation:
if ( output == null ) output = new ArrayList < > ( ) ; // extract values of covariance
double cxx = covariance . get ( 0 , 0 ) ; double cxy = covariance . get ( 0 , 1 ) ; double cyy = covariance . get ( 1 , 1 ) ; // perform cholesky decomposition
double sxx = Math . sqrt ( cxx ) ; double sxy = cxy / cxx ; double syy = Math . sqrt ( cyy - sxy * sxy ) ; for ( int i = 0 ; i < count ; i ++ ) { Point2D_F64 p = new Point2D_F64 ( ) ; double x = rand . nextGaussian ( ) ; double y = rand . nextGaussian ( ) ; p . x = mean . x + sxx * x + sxy * y ; p . y = mean . y + sxy * x + syy * y ; output . add ( p ) ; } return output ;


signature:
public class LineGeneral2D_F64 { /** * A * x + B * y + C = 0
 * @ param a parameter A
 * @ param b parameter B
 * @ param c parameter C */
public void set ( double a , double b , double c ) { } }

implementation: this . A = a ; this . B = b ; this . C = c ;


signature:
public class LineGeneral2D_F64 { /** * Ensures that A * A + B * B = = 1 */
public void normalize ( ) { } }

implementation: double d = Math . sqrt ( A * A + B * B ) ; A /= d ; B /= d ; C /= d ;


signature:
public class Vector2D_F64 { /** * In - place minus operation . this = a - b .
 * @ param a Point
 * @ param b Point */
public void minus ( Point2D_F64 a , Point2D_F64 b ) { } }

implementation: x = a . x - b . x ; y = a . y - b . y ;


signature:
public class UtilPolygons2D_I32 { /** * Finds the minimum area bounding rectangle which is aligned to the x and y axis around the list of points .
 * Note ( x0 , y0 ) is inclusive and ( x1 , y1 ) is exclusive .
 * @ param points ( Input ) Quadrilateral
 * @ param rectangle ( Output ) Minimum area rectangle */
public static void bounding ( List < Point2D_I32 > points , Rectangle2D_I32 rectangle ) { } }

implementation: rectangle . x0 = Integer . MAX_VALUE ; rectangle . y0 = Integer . MAX_VALUE ; rectangle . x1 = Integer . MIN_VALUE ; rectangle . y1 = Integer . MIN_VALUE ; for ( int i = 0 ; i < points . size ( ) ; i ++ ) { Point2D_I32 p = points . get ( i ) ; if ( p . x < rectangle . x0 ) rectangle . x0 = p . x ; if ( p . x > rectangle . x1 ) rectangle . x1 = p . x ; if ( p . y < rectangle . y0 ) rectangle . y0 = p . y ; if ( p . y > rectangle . y1 ) rectangle . y1 = p . y ; } rectangle . x1 ++ ; rectangle . y1 ++ ;


signature:
public class UtilPolygons2D_I32 { /** * Finds the minimum area bounding rectangle which is aligned to the x and y axis around the polygon .
 * Note ( x0 , y0 ) is inclusive and ( x1 , y1 ) is exclusive .
 * @ param quad ( Input ) Quadrilateral
 * @ param rectangle ( Output ) Minimum area rectangle */
public static void bounding ( Polygon2D_I32 quad , Rectangle2D_I32 rectangle ) { } }

implementation: UtilPolygons2D_I32 . bounding ( quad . vertexes . toList ( ) , rectangle ) ;


signature:
public class UtilPolygons2D_I32 { /** * Returns true if the polygon is ordered in a counter - clockwise order . This is done by summing up the interior
 * angles .
 * @ param polygon List of ordered points which define a polygon
 * @ return true if CCW and false if CW */
public static boolean isCCW ( List < Point2D_I32 > polygon ) { } }

implementation: final int N = polygon . size ( ) ; int sign = 0 ; for ( int i = 0 ; i < N ; i ++ ) { int j = ( i + 1 ) % N ; int k = ( i + 2 ) % N ; if ( isPositiveZ ( polygon . get ( i ) , polygon . get ( j ) , polygon . get ( k ) ) ) { sign ++ ; } else { sign -- ; } } return sign < 0 ;


signature:
public class UtilPolygons2D_I32 { /** * Flips the order of points inside the polygon . The first index will remain the same will otherwise be reversed
 * @ param a Polygon of order 3 or more . */
public static void flip ( Polygon2D_I32 a ) { } }

implementation: int N = a . size ( ) ; int H = N / 2 ; for ( int i = 1 ; i <= H ; i ++ ) { int j = N - i ; Point2D_I32 tmp = a . vertexes . data [ i ] ; a . vertexes . data [ i ] = a . vertexes . data [ j ] ; a . vertexes . data [ j ] = tmp ; }


signature:
public class UtilPolygons2D_I32 { /** * Determines if the polugon is convex or concave .
 * @ param poly Polygon
 * @ return true if convex and false if concave */
public static boolean isConvex ( Polygon2D_I32 poly ) { } }

implementation:
// if the cross product of all consecutive triples is positive or negative then it is convex
final int N = poly . size ( ) ; int numPositive = 0 ; for ( int i = 0 ; i < N ; i ++ ) { int j = ( i + 1 ) % N ; int k = ( i + 2 ) % N ; Point2D_I32 a = poly . vertexes . data [ i ] ; Point2D_I32 b = poly . vertexes . data [ j ] ; Point2D_I32 c = poly . vertexes . data [ k ] ; int dx0 = a . x - b . x ; int dy0 = a . y - b . y ; int dx1 = c . x - b . x ; int dy1 = c . y - b . y ; int z = dx0 * dy1 - dy0 * dx1 ; if ( z > 0 ) numPositive ++ ; // z can be zero if there are duplicate points .
// not sure if it should throw an exception if its " bad " or not
} return ( numPositive == 0 || numPositive == N ) ;


signature:
public class UtilPolygons2D_I32 { /** * Returns true if the cross product would result in a strictly positive z ( e . g . z & gt ; 0 ) . If true then
 * the order is clockwise .
 * v0 = a - b
 * v1 = c - b
 * @ param a first point in sequence
 * @ param b second point in sequence
 * @ param c third point in sequence
 * @ return true if positive z */
public static boolean isPositiveZ ( Point2D_I32 a , Point2D_I32 b , Point2D_I32 c ) { } }

implementation: int dx0 = a . x - b . x ; int dy0 = a . y - b . y ; int dx1 = c . x - b . x ; int dy1 = c . y - b . y ; int z = dx0 * dy1 - dy0 * dx1 ; return z > 0 ;


signature:
public class UtilPolygons2D_I32 { /** * Checks to see if the vertexes of the two polygon ' s are the same up to the specified tolerance
 * @ param a Polygon
 * @ param b Polygon
 * @ return true if identical up to tolerance or false if not */
public static boolean isIdentical ( Polygon2D_I32 a , Polygon2D_I32 b ) { } }

implementation: if ( a . size ( ) != b . size ( ) ) return false ; for ( int i = 0 ; i < a . size ( ) ; i ++ ) { if ( ! a . get ( i ) . equals ( b . get ( i ) ) ) return false ; } return true ;


signature:
public class UtilPolygons2D_I32 { /** * Checks to see if the vertexes of the two polygon ' s are the same up to the specified tolerance and allows
 * for a shift in their order
 * @ param a Polygon
 * @ param b Polygon
 * @ return true if identical up to tolerance or false if not */
public static boolean isEquivalent ( Polygon2D_I32 a , Polygon2D_I32 b ) { } }

implementation:
if ( a . size ( ) != b . size ( ) ) return false ; // first find two vertexes which are the same
Point2D_I32 a0 = a . get ( 0 ) ; int match = - 1 ; for ( int i = 0 ; i < b . size ( ) ; i ++ ) { if ( a0 . equals ( b . get ( i ) ) ) { match = i ; break ; } } if ( match < 0 ) return false ; // now go in a circle and see if they all line up
for ( int i = 1 ; i < b . size ( ) ; i ++ ) { Point2D_I32 ai = a . get ( i ) ; Point2D_I32 bi = b . get ( ( match + i ) % b . size ( ) ) ; if ( ! ai . equals ( bi ) ) { return false ; } } return true ;


signature:
public class UtilPoint2D_I32 { /** * Finds the point which has the mean location of all the points in the list . This is also known
 * as the centroid .
 * @ param list List of points
 * @ param mean Storage for mean point . If null then a new instance will be declared
 * @ return The found mean */
public static Point2D_I32 mean ( List < Point2D_I32 > list , Point2D_I32 mean ) { } }

implementation: if ( mean == null ) mean = new Point2D_I32 ( ) ; int sumX = 0 , sumY = 0 ; int N = list . size ( ) ; for ( int i = 0 ; i < N ; i ++ ) { Point2D_I32 p = list . get ( i ) ; sumX += p . x ; sumY += p . y ; } mean . x = sumX / N ; mean . y = sumY / N ; return mean ;


signature:
public class GeoTuple4D_F64 { /** * < p > In - place addition < / p >
 * this . x = this . x + a . x ;
 * @ param a value which is to be added */
public void plusIP ( GeoTuple4D_F64 a ) { } }


signature:
public class GeoTuple4D_F64 { /** * In - place scalar multiplication
 * @ param scalar value that it is multiplied by */
public void timesIP ( double scalar ) { } }

implementation: x *= scalar ; y *= scalar ; z *= scalar ; w *= scalar ;


signature:
public class GeoTuple4D_F64 { /** * Returns the absolute value of the component with the largest absolute value
 * @ return max absolute value */
public double maxAbs ( ) { } }

implementation: double absX = Math . abs ( x ) ; double absY = Math . abs ( y ) ; double absZ = Math . abs ( z ) ; double absW = Math . abs ( w ) ; double found = Math . max ( absX , absY ) ; if ( found < absZ ) found = absZ ; if ( found < absW ) found = absW ; return found ;


signature:
public class FitCurve_F64 { /** * < p > Fits points to the quadratic polynomial . It ' s recommended that you apply a linear transform to the points
 * to ensure that they have zero mean and a standard deviation of 1 . Then reverse the transform on the result .
 * A solution is found using the pseudo inverse and inverse by minor matrices . < / p >
 * < p > For a more numerically stable algorithm see { @ link # fitQRP ( double [ ] , int , int , PolynomialQuadratic1D _ F64 ) } < / p >
 * @ param data Interleaved data [ input [ 0 ] , output [ 0 ] , . . . .
 * @ param offset first index in data
 * @ param length number of elements in data that are to be read . must be divisible by 2
 * @ param output ( Optional ) storage for the curve
 * @ return The fitted curve */
public static boolean fitMM ( double [ ] data , int offset , int length , PolynomialQuadratic1D_F64 output , @ Nullable DMatrix3x3 work ) { } }

implementation:
if ( work == null ) work = new DMatrix3x3 ( ) ; final int N = length / 2 ; // Unrolled pseudo inverse
// coef = inv ( A ^ T * A ) * A ^ T * y
double sx0 = N , sx1 = 0 , sx2 = 0 ; double sx3 = 0 ; double sx4 = 0 ; double b0 = 0 , b1 = 0 , b2 = 0 ; int end = offset + length ; for ( int i = offset ; i < end ; i += 2 ) { double x = data [ i ] ; double y = data [ i + 1 ] ; double x2 = x * x ; sx1 += x ; sx2 += x2 ; sx3 += x2 * x ; sx4 += x2 * x2 ; b0 += y ; b1 += x * y ; b2 += x2 * y ; } DMatrix3x3 A = work ; A . set ( sx0 , sx1 , sx2 , sx1 , sx2 , sx3 , sx2 , sx3 , sx4 ) ; if ( ! CommonOps_DDF3 . invert ( A , A ) ) // TODO use a symmetric inverse . Should be slightly faster
return false ; // output = inv ( A ) * B Unrolled here for speed
output . a = A . a11 * b0 + A . a12 * b1 + A . a13 * b2 ; output . b = A . a21 * b0 + A . a22 * b1 + A . a23 * b2 ; output . c = A . a31 * b0 + A . a32 * b1 + A . a33 * b2 ; return true ;


signature:
public class FitCurve_F64 { /** * < p > Fits points to the quadratic polynomial using a QRP linear solver . < / p >
 * @ see FitPolynomialSolverTall _ F64
 * @ param data Interleaved data [ input [ 0 ] , output [ 0 ] , . . . .
 * @ param offset first index in data
 * @ param length number of elements in data that are to be read . must be divisible by 2
 * @ param output ( Optional ) storage for the curve
 * @ return The fitted curve */
public static boolean fitQRP ( double [ ] data , int offset , int length , PolynomialQuadratic1D_F64 output ) { } }

implementation: FitPolynomialSolverTall_F64 solver = new FitPolynomialSolverTall_F64 ( ) ; return solver . process ( data , offset , length , output ) ;


signature:
public class FitCurve_F64 { /** * < p > Fits points to the cubic polynomial . It ' s recommended that you apply a linear transform to the points
 * to ensure that they have zero mean and a standard deviation of 1 . Then reverse the transform on the result .
 * A solution is found using the pseudo inverse and inverse by minor matrices . < / p >
 * < p > For a more numerically stable algorithm see { @ link # fitQRP ( double [ ] , int , int , PolynomialQuadratic1D _ F64 ) } < / p >
 * @ param data Interleaved data [ input [ 0 ] , output [ 0 ] , . . . .
 * @ param offset first index in data
 * @ param length number of elements in data that are to be read . must be divisible by 2
 * @ param output ( Optional ) storage for the curve
 * @ return The fitted curve */
public static boolean fitMM ( double [ ] data , int offset , int length , PolynomialCubic1D_F64 output , @ Nullable DMatrix4x4 A ) { } }

implementation:
if ( A == null ) A = new DMatrix4x4 ( ) ; final int N = length / 2 ; if ( N < 4 ) throw new IllegalArgumentException ( "Need at least 4 points and not " + N ) ; // Unrolled pseudo inverse
// coef = inv ( A ^ T * A ) * A ^ T * y
double sx1 = 0 , sx2 = 0 , sx3 = 0 , sx4 = 0 , sx5 = 0 , sx6 = 0 ; double b0 = 0 , b1 = 0 , b2 = 0 , b3 = 0 ; int end = offset + length ; for ( int i = offset ; i < end ; i += 2 ) { double x = data [ i ] ; double y = data [ i + 1 ] ; double x2 = x * x ; double x3 = x2 * x ; double x4 = x2 * x2 ; sx1 += x ; sx2 += x2 ; sx3 += x3 ; sx4 += x4 ; sx5 += x4 * x ; sx6 += x4 * x2 ; b0 += y ; b1 += x * y ; b2 += x2 * y ; b3 += x3 * y ; } A . set ( N , sx1 , sx2 , sx3 , sx1 , sx2 , sx3 , sx4 , sx2 , sx3 , sx4 , sx5 , sx3 , sx4 , sx5 , sx6 ) ; if ( ! CommonOps_DDF4 . invert ( A , A ) ) // TODO use a symmetric inverse . Should be slightly faster
return false ; // output = inv ( A ) * B Unrolled here for speed
output . a = A . a11 * b0 + A . a12 * b1 + A . a13 * b2 + A . a14 * b3 ; output . b = A . a21 * b0 + A . a22 * b1 + A . a23 * b2 + A . a24 * b3 ; output . c = A . a31 * b0 + A . a32 * b1 + A . a33 * b2 + A . a34 * b3 ; output . d = A . a41 * b0 + A . a42 * b1 + A . a43 * b2 + A . a44 * b3 ; return true ;


signature:
public class FitCurve_F64 { /** * < p > Fits points to a 2D quadratic polynomial . There are two inputs and one output for each data point .
 * It ' s recommended that you apply a linear transform to the points . < / p >
 * @ param data Interleaved data [ inputA [ 0 ] , inputB [ 0 ] , output [ 0 ] , . . . .
 * @ param offset first index in data
 * @ param length number of elements in data that are to be read . must be divisible by 2
 * @ param output ( Optional ) storage for the curve
 * @ return The fitted curve */
public static boolean fit ( double [ ] data , int offset , int length , PolynomialQuadratic2D_F64 output ) { } }

implementation:
final int N = length / 3 ; if ( N < 6 ) throw new IllegalArgumentException ( "Need at least 6 points and not " + N ) ; // Unrolled pseudo inverse
// coef = inv ( A ^ T * A ) * A ^ T * y
double sx1 = 0 , sy1 = 0 , sx1y1 = 0 , sx2 = 0 , sy2 = 0 , sx2y1 = 0 , sx1y2 = 0 , sx2y2 = 0 , sx3 = 0 , sy3 = 0 , sx3y1 = 0 , sx1y3 = 0 , sx4 = 0 , sy4 = 0 ; double b0 = 0 , b1 = 0 , b2 = 0 , b3 = 0 , b4 = 0 , b5 = 0 ; int end = offset + length ; for ( int i = offset ; i < end ; i += 3 ) { double x = data [ i ] ; double y = data [ i + 1 ] ; double z = data [ i + 2 ] ; double x2 = x * x ; double x3 = x2 * x ; double x4 = x2 * x2 ; double y2 = y * y ; double y3 = y2 * y ; double y4 = y2 * y2 ; sx1 += x ; sx2 += x2 ; sx3 += x3 ; sx4 += x4 ; sy1 += y ; sy2 += y2 ; sy3 += y3 ; sy4 += y4 ; sx1y1 += x * y ; sx2y1 += x2 * y ; sx1y2 += x * y2 ; sx2y2 += x2 * y2 ; sx3y1 += x3 * y ; sx1y3 += x * y3 ; b0 += z ; b1 += x * z ; b2 += y * z ; b3 += x * y * z ; b4 += x2 * z ; b5 += y2 * z ; } // using a fixed size matrix because the notation is much nicer
DMatrix6x6 A = new DMatrix6x6 ( ) ; A . set ( N , sx1 , sy1 , sx1y1 , sx2 , sy2 , sx1 , sx2 , sx1y1 , sx2y1 , sx3 , sx1y2 , sy1 , sx1y1 , sy2 , sx1y2 , sx2y1 , sy3 , sx1y1 , sx2y1 , sx1y2 , sx2y2 , sx3y1 , sx1y3 , sx2 , sx3 , sx2y1 , sx3y1 , sx4 , sx2y2 , sy2 , sx1y2 , sy3 , sx1y3 , sx2y2 , sy4 ) ; DMatrixRMaj _A = new DMatrixRMaj ( 6 , 6 ) ; ConvertDMatrixStruct . convert ( A , _A ) ; // pseudo inverse is required to handle degenerate matrices , e . g . lines
LinearSolverDense < DMatrixRMaj > solver = LinearSolverFactory_DDRM . pseudoInverse ( true ) ; if ( ! solver . setA ( _A ) ) return false ; solver . invert ( _A ) ; DMatrixRMaj B = new DMatrixRMaj ( 6 , 1 , true , b0 , b1 , b2 , b3 , b4 , b5 ) ; DMatrixRMaj Y = new DMatrixRMaj ( 6 , 1 ) ; CommonOps_DDRM . mult ( _A , B , Y ) ; // output = inv ( A ) * B Unrolled here for speed
output . a = Y . data [ 0 ] ; output . b = Y . data [ 1 ] ; output . c = Y . data [ 2 ] ; output . d = Y . data [ 3 ] ; output . e = Y . data [ 4 ] ; output . f = Y . data [ 5 ] ; return true ;


signature:
public class UtilPoint3D_F64 { /** * Euclidean distance between the two specified points
 * @ param x0 x - axis on Point 0
 * @ param y0 y - axis on Point 0
 * @ param z0 z - axis on Point 0
 * @ param x1 x - axis on Point 1
 * @ param y1 y - axis on Point 1
 * @ param z1 z - axis on Point 1
 * @ return Euclidean distance */
public static double distance ( double x0 , double y0 , double z0 , double x1 , double y1 , double z1 ) { } }

implementation: return norm ( x1 - x0 , y1 - y0 , z1 - z0 ) ;


signature:
public class UtilPoint3D_F64 { /** * Euclidean distance squared between the two specified points
 * @ param x0 x - axis on Point 0
 * @ param y0 y - axis on Point 0
 * @ param z0 z - axis on Point 0
 * @ param x1 x - axis on Point 1
 * @ param y1 y - axis on Point 1
 * @ param z1 z - axis on Point 1
 * @ return Euclidean distance squared */
public static double distanceSq ( double x0 , double y0 , double z0 , double x1 , double y1 , double z1 ) { } }

implementation: double dx = x1 - x0 ; double dy = y1 - y0 ; double dz = z1 - z0 ; return dx * dx + dy * dy + dz * dz ;


signature:
public class UtilPoint3D_F64 { /** * Randomly generates a set of points on the plane centered at the plane ' s origin
 * using a uniform distribution .
 * @ param plane Plane
 * @ param max Maximum distance from center
 * @ param rand random number generator
 * @ return set of points on the plane */
public static List < Point3D_F64 > random ( PlaneNormal3D_F64 plane , double max , int num , Random rand ) { } }

implementation: List < Point3D_F64 > ret = new ArrayList < > ( ) ; Vector3D_F64 axisX = new Vector3D_F64 ( ) ; Vector3D_F64 axisY = new Vector3D_F64 ( ) ; UtilPlane3D_F64 . selectAxis2D ( plane . n , axisX , axisY ) ; for ( int i = 0 ; i < num ; i ++ ) { double x = 2 * max * ( rand . nextDouble ( ) - 0.5 ) ; double y = 2 * max * ( rand . nextDouble ( ) - 0.5 ) ; Point3D_F64 p = new Point3D_F64 ( ) ; p . x = plane . p . x + axisX . x * x + axisY . x * y ; p . y = plane . p . y + axisX . y * x + axisY . y * y ; p . z = plane . p . z + axisX . z * x + axisY . z * y ; ret . add ( p ) ; } return ret ;


signature:
public class UtilPoint3D_F64 { /** * Creates a list of random points from a uniform distribution along each axis */
public static List < Point3D_F64 > random ( Point3D_F64 mean , double minX , double maxX , double minY , double maxY , double minZ , double maxZ , int num , Random rand ) { } }

implementation: List < Point3D_F64 > ret = new ArrayList < > ( ) ; for ( int i = 0 ; i < num ; i ++ ) { Point3D_F64 p = new Point3D_F64 ( ) ; p . x = mean . x + rand . nextDouble ( ) * ( maxX - minX ) + minX ; p . y = mean . y + rand . nextDouble ( ) * ( maxY - minY ) + minY ; p . z = mean . z + rand . nextDouble ( ) * ( maxZ - minZ ) + minZ ; ret . add ( p ) ; } return ret ;


signature:
public class UtilPoint3D_F64 { /** * Creates a list of random points from a normal distribution along each axis */
public static List < Point3D_F64 > randomN ( Point3D_F64 mean , double stdX , double stdY , double stdZ , int num , Random rand ) { } }

implementation: List < Point3D_F64 > ret = new ArrayList < > ( ) ; for ( int i = 0 ; i < num ; i ++ ) { Point3D_F64 p = new Point3D_F64 ( ) ; p . x = mean . x + rand . nextGaussian ( ) * stdX ; p . y = mean . y + rand . nextGaussian ( ) * stdY ; p . z = mean . z + rand . nextGaussian ( ) * stdZ ; ret . add ( p ) ; } return ret ;


signature:
public class UtilPoint3D_F64 { /** * Computes the mean of the list of points .
 * @ param points List of points
 * @ param mean ( Optional ) storage for the mean . Can be null
 * @ return Mean */
public static Point3D_F64 mean ( List < Point3D_F64 > points , Point3D_F64 mean ) { } }

implementation: if ( mean == null ) mean = new Point3D_F64 ( ) ; double x = 0 , y = 0 , z = 0 ; for ( Point3D_F64 p : points ) { x += p . x ; y += p . y ; z += p . z ; } mean . x = x / points . size ( ) ; mean . y = y / points . size ( ) ; mean . z = z / points . size ( ) ; return mean ;


signature:
public class UtilPoint3D_F64 { /** * Computes the mean of the list of points up to element num .
 * @ param points List of points
 * @ param num use points up to num , exclusive .
 * @ param mean ( Optional ) storage for the mean . Can be null
 * @ return Mean */
public static Point3D_F64 mean ( List < Point3D_F64 > points , int num , Point3D_F64 mean ) { } }

implementation: if ( mean == null ) mean = new Point3D_F64 ( ) ; double x = 0 , y = 0 , z = 0 ; for ( int i = 0 ; i < num ; i ++ ) { Point3D_F64 p = points . get ( i ) ; x += p . x ; y += p . y ; z += p . z ; } mean . x = x / num ; mean . y = y / num ; mean . z = z / num ; return mean ;


signature:
public class UtilPoint3D_F64 { /** * Finds the minimal volume { @ link Box3D _ F64 } which contains all the points .
 * @ param points Input : List of points .
 * @ param bounding Output : Bounding box */
public static void boundingBox ( List < Point3D_F64 > points , Box3D_F64 bounding ) { } }

implementation: double minX = Double . MAX_VALUE , maxX = - Double . MAX_VALUE ; double minY = Double . MAX_VALUE , maxY = - Double . MAX_VALUE ; double minZ = Double . MAX_VALUE , maxZ = - Double . MAX_VALUE ; for ( int i = 0 ; i < points . size ( ) ; i ++ ) { Point3D_F64 p = points . get ( i ) ; if ( p . x < minX ) minX = p . x ; if ( p . x > maxX ) maxX = p . x ; if ( p . y < minY ) minY = p . y ; if ( p . y > maxY ) maxY = p . y ; if ( p . z < minZ ) minZ = p . z ; if ( p . z > maxZ ) maxZ = p . z ; } bounding . p0 . set ( minX , minY , minZ ) ; bounding . p1 . set ( maxX , maxY , maxZ ) ;


signature:
public class CachingJwtAuthenticator { /** * Discards any cached principal for the given collection of credentials .
 * @ param credentials a collection of credentials */
public void invalidateAll ( Iterable < JwtContext > credentials ) { } }

implementation: credentials . forEach ( context -> cache . invalidate ( context . getJwt ( ) ) ) ;


signature:
public class CachingJwtAuthenticator { /** * Discards any cached principal for the collection of credentials satisfying the given predicate .
 * @ param predicate a predicate to filter credentials */
public void invalidateAll ( Predicate < ? super JwtContext > predicate ) { } }

implementation: cache . asMap ( ) . entrySet ( ) . stream ( ) . map ( entry -> entry . getValue ( ) . getKey ( ) ) . filter ( predicate :: test ) . map ( JwtContext :: getJwt ) . forEach ( cache :: invalidate ) ;


signature:
public class InstallFeatureUtil { /** * Combine the given String collections into a set using case - insensitive matching .
 * If there are multiple instances of the same string but with different capitalization ,
 * only the first one found will be included .
 * @ param collections a collection of strings
 * @ return the combined set of strings , ignoring case */
@ SafeVarargs public static Set < String > combineToSet ( Collection < String > ... collections ) { } }

implementation: Set < String > result = new HashSet < String > ( ) ; Set < String > lowercaseSet = new HashSet < String > ( ) ; for ( Collection < String > collection : collections ) { if ( collection != null ) { for ( String value : collection ) { if ( ! lowercaseSet . contains ( value . toLowerCase ( ) ) ) { lowercaseSet . add ( value . toLowerCase ( ) ) ; result . add ( value ) ; } } } } return result ;


signature:
public class InstallFeatureUtil { /** * Get the set of features defined in the server . xml
 * @ param serverDirectory The server directory containing the server . xml
 * @ return the set of features that should be installed from server . xml , or empty set if nothing should be installed */
public Set < String > getServerFeatures ( File serverDirectory ) { } }

implementation:
Set < String > result = getConfigDropinsFeatures ( null , serverDirectory , "defaults" ) ; result = getServerXmlFeatures ( result , new File ( serverDirectory , "server.xml" ) , null ) ; // add the overrides at the end since they should not be replaced by any previous content
return getConfigDropinsFeatures ( result , serverDirectory , "overrides" ) ;


signature:
public class InstallFeatureUtil { /** * Gets features from the configDropins ' s defaults or overrides directory
 * @ param origResult
 * The features that have been parsed so far .
 * @ param serverDirectory
 * The server directory
 * @ param folderName
 * The folder under configDropins : either " defaults " or
 * " overrides "
 * @ return The set of features to install , or empty set if the cumulatively
 * parsed xml files only have featureManager sections but no
 * features to install , or null if there are no valid xml files or
 * they have no featureManager section */
private Set < String > getConfigDropinsFeatures ( Set < String > origResult , File serverDirectory , String folderName ) { } }

implementation:
Set < String > result = origResult ; File configDropinsFolder ; try { configDropinsFolder = new File ( new File ( serverDirectory , "configDropins" ) , folderName ) . getCanonicalFile ( ) ; } catch ( IOException e ) { // skip this directory if its path cannot be queried
warn ( "The " + serverDirectory + "/configDropins/" + folderName + " directory cannot be accessed. Skipping its server features." ) ; debug ( e ) ; return result ; } File [ ] configDropinsXmls = configDropinsFolder . listFiles ( new FilenameFilter ( ) { @ Override public boolean accept ( File dir , String name ) { return name . endsWith ( ".xml" ) ; } } ) ; if ( configDropinsXmls == null || configDropinsXmls . length == 0 ) { return result ; } // sort the files in alphabetical order so that overrides will happen in the proper order
Comparator < File > comparator = new Comparator < File > ( ) { @ Override public int compare ( File left , File right ) { return left . getAbsolutePath ( ) . toLowerCase ( ) . compareTo ( right . getAbsolutePath ( ) . toLowerCase ( ) ) ; } } ; Collections . sort ( Arrays . asList ( configDropinsXmls ) , comparator ) ; for ( File xml : configDropinsXmls ) { Set < String > features = getServerXmlFeatures ( result , xml , null ) ; if ( features != null ) { result = features ; } } return result ;


signature:
public class InstallFeatureUtil { /** * Adds features from the given server file into the origResult or a new set
 * if origResult is null .
 * @ param origResult
 * The features that have been parsed so far .
 * @ param serverFile
 * The server XML file .
 * @ param parsedXmls
 * The list of XML files that have been parsed so far .
 * @ return The set of features to install , or empty set if the cumulatively
 * parsed xml files only have featureManager sections but no
 * features to install , or null if there are no valid xml files or
 * they have no featureManager section */
private Set < String > getServerXmlFeatures ( Set < String > origResult , File serverFile , List < File > parsedXmls ) { } }

implementation:
Set < String > result = origResult ; List < File > updatedParsedXmls = parsedXmls != null ? parsedXmls : new ArrayList < File > ( ) ; File canonicalServerFile ; try { canonicalServerFile = serverFile . getCanonicalFile ( ) ; } catch ( IOException e ) { // skip this server . xml if its path cannot be queried
warn ( "The server file " + serverFile + " cannot be accessed. Skipping its features." ) ; debug ( e ) ; return result ; } updatedParsedXmls . add ( canonicalServerFile ) ; if ( canonicalServerFile . exists ( ) ) { try { Document doc = new XmlDocument ( ) { public Document getDocument ( File file ) throws IOException , ParserConfigurationException , SAXException { createDocument ( file ) ; return doc ; } } . getDocument ( canonicalServerFile ) ; Element root = doc . getDocumentElement ( ) ; NodeList nodes = root . getChildNodes ( ) ; for ( int i = 0 ; i < nodes . getLength ( ) ; i ++ ) { if ( nodes . item ( i ) instanceof Element ) { Element child = ( Element ) nodes . item ( i ) ; if ( "featureManager" . equals ( child . getNodeName ( ) ) ) { if ( result == null ) { result = new HashSet < String > ( ) ; } result . addAll ( parseFeatureManagerNode ( child ) ) ; } else if ( "include" . equals ( child . getNodeName ( ) ) ) { result = parseIncludeNode ( result , canonicalServerFile , child , updatedParsedXmls ) ; } } } } catch ( IOException | ParserConfigurationException | SAXException e ) { // just skip this server . xml if it cannot be parsed
warn ( "The server file " + serverFile + " cannot be parsed. Skipping its features." ) ; debug ( e ) ; return result ; } } return result ;


signature:
public class InstallFeatureUtil { /** * Parse features from an include node .
 * @ param origResult
 * The features that have been parsed so far .
 * @ param serverFile
 * The parent server XML file containing the include node .
 * @ param node
 * The include node .
 * @ param updatedParsedXmls
 * The list of XML files that have been parsed so far .
 * @ return The set of features to install , or empty set if the cumulatively
 * parsed xml files only have featureManager sections but no
 * features to install , or null if there are no valid xml files or
 * they have no featureManager section */
private Set < String > parseIncludeNode ( Set < String > origResult , File serverFile , Element node , List < File > updatedParsedXmls ) { } }

implementation:
Set < String > result = origResult ; String includeFileName = node . getAttribute ( "location" ) ; if ( includeFileName == null || includeFileName . trim ( ) . isEmpty ( ) ) { return result ; } File includeFile = null ; if ( isURL ( includeFileName ) ) { try { File tempFile = File . createTempFile ( "serverFromURL" , ".xml" ) ; FileUtils . copyURLToFile ( new URL ( includeFileName ) , tempFile , COPY_FILE_TIMEOUT_MILLIS , COPY_FILE_TIMEOUT_MILLIS ) ; includeFile = tempFile ; } catch ( IOException e ) { // skip this xml if it cannot be accessed from URL
warn ( "The server file " + serverFile + " includes a URL " + includeFileName + " that cannot be accessed. Skipping the included features." ) ; debug ( e ) ; return result ; } } else { includeFile = new File ( includeFileName ) ; } try { if ( ! includeFile . isAbsolute ( ) ) { includeFile = new File ( serverFile . getParentFile ( ) . getAbsolutePath ( ) , includeFileName ) . getCanonicalFile ( ) ; } else { includeFile = includeFile . getCanonicalFile ( ) ; } } catch ( IOException e ) { // skip this xml if its path cannot be queried
warn ( "The server file " + serverFile + " includes a file " + includeFileName + " that cannot be accessed. Skipping the included features." ) ; debug ( e ) ; return result ; } if ( ! updatedParsedXmls . contains ( includeFile ) ) { String onConflict = node . getAttribute ( "onConflict" ) ; Set < String > features = getServerXmlFeatures ( null , includeFile , updatedParsedXmls ) ; result = handleOnConflict ( result , onConflict , features ) ; } return result ;


signature:
public class InstallFeatureUtil { /** * Parse feature elements from a featureManager node , trimming whitespace
 * and treating everything as lowercase .
 * @ param node
 * The featureManager node
 * @ return Set of trimmed lowercase feature names */
private static Set < String > parseFeatureManagerNode ( Element node ) { } }

implementation: Set < String > result = new HashSet < String > ( ) ; NodeList features = node . getElementsByTagName ( "feature" ) ; if ( features != null ) { for ( int j = 0 ; j < features . getLength ( ) ; j ++ ) { String content = features . item ( j ) . getTextContent ( ) ; if ( content != null ) { if ( content . contains ( ":" ) ) { String [ ] split = content . split ( ":" , 2 ) ; result . add ( split [ 1 ] . trim ( ) . toLowerCase ( ) ) ; } else { result . add ( content . trim ( ) . toLowerCase ( ) ) ; } } } } return result ;


signature:
public class InstallFeatureUtil { /** * Get the JSON files corresponding to the product properties from the lib / versions / * . properties files
 * @ return the set of JSON files for the product
 * @ throws PluginExecutionException if properties files could not be found from lib / versions */
private Set < File > downloadProductJsons ( ) throws PluginExecutionException { } }

implementation:
// download JSONs
Set < File > downloadedJsons = new HashSet < File > ( ) ; for ( ProductProperties properties : propertiesList ) { File json = downloadJsons ( properties . getId ( ) , properties . getVersion ( ) ) ; if ( json != null ) { downloadedJsons . add ( json ) ; } } return downloadedJsons ;


signature:
public class InstallFeatureUtil { /** * Download the JSON file for the given product .
 * @ param productId The product ID from the runtime ' s properties file
 * @ param productVersion The product version from the runtime ' s properties file
 * @ return The JSON file , or null if not found */
private File downloadJsons ( String productId , String productVersion ) { } }

implementation: String jsonGroupId = productId + ".features" ; try { return downloadArtifact ( jsonGroupId , "features" , "json" , productVersion ) ; } catch ( PluginExecutionException e ) { debug ( "Cannot find json for productId " + productId + ", productVersion " + productVersion , e ) ; return null ; }


signature:
public class InstallFeatureUtil { /** * Returns true if this scenario is not supported for installing from Maven
 * repository , which is one of the following conditions : " from " parameter is
 * specified ( don ' t need Maven repositories ) , or esa files are specified in
 * the configuration ( not supported with Maven for now )
 * @ param from
 * the " from " parameter specified in the plugin
 * @ param pluginListedEsas
 * the ESA files specified in the plugin configuration
 * @ return true if the fallback scenario occurred , false otherwise */
private boolean hasUnsupportedParameters ( String from , Set < String > pluginListedEsas ) { } }

implementation: boolean hasFrom = from != null ; boolean hasPluginListedEsas = ! pluginListedEsas . isEmpty ( ) ; debug ( "hasFrom: " + hasFrom ) ; debug ( "hasPluginListedEsas: " + hasPluginListedEsas ) ; return hasFrom || hasPluginListedEsas ;


signature:
public class InstallFeatureUtil { /** * Gets the set of all Open Liberty features by scanning the product JSONs .
 * @ param jsons The set of product JSON files to scan
 * @ return set of all Open Liberty features
 * @ throws PluginExecutionException if any of the JSONs could not be found */
public static Set < String > getOpenLibertyFeatureSet ( Set < File > jsons ) throws PluginExecutionException { } }

implementation:
Set < String > libertyFeatures = new HashSet < String > ( ) ; for ( File file : jsons ) { Scanner s = null ; try { s = new Scanner ( file ) ; // scan Maven coordinates for artifactIds that belong to the Open Liberty groupId
while ( s . findWithinHorizon ( OPEN_LIBERTY_GROUP_ID + ":([^:]*):" , 0 ) != null ) { MatchResult match = s . match ( ) ; if ( match . groupCount ( ) >= 1 ) { libertyFeatures . add ( match . group ( 1 ) ) ; } } } catch ( FileNotFoundException e ) { throw new PluginExecutionException ( "The JSON file is not found at " + file . getAbsolutePath ( ) , e ) ; } finally { if ( s != null ) { s . close ( ) ; } } } return libertyFeatures ;


signature:
public class InstallFeatureUtil { /** * Returns true if all features in featuresToInstall are Open Liberty features .
 * @ param featuresToInstall list of features to check
 * @ return true if featureToInstall has only Open Liberty features
 * @ throws PluginExecutionException if any of the downloaded JSONs could not be found */
private boolean isOnlyOpenLibertyFeatures ( List < String > featuresToInstall ) throws PluginExecutionException { } }

implementation: boolean result = containsIgnoreCase ( getOpenLibertyFeatureSet ( downloadedJsons ) , featuresToInstall ) ; debug ( "Is installing only Open Liberty features? " + result ) ; return result ;


signature:
public class InstallFeatureUtil { /** * Returns whether the reference collection contains all of the strings in the target collection , ignoring case .
 * @ param reference The reference collection
 * @ param target The target collection
 * @ return true if reference contains all Strings from target , ignoring case */
public static boolean containsIgnoreCase ( Collection < String > reference , Collection < String > target ) { } }

implementation: return toLowerCase ( reference ) . containsAll ( toLowerCase ( target ) ) ;