tdf#130857 qt weld: Implement QtInstanceWidget::get_text_height
[LibreOffice.git] / basegfx / source / workbench / bezierclip.hxx
blob54cceb414f333e030aefe41f8c30a75b4bb12801
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 #pragma once
22 #include <vector>
24 struct Point2D
26 typedef double value_type;
27 Point2D( double _x, double _y ) : x(_x), y(_y) {}
28 Point2D() : x(), y() {}
29 double x;
30 double y;
33 struct Bezier
35 Point2D p0;
36 Point2D p1;
37 Point2D p2;
38 Point2D p3;
40 Point2D& operator[]( int i ) { return reinterpret_cast<Point2D*>(this)[i]; }
41 const Point2D& operator[]( int i ) const { return reinterpret_cast<const Point2D*>(this)[i]; }
44 struct FatLine
46 // line L through p1 and p4 in normalized implicit form
47 double a;
48 double b;
49 double c;
51 // the upper and lower distance from this line
52 double dMin;
53 double dMax;
56 template <typename DataType> DataType calcLineDistance( const DataType& a,
57 const DataType& b,
58 const DataType& c,
59 const DataType& x,
60 const DataType& y )
62 return a*x + b*y + c;
65 typedef std::vector< Point2D > Polygon2D;
67 /* little abs template */
68 template <typename NumType> NumType absval( NumType x )
70 return x<0 ? -x : x;
73 Polygon2D convexHull( const Polygon2D& rPoly );
75 // TODO: find proper epsilon here (try std::numeric_limits<NumType>::epsilon()?)!
76 constexpr auto DBL_EPSILON = 1.0e-100;
78 /* little approximate comparisons */
79 template <typename NumType> bool tolZero( NumType n ) { return fabs(n) < DBL_EPSILON; }
80 template <typename NumType> bool tolEqual( NumType n1, NumType n2 ) { return tolZero(n1-n2); }
81 template <typename NumType> bool tolLessEqual( NumType n1, NumType n2 ) { return tolEqual(n1,n2) || n1<n2; }
82 template <typename NumType> bool tolGreaterEqual( NumType n1, NumType n2 ) { return tolEqual(n1,n2) || n1>n2; }
84 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */