2 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
3 // Free Software Foundation, Inc
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or
8 // (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 #include "gnashconfig.h"
29 #include "Geometry.h" // for edge
35 // for double comparison
38 double _t
; // tolerance
40 D(double d
) : _d(d
), _t(1e-4) {}
43 D(double d
, double t
) : _d(d
), _t(t
) {}
45 // Return true if the difference between the two
46 // doubles is below the minimum tolerance defined for the two
47 bool operator==(const D
& d
)
49 double tol
= std::min(_t
, d
._t
);
50 double delta
= std::abs(_d
- d
._d
);
51 bool ret
= delta
< tol
;
52 //cout << "D " << _d << "operator==(const D " << d._d <<") returning " << ret << " (delta is " << delta << ") " << endl;
56 std::ostream
& operator<<(std::ostream
& os
, const D
& d
)
58 return os
<< d
._d
<< " [tol: " << d
._t
<< "]";
62 main(int /*argc*/, char** /*argv*/)
69 check_equals(Edge::distancePtSeg(point(0,0), point(9, 0), point(9, 0)), 9);
70 check_equals(Edge::distancePtSeg(point(0,0), point(0, 0), point(3, 0)), 0);
71 check_equals(Edge::distancePtSeg(point(-5,0), point(0, 0), point(3, 0)), 5);
72 check_equals(Edge::distancePtSeg(point(5,0), point(0, 0), point(3, 0)), 2);
73 check_equals(D(Edge::distancePtSeg(point(0,0), point(-10, 0), point(3, 0))), 0);
74 check_equals(Edge::distancePtSeg(point(0,0), point(-10, 0), point(-10, 30)), 10);
75 check_equals(Edge::distancePtSeg(point(5,5), point(-10, 0), point(10, 0)), 5);
89 check_equals(Edge::pointOnCurve(A
, C
, B
, 0), A
);
90 check_equals(Edge::pointOnCurve(A
, C
, B
, 1), B
);
91 check_equals(Edge::pointOnCurve(A
, C
, B
, 0.5), point(17.5, 12.5));
92 check_equals(std::sqrt((float)Edge::squareDistancePtCurve(A
, C
, B
, B
, 1)), 0);
93 check_equals(std::sqrt((float)Edge::squareDistancePtCurve(A
, C
, B
, A
, 0)), 0);
101 check_equals(Edge::pointOnCurve(A
, C
, B
, 0), A
);
102 check_equals(Edge::pointOnCurve(A
, C
, B
, 1), B
);
103 check_equals(Edge::pointOnCurve(A
, C
, B
, 0.5), point(27.5, 10));
104 check_equals(std::sqrt((float)Edge::squareDistancePtCurve(A
, C
, B
, B
, 1)), 0);
105 check_equals(std::sqrt((float)Edge::squareDistancePtCurve(A
, C
, B
, A
, 0)), 0);