LibreOffice Module basegfx (master) 1
bezierclip.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#pragma once
21
22#include <vector>
23
24struct Point2D
25{
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;
31};
32
33struct Bezier
34{
39
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]; }
42};
43
44struct FatLine
45{
46 // line L through p1 and p4 in normalized implicit form
47 double a;
48 double b;
49 double c;
50
51 // the upper and lower distance from this line
52 double dMin;
53 double dMax;
54};
55
56template <typename DataType> DataType calcLineDistance( const DataType& a,
57 const DataType& b,
58 const DataType& c,
59 const DataType& x,
60 const DataType& y )
61{
62 return a*x + b*y + c;
63}
64
65typedef std::vector< Point2D > Polygon2D;
66
67/* little abs template */
68template <typename NumType> NumType absval( NumType x )
69{
70 return x<0 ? -x : x;
71}
72
73Polygon2D convexHull( const Polygon2D& rPoly );
74
75// TODO: find proper epsilon here (try std::numeric_limits<NumType>::epsilon()?)!
76constexpr auto DBL_EPSILON = 1.0e-100;
77
78/* little approximate comparisons */
79template <typename NumType> bool tolZero( NumType n ) { return fabs(n) < DBL_EPSILON; }
80template <typename NumType> bool tolEqual( NumType n1, NumType n2 ) { return tolZero(n1-n2); }
81template <typename NumType> bool tolLessEqual( NumType n1, NumType n2 ) { return tolEqual(n1,n2) || n1<n2; }
82template <typename NumType> bool tolGreaterEqual( NumType n1, NumType n2 ) { return tolEqual(n1,n2) || n1>n2; }
83
84/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
DataType calcLineDistance(const DataType &a, const DataType &b, const DataType &c, const DataType &x, const DataType &y)
Definition: bezierclip.hxx:56
bool tolEqual(NumType n1, NumType n2)
Definition: bezierclip.hxx:80
Polygon2D convexHull(const Polygon2D &rPoly)
Definition: convexhull.cxx:150
bool tolGreaterEqual(NumType n1, NumType n2)
Definition: bezierclip.hxx:82
bool tolLessEqual(NumType n1, NumType n2)
Definition: bezierclip.hxx:81
std::vector< Point2D > Polygon2D
Definition: bezierclip.hxx:65
NumType absval(NumType x)
Definition: bezierclip.hxx:68
constexpr auto DBL_EPSILON
Definition: bezierclip.hxx:76
bool tolZero(NumType n)
Definition: bezierclip.hxx:79
float y
float x
sal_Int64 n
uno_Any a
int n2
int n1
int i
DataType
Point2D p3
Definition: bezierclip.hxx:38
Point2D p1
Definition: bezierclip.hxx:36
const Point2D & operator[](int i) const
Definition: bezierclip.hxx:41
Point2D p0
Definition: bezierclip.hxx:35
Point2D p2
Definition: bezierclip.hxx:37
Point2D & operator[](int i)
Definition: bezierclip.hxx:40
double b
Definition: bezierclip.hxx:48
double a
Definition: bezierclip.hxx:47
double c
Definition: bezierclip.hxx:49
double dMax
Definition: bezierclip.hxx:53
double dMin
Definition: bezierclip.hxx:52
Point2D(double _x, double _y)
Definition: bezierclip.hxx:27
double x
Definition: bezierclip.hxx:29
double y
Definition: bezierclip.hxx:30
double value_type
Definition: bezierclip.hxx:26