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