Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / basegfx / source / workbench / bezierclip.hxx
blob11ab32109414952b1a38f756aee0dfad03f4cd77
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_BASEGFX_SOURCE_WORKBENCH_BEZIERCLIP_HXX
21 #define INCLUDED_BASEGFX_SOURCE_WORKBENCH_BEZIERCLIP_HXX
23 #include <vector>
25 struct Point2D
27 typedef double value_type;
28 Point2D( double _x, double _y ) : x(_x), y(_y) {}
29 Point2D() : x(), y() {}
30 double x;
31 double y;
34 struct Bezier
36 Point2D p0;
37 Point2D p1;
38 Point2D p2;
39 Point2D p3;
41 Point2D& operator[]( int i ) { return reinterpret_cast<Point2D*>(this)[i]; }
42 const Point2D& operator[]( int i ) const { return reinterpret_cast<const Point2D*>(this)[i]; }
45 struct FatLine
47 // line L through p1 and p4 in normalized implicit form
48 double a;
49 double b;
50 double c;
52 // the upper and lower distance from this line
53 double dMin;
54 double dMax;
57 template <typename DataType> DataType calcLineDistance( const DataType& a,
58 const DataType& b,
59 const DataType& c,
60 const DataType& x,
61 const DataType& y )
63 return a*x + b*y + c;
66 typedef ::std::vector< Point2D > Polygon2D;
68 /* little abs template */
69 template <typename NumType> NumType absval( NumType x )
71 return x<0 ? -x : x;
74 Polygon2D convexHull( const Polygon2D& rPoly );
76 // TODO: find proper epsilon here (try ::std::numeric_limits<NumType>::epsilon()?)!
77 #define DBL_EPSILON 1.0e-100
79 /* little approximate comparisons */
80 template <typename NumType> bool tolZero( NumType n ) { return fabs(n) < DBL_EPSILON; }
81 template <typename NumType> bool tolEqual( NumType n1, NumType n2 ) { return tolZero(n1-n2); }
82 template <typename NumType> bool tolLessEqual( NumType n1, NumType n2 ) { return tolEqual(n1,n2) || n1<n2; }
83 template <typename NumType> bool tolGreaterEqual( NumType n1, NumType n2 ) { return tolEqual(n1,n2) || n1>n2; }
85 #endif // INCLUDED_BASEGFX_SOURCE_WORKBENCH_BEZIERCLIP_HXX
87 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */