// Path: jopenvoronoi-main/src/main/java/org/rogach/jopenvoronoi/Numeric.java
// public static double determinant(double a, double b, double c,
//                                  double d, double e, double f,
//                                  double g, double h, double i ) {
//     return a*(e*i-h*f)-b*(d*i-g*f)+c*(d*h-g*e);
// }
// 
// Path: jopenvoronoi-main/src/main/java/org/rogach/jopenvoronoi/Numeric.java
// public static double chop(double val, double tol) {
//     double _epsilon = tol;
//     if (Math.abs(val) < _epsilon)
//         return 0;
//     else
//         return val;
// }


import java.util.List;
import java.util.ArrayList;
import static org.rogach.jopenvoronoi.Numeric.determinant;
import static org.rogach.jopenvoronoi.Numeric.chop;
package org.rogach.jopenvoronoi;


/// \brief line-line-line Solver
///
/// solves 3x3 system.
public class LLLSolver extends Solver {

//  a1 x + b1 y + c1 + k1 t = 0
//  a2 x + b2 y + c2 + k2 t = 0
//  a3 x + b3 y + c3 + k3 t = 0
//
// or in matrix form
//
//  ( a1 b1 k1 ) ( x )    ( c1 )
//  ( a2 b2 k2 ) ( y ) = -( c2 )          Ax = b
//  ( a3 b3 k3 ) ( t )    ( c3 )
//
//  Cramers rule x_i = det(A_i)/det(A)
//  where A_i is A with column i replaced by b

    public int solve( Site s1, double k1,
                      Site s2, double k2,
                      Site s3, double k3, List<Solution> slns ) {

        assert( s1.isLine() && s2.isLine() && s3.isLine() ) : " s1.isLine() && s2.isLine() && s3.isLine() ";

        List<Eq> eq = new ArrayList<>(); // equation-parameters, in quad-precision
        Site[] sites = new Site[] { s1, s2, s3 };
        double[] kvals = new double[] { k1, k2, k3 };
        for (int i=0;i<3;i++)
            eq.add( sites[i].eqp( kvals[i] ) );

        int i = 0, j=1, k=2;
// Path: jopenvoronoi-main/src/main/java/org/rogach/jopenvoronoi/Numeric.java
// public static double determinant(double a, double b, double c,
//                                  double d, double e, double f,
//                                  double g, double h, double i ) {
//     return a*(e*i-h*f)-b*(d*i-g*f)+c*(d*h-g*e);
// }
// 
// Path: jopenvoronoi-main/src/main/java/org/rogach/jopenvoronoi/Numeric.java
// public static double chop(double val, double tol) {
//     double _epsilon = tol;
//     if (Math.abs(val) < _epsilon)
//         return 0;
//     else
//         return val;
// }


// Path: jopenvoronoi-main/src/main/java/org/rogach/jopenvoronoi/LLLSolver.java
import java.util.List;
import java.util.ArrayList;
import static org.rogach.jopenvoronoi.Numeric.determinant;
import static org.rogach.jopenvoronoi.Numeric.chop;

package org.rogach.jopenvoronoi;


/// \brief line-line-line Solver
///
/// solves 3x3 system.
public class LLLSolver extends Solver {

//  a1 x + b1 y + c1 + k1 t = 0
//  a2 x + b2 y + c2 + k2 t = 0
//  a3 x + b3 y + c3 + k3 t = 0
//
// or in matrix form
//
//  ( a1 b1 k1 ) ( x )    ( c1 )
//  ( a2 b2 k2 ) ( y ) = -( c2 )          Ax = b
//  ( a3 b3 k3 ) ( t )    ( c3 )
//
//  Cramers rule x_i = det(A_i)/det(A)
//  where A_i is A with column i replaced by b

    public int solve( Site s1, double k1,
                      Site s2, double k2,
                      Site s3, double k3, List<Solution> slns ) {

        assert( s1.isLine() && s2.isLine() && s3.isLine() ) : " s1.isLine() && s2.isLine() && s3.isLine() ";

        List<Eq> eq = new ArrayList<>(); // equation-parameters, in quad-precision
        Site[] sites = new Site[] { s1, s2, s3 };
        double[] kvals = new double[] { k1, k2, k3 };
        for (int i=0;i<3;i++)
            eq.add( sites[i].eqp( kvals[i] ) );

        int i = 0, j=1, k=2;
        double d = chop( determinant( eq.get(i).a, eq.get(i).b, eq.get(i).k,