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