/** @file
* @brief Basic intersection routines
*//*
* Authors:
* Nathan Hurst <njh@njhurst.com>
* Marco Cecchetti <mrcekets at gmail.com>
* Jean-François Barraud <jf.barraud@gmail.com>
*
* Copyright 2008-2009 Authors
*
* modify it either under the terms of the GNU Lesser General Public
* License version 2.1 as published by the Free Software Foundation
* (the "LGPL") or, at your option, under the terms of the Mozilla
* Public License Version 1.1 (the "MPL"). If you do not alter this
* notice, a recipient may use your version of this file under either
* the MPL or the LGPL.
*
* You should have received a copy of the LGPL along with this library
* in the file COPYING-LGPL-2.1; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* You should have received a copy of the MPL along with this library
* in the file COPYING-MPL-1.1
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
* OF ANY KIND, either express or implied. See the LGPL or the MPL for
* the specific language governing rights and limitations.
*
*/
#ifdef HAVE_GSL
#include <gsl/gsl_vector.h>
#include <gsl/gsl_multiroots.h>
#endif
namespace Geom {
//#ifdef USE_RECURSIVE_INTERSECTOR
// void find_intersections(std::vector<std::pair<double, double> > &xs,
// D2<SBasis> const & A,
// D2<SBasis> const & B) {
// vector<Point> BezA, BezB;
// sbasis_to_bezier(BezA, A);
// sbasis_to_bezier(BezB, B);
// xs.clear();
// find_intersections_bezier_recursive(xs, BezA, BezB);
// }
// void find_intersections(std::vector< std::pair<double, double> > & xs,
// std::vector<Point> const& A,
// std::vector<Point> const& B,
// double precision){
// find_intersections_bezier_recursive(xs, A, B, precision);
// }
//#else
}; };
double precision)
{
}
double precision)
{
sbasis_to_bezier(BezA, A);
sbasis_to_bezier(BezB, B);
}
double precision)
{
}
//#endif
/*
* split the curve at the midpoint, returning an array with the two parts
* Temporary storage is minimized by using part of the storage for the result
* to hold an intermediate value until it is no longer needed.
*/
// TODO replace with Bezier method
//Geom::Point Vtemp[sz][sz];
/* Copy control points */
/* Triangle computation */
for (unsigned i = 1; i < sz; i++) {
for (unsigned j = 0; j < sz - i; j++) {
}
}
for (unsigned j = 0; j < sz; j++)
for (unsigned j = 0; j < sz; j++)
}
double precision)
{
{
}
// We want to be sure that we have no empty segments
}
/*{
vector<Point> l, r, in = A;
for(unsigned i = 0; i < dr.size()-1; i++) {
split(in, (dr[i+1]-dr[i]) / (1 - dr[i]), l, r);
pieces.push_back(l);
in = r;
}
}*/
// XXX: This condition will prune out false positives, but it might create some false negatives. Todo: Confirm it is correct.
if(j == i+1)
//if((l == 1) && (r == 0))
continue;
}
}
}
// Because i is in order, xs should be roughly already in order?
//sort(xs.begin(), xs.end());
//unique(xs.begin(), xs.end());
}
double precision)
{
sbasis_to_bezier(in, A);
}
{
return;
}
}
}
#ifdef HAVE_GSL
#include <gsl/gsl_multiroots.h>
struct rparams
{
};
static int
gsl_vector * f)
{
gsl_vector_set (f, 0, dx[0]);
return GSL_SUCCESS;
}
#endif
union dbl_64{
long long i64;
double d64;
};
{
dbl_64 s;
return s.d64;
}
#ifdef HAVE_GSL
const gsl_multiroot_fsolver_type *T;
int status;
#endif
for(int i = 0; i < 4; i++) {
/**
we want to solve
J*(x1 - x0) = f(x0)
|dA(s)[0] -dB(t)[0]| (X1 - X0) = A(s) - B(t)
|dA(s)[1] -dB(t)[1]|
**/
// We're using the standard transformation matricies, which is numerically rather poor. Much better to solve the equation using elimination.
0, 0);
// At this point we could do a line search
break;
}
s = ns;
t = nt;
}
#ifdef HAVE_GSL
const size_t n = 2;
struct rparams p = {A, B};
gsl_multiroot_function f = {&intersect_polish_f, n, &p};
gsl_vector *x = gsl_vector_alloc (n);
gsl_vector_set (x, 0, x_init[0]);
gsl_multiroot_fsolver_set (sol, &f, x);
do
{
iter++;
if (status) /* check if solver is stuck */
break;
status =
}
s = gsl_vector_get (sol->x, 0);
gsl_vector_free (x);
#endif
{
// This code does a neighbourhood search for minor improvements.
//std::cout << "------\n" << best_v << std::endl;
while (true) {
double c = L1(A(n[0]) - B(n[1]));
//std::cout << c << "; ";
if (c < trial_v) {
trial = n;
trial_v = c;
}
}
}
//std::cout << "\n" << s << " -> " << s - best[0] << std::endl;
//std::cout << t << " -> " << t - best[1] << std::endl;
//std::cout << best_v << std::endl;
s = best[0];
t = best[1];
return;
} else {
}
}
}
}
{
}
/**
* Compute the Hausdorf distance from A to B only.
*/
double m_precision,
sbasis_to_bezier (Az, A);
sbasis_to_bezier (Bz, B);
double dist = 0;
h_a_t = 0;
h_b_t = t;
}
h_a_t = 1;
h_b_t = t;
}
{
//FIXME: we might miss it due to floating point precision...
}
}
return h_dist;
}
/**
* Compute the symmetric Hausdorf distance.
*/
double m_precision,
double dist = 0;
}
}
return h_dist;
}
};
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :