QGIS API Documentation
3.14.0-Pi (9f7028fd23)
|
Go to the documentation of this file.
25 static const double SOFT_CONSTRAINT_TOLERANCE_PIXEL = 15;
26 static const double SOFT_CONSTRAINT_TOLERANCE_DEGREES = 10;
80 const double dx = edgePt1.
x() - edgePt0.
x();
83 point.
setY( edgePt0.
y() );
87 const double dy = edgePt1.
y() - edgePt0.
y();
88 point.
setY( edgePt0.
y() + ( dy * ( point.
x() - edgePt0.
x() ) ) / dx );
108 const double dy = edgePt1.
y() - edgePt0.
y();
111 point.
setX( edgePt0.
x() );
115 const double dx = edgePt1.
x() - edgePt0.
x();
116 point.
setX( edgePt0.
x() + ( dx * ( point.
y() - edgePt0.
y() ) ) / dy );
128 double softAngle = std::atan2( point.
y() - previousPt.
y(),
129 point.
x() - previousPt.
x() );
130 double deltaAngle = 0;
134 deltaAngle = std::atan2( previousPt.
y() - penultimatePt.
y(),
135 previousPt.
x() - penultimatePt.
x() );
136 softAngle -= deltaAngle;
138 int quo = std::round( softAngle / commonAngle );
139 if ( std::fabs( softAngle - quo * commonAngle ) * 180.0 * M_1_PI <= SOFT_CONSTRAINT_TOLERANCE_DEGREES )
142 softAngle = quo * commonAngle;
145 const double dist = std::fabs( std::cos( softAngle + deltaAngle ) * ( previousPt.
y() - point.
y() )
146 - std::sin( softAngle + deltaAngle ) * ( previousPt.
x() - point.
x() ) );
157 bool angleLocked =
false, angleRelative =
false;
158 double angleValueDeg = 0;
177 double angleValue = angleValueDeg * M_PI / 180;
181 angleValue += std::atan2( previousPt.
y() - penultimatePt.
y(),
182 previousPt.
x() - penultimatePt.
x() );
185 double cosa = std::cos( angleValue );
186 double sina = std::sin( angleValue );
187 double v = ( point.
x() - previousPt.
x() ) * cosa + ( point.
y() - previousPt.
y() ) * sina;
205 point.
setY( previousPt.
y() + x * sina / cosa );
221 point.
setX( previousPt.
x() + y * cosa / sina );
226 point.
setX( previousPt.
x() + cosa * v );
227 point.
setY( previousPt.
y() + sina * v );
235 const double x1 = previousPt.
x();
236 const double y1 = previousPt.
y();
237 const double x2 = previousPt.
x() + cosa;
238 const double y2 = previousPt.
y() + sina;
240 const double x3 = edgePt0.
x();
241 const double y3 = edgePt0.
y();
242 const double x4 = edgePt1.
x();
243 const double y4 = edgePt1.
y();
245 const double d = ( x1 - x2 ) * ( y3 - y4 ) - ( y1 - y2 ) * ( x3 - x4 );
249 if ( std::fabs( d ) > 0.01 )
251 point.
setX( ( ( x3 - x4 ) * ( x1 * y2 - y1 * x2 ) - ( x1 - x2 ) * ( x3 * y4 - y3 * x4 ) ) / d );
252 point.
setY( ( ( y3 - y4 ) * ( x1 * y2 - y1 * x2 ) - ( y1 - y2 ) * ( x3 * y4 - y3 * x4 ) ) / d );
279 const double dist = std::sqrt( point.
sqrDist( previousPt ) );
289 point.
set( previousPt.
x() + ( point.
x() - previousPt.
x() ) * vP,
290 previousPt.
y() + ( point.
y() - previousPt.
y() ) * vP );
303 QgsDebugMsgLevel( QStringLiteral(
"point: %1 %2" ).arg( point.
x() ).arg( point.
y() ), 4 );
304 QgsDebugMsgLevel( QStringLiteral(
"previous point: %1 %2" ).arg( previousPt.
x() ).arg( previousPt.
y() ), 4 );
305 QgsDebugMsgLevel( QStringLiteral(
"penultimate point: %1 %2" ).arg( penultimatePt.
x() ).arg( penultimatePt.
y() ), 4 );
316 QgsDebugMsg( QStringLiteral(
"Constraints (locked / relative / value" ) );
static QgsCadUtils::AlignMapPointOutput alignMapPoint(const QgsPointXY &originalMapPoint, const QgsCadUtils::AlignMapPointContext &ctx)
Applies X/Y/angle/distance constraints from the given context to a map point.
QgsCadUtils::AlignMapPointConstraint xConstraint
Constraint for X coordinate.
#define QgsDebugMsgLevel(str, level)
virtual bool acceptMatch(const QgsPointLocator::Match &match)=0
double sqrDist(double x, double y) const
Returns the squared distance between this point a specified x, y coordinate.
void edgePoints(QgsPointXY &pt1, QgsPointXY &pt2) const
Only for a valid edge match - obtain endpoints of the edge.
QgsPointXY point() const
for vertex / edge match coords depending on what class returns it (geom.cache: layer coords,...
Structure defining all constraints for alignMapPoint() method.
QgsCadUtils::AlignMapPointConstraint distanceConstraint
Constraint for distance.
QgsPointLocator::Match snapToMap(QPoint point, QgsPointLocator::MatchFilter *filter=nullptr, bool relaxed=false)
Snap to map according to the current configuration.
bool hasEdge() const
Returns true if the Match is an edge.
bool locked
Whether the constraint is active, i.e. should be considered.
QgsPointLocator::Match edgeMatch
Snapped segment - only valid if actually used for something.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
QgsPointXY finalMapPoint
map point aligned according to the constraints
QgsCadUtils::AlignMapPointConstraint commonAngleConstraint
Constraint for soft lock to a common angle.
void setY(double y)
Sets the y value of the point.
QList< QgsPointXY > cadPointList
List of recent CAD points in map coordinates.
double mapUnitsPerPixel
Map units/pixel ratio from map canvas. Needed for.
void dump() const
Dumps the context's properties, for debugging.
double value
Numeric value of the constraint (coordinate/distance in map units or angle in degrees)
double softLockCommonAngle
Angle (in degrees) to which we have soft-locked ourselves (if not set it is -1)
Structure returned from alignMapPoint() method.
bool valid
Whether the combination of constraints is actually valid.
QgsCadUtils::AlignMapPointConstraint angleConstraint
Constraint for angle.
QgsSnappingUtils * snappingUtils
Snapping utils that will be used to snap point to map. Must not be nullptr.
static bool lineCircleIntersection(const QgsPointXY ¢er, double radius, const QgsPointXY &linePoint1, const QgsPointXY &linePoint2, QgsPointXY &intersection)
Compute the intersection of a line and a circle.
Interface that allows rejection of some matches in intersection queries (e.g.
void setX(double x)
Sets the x value of the point.
bool relative
Whether the value is relative to previous value.
QgsCadUtils::AlignMapPointConstraint yConstraint
Constraint for Y coordinate.
void set(double x, double y)
Sets the x and y value of the point.
QgsPointLocator::Match snapMatch
Snapped point - only valid if actually used for something.