1*ce9c7ef7SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*ce9c7ef7SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*ce9c7ef7SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*ce9c7ef7SAndrew Rist  * distributed with this work for additional information
6*ce9c7ef7SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*ce9c7ef7SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*ce9c7ef7SAndrew Rist  * "License"); you may not use this file except in compliance
9*ce9c7ef7SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*ce9c7ef7SAndrew Rist  *
11*ce9c7ef7SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*ce9c7ef7SAndrew Rist  *
13*ce9c7ef7SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*ce9c7ef7SAndrew Rist  * software distributed under the License is distributed on an
15*ce9c7ef7SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*ce9c7ef7SAndrew Rist  * KIND, either express or implied.  See the License for the
17*ce9c7ef7SAndrew Rist  * specific language governing permissions and limitations
18*ce9c7ef7SAndrew Rist  * under the License.
19*ce9c7ef7SAndrew Rist  *
20*ce9c7ef7SAndrew Rist  *************************************************************/
21*ce9c7ef7SAndrew Rist 
22*ce9c7ef7SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef BASEGFX_BEZIERCLIP_HXX
25cdf0e10cSrcweir #define BASEGFX_BEZIERCLIP_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <vector>
28cdf0e10cSrcweir 
29cdf0e10cSrcweir struct Point2D
30cdf0e10cSrcweir {
31cdf0e10cSrcweir     typedef double value_type;
Point2DPoint2D32cdf0e10cSrcweir     Point2D( double _x, double _y ) : x(_x), y(_y) {}
Point2DPoint2D33cdf0e10cSrcweir     Point2D() : x(), y() {}
34cdf0e10cSrcweir     double x;
35cdf0e10cSrcweir     double y;
36cdf0e10cSrcweir };
37cdf0e10cSrcweir 
38cdf0e10cSrcweir struct Bezier
39cdf0e10cSrcweir {
40cdf0e10cSrcweir     Point2D	p0;
41cdf0e10cSrcweir     Point2D	p1;
42cdf0e10cSrcweir     Point2D	p2;
43cdf0e10cSrcweir     Point2D	p3;
44cdf0e10cSrcweir 
operator []Bezier45cdf0e10cSrcweir     Point2D& 		operator[]( int i ) { return reinterpret_cast<Point2D*>(this)[i]; }
operator []Bezier46cdf0e10cSrcweir     const Point2D& 	operator[]( int i ) const { return reinterpret_cast<const Point2D*>(this)[i]; }
47cdf0e10cSrcweir };
48cdf0e10cSrcweir 
49cdf0e10cSrcweir struct FatLine
50cdf0e10cSrcweir {
51cdf0e10cSrcweir     // line L through p1 and p4 in normalized implicit form
52cdf0e10cSrcweir     double a;
53cdf0e10cSrcweir     double b;
54cdf0e10cSrcweir     double c;
55cdf0e10cSrcweir 
56cdf0e10cSrcweir     // the upper and lower distance from this line
57cdf0e10cSrcweir     double dMin;
58cdf0e10cSrcweir     double dMax;
59cdf0e10cSrcweir };
60cdf0e10cSrcweir 
calcLineDistance(const DataType & a,const DataType & b,const DataType & c,const DataType & x,const DataType & y)61cdf0e10cSrcweir template <typename DataType> DataType calcLineDistance( const DataType& a,
62cdf0e10cSrcweir                                                         const DataType& b,
63cdf0e10cSrcweir                                                         const DataType& c,
64cdf0e10cSrcweir                                                         const DataType& x,
65cdf0e10cSrcweir                                                         const DataType& y )
66cdf0e10cSrcweir {
67cdf0e10cSrcweir     return a*x + b*y + c;
68cdf0e10cSrcweir }
69cdf0e10cSrcweir 
70cdf0e10cSrcweir typedef ::std::vector< Point2D > Polygon2D;
71cdf0e10cSrcweir 
72cdf0e10cSrcweir /* little abs template */
absval(NumType x)73cdf0e10cSrcweir template <typename NumType> NumType absval( NumType x )
74cdf0e10cSrcweir {
75cdf0e10cSrcweir     return x<0 ? -x : x;
76cdf0e10cSrcweir }
77cdf0e10cSrcweir 
78cdf0e10cSrcweir Polygon2D convexHull( const Polygon2D& rPoly );
79cdf0e10cSrcweir 
80cdf0e10cSrcweir // TODO: find proper epsilon here (try ::std::numeric_limits<NumType>::epsilon()?)!
81cdf0e10cSrcweir #define DBL_EPSILON 1.0e-100
82cdf0e10cSrcweir 
83cdf0e10cSrcweir /* little approximate comparions */
tolZero(NumType n)84cdf0e10cSrcweir template <typename NumType> bool tolZero( NumType n ) { return fabs(n) < DBL_EPSILON; }
tolEqual(NumType n1,NumType n2)85cdf0e10cSrcweir template <typename NumType> bool tolEqual( NumType n1, NumType n2 ) { return tolZero(n1-n2); }
tolLessEqual(NumType n1,NumType n2)86cdf0e10cSrcweir template <typename NumType> bool tolLessEqual( NumType n1, NumType n2 ) { return tolEqual(n1,n2) || n1<n2; }
tolGreaterEqual(NumType n1,NumType n2)87cdf0e10cSrcweir template <typename NumType> bool tolGreaterEqual( NumType n1, NumType n2 ) { return tolEqual(n1,n2) || n1>n2; }
88cdf0e10cSrcweir 
89cdf0e10cSrcweir #endif /* BASEGFX_BEZIERCLIP_HXX */
90