1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef BASEGFX_BEZIERCLIP_HXX
29 #define BASEGFX_BEZIERCLIP_HXX
30 
31 #include <vector>
32 
33 struct Point2D
34 {
35     typedef double value_type;
36     Point2D( double _x, double _y ) : x(_x), y(_y) {}
37     Point2D() : x(), y() {}
38     double x;
39     double y;
40 };
41 
42 struct Bezier
43 {
44     Point2D	p0;
45     Point2D	p1;
46     Point2D	p2;
47     Point2D	p3;
48 
49     Point2D& 		operator[]( int i ) { return reinterpret_cast<Point2D*>(this)[i]; }
50     const Point2D& 	operator[]( int i ) const { return reinterpret_cast<const Point2D*>(this)[i]; }
51 };
52 
53 struct FatLine
54 {
55     // line L through p1 and p4 in normalized implicit form
56     double a;
57     double b;
58     double c;
59 
60     // the upper and lower distance from this line
61     double dMin;
62     double dMax;
63 };
64 
65 template <typename DataType> DataType calcLineDistance( const DataType& a,
66                                                         const DataType& b,
67                                                         const DataType& c,
68                                                         const DataType& x,
69                                                         const DataType& y )
70 {
71     return a*x + b*y + c;
72 }
73 
74 typedef ::std::vector< Point2D > Polygon2D;
75 
76 /* little abs template */
77 template <typename NumType> NumType absval( NumType x )
78 {
79     return x<0 ? -x : x;
80 }
81 
82 Polygon2D convexHull( const Polygon2D& rPoly );
83 
84 // TODO: find proper epsilon here (try ::std::numeric_limits<NumType>::epsilon()?)!
85 #define DBL_EPSILON 1.0e-100
86 
87 /* little approximate comparions */
88 template <typename NumType> bool tolZero( NumType n ) { return fabs(n) < DBL_EPSILON; }
89 template <typename NumType> bool tolEqual( NumType n1, NumType n2 ) { return tolZero(n1-n2); }
90 template <typename NumType> bool tolLessEqual( NumType n1, NumType n2 ) { return tolEqual(n1,n2) || n1<n2; }
91 template <typename NumType> bool tolGreaterEqual( NumType n1, NumType n2 ) { return tolEqual(n1,n2) || n1>n2; }
92 
93 #endif /* BASEGFX_BEZIERCLIP_HXX */
94