QGIS API Documentation
4.3.0-Master (16eddb2670e)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
core
symbology
line_p.h
Go to the documentation of this file.
1
/***************************************************************************
2
line_p.h
3
---------------------
4
begin : 2025/09/25
5
copyright : (C) 2025 by Julien Cabieces
6
email : julien dot cabieces at oslandia dot com
7
***************************************************************************
8
* *
9
* This program is free software; you can redistribute it and/or modify *
10
* it under the terms of the GNU General Public License as published by *
11
* the Free Software Foundation; either version 2 of the License, or *
12
* (at your option) any later version. *
13
* *
14
***************************************************************************/
15
16
#ifndef LINE_P_H
17
#define LINE_P_H
18
19
20
#include "
qgsgeometryutils_base.h
"
21
22
#define SIP_NO_FILE
23
25
27
28
33
class
Line
34
{
35
public
:
36
Line( QPointF p1, QPointF p2 )
37
: mVertical(
false
)
38
, mIncreasing(
false
)
39
, mTangent( 0.0 )
40
, mLength( 0.0 )
41
{
42
if
( p1 == p2 )
43
return
;
// invalid
44
45
// tangent and direction
46
if
(
qgsDoubleNear
( p1.x(), p2.x() ) )
47
{
48
// vertical line - tangent undefined
49
mVertical =
true
;
50
mIncreasing = ( p2.y() > p1.y() );
51
}
52
else
53
{
54
mVertical =
false
;
55
mTangent = ( p2.y() - p1.y() ) / ( p2.x() - p1.x() );
56
mIncreasing = ( p2.x() > p1.x() );
57
}
58
59
mLength =
QgsGeometryUtilsBase::distance2D
( p1, p2 );
60
}
61
62
// return angle in radians
63
double
angle()
64
{
65
double
a = ( mVertical ? M_PI_2 : std::atan( mTangent ) );
66
67
if
( !mIncreasing )
68
a += M_PI;
69
return
a;
70
}
71
72
// return difference for x,y when going along the line with specified interval
73
QPointF diffForInterval(
double
interval )
const
74
{
75
if
( mVertical )
76
return
( mIncreasing ? QPointF( 0, interval ) : QPointF( 0, -interval ) );
77
78
double
alpha = std::atan( mTangent );
79
double
dx = std::cos( alpha ) * interval;
80
double
dy = std::sin( alpha ) * interval;
81
return
( mIncreasing ? QPointF( dx, dy ) : QPointF( -dx, -dy ) );
82
}
83
84
double
length()
const
{
return
mLength; }
85
86
protected
:
87
bool
mVertical;
88
bool
mIncreasing;
89
double
mTangent;
90
double
mLength;
91
};
92
94
95
#endif
QgsGeometryUtilsBase::distance2D
static double distance2D(double x1, double y1, double x2, double y2)
Returns the 2D distance between (x1, y1) and (x2, y2).
Definition
qgsgeometryutils_base.h:64
qgsDoubleNear
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference).
Definition
qgis.h:7743
qgsgeometryutils_base.h
Generated on
for QGIS API Documentation by
1.17.0