[go: up one dir, main page]

Menu

[r999]: / mia2 / mia / core / sqmin.cc  Maximize  Restore  History

Download this file

60 lines (47 with data), 1.6 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/* -*- mona-c++ -*-
*
* Copyright (c) Leipzig, Madrid 2004 - 2009
* Max-Planck-Institute for Human Cognitive and Brain Science
* Max-Planck-Institute for Evolutionary Anthropology
* BIT, ETSI Telecomunicacion, UPM
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PUcRPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include <cassert>
#include <cmath>
#include <mia/core/sqmin.hh>
#include <mia/core/msgstream.hh>
NS_MIA_BEGIN
// float x0 = 0.0, float x1 = 1.0,
EXPORT_CORE double min_ax2_px_c(double x, double y0, double y1, double y2)
{
assert (x != 0.0 && x != 1.0);
const double d10 = y1 - y0;
const double d20 = y2 - y0;
const double x2 = x * x;
const double b = (d10 * x2 - d20) / (x2 - x);
const double a = 2.0 * (b - d10);
if ( ( ((x > 1.0 ) ? x : 1.0) * fabs(a) ) < fabs(b) ) {
if ( b > 0 )
return 0.0;
else
return (x > 1.0 ) ? x : 1.0;
}
if (a * b < 0.0)
return 0.0;
return b / a;
}
NS_MIA_END