25 static const double SOFT_CONSTRAINT_TOLERANCE_PIXEL = 15;
26 static const double SOFT_CONSTRAINT_TOLERANCE_DEGREES = 10;
49 EdgesOnlyFilter edgesOnlyFilter;
77 const double dx = edgePt1.
x() - edgePt0.
x();
80 point.
setY( edgePt0.
y() );
84 const double dy = edgePt1.
y() - edgePt0.
y();
85 point.
setY( edgePt0.
y() + ( dy * ( point.
x() - edgePt0.
x() ) ) / dx );
105 const double dy = edgePt1.
y() - edgePt0.
y();
108 point.
setX( edgePt0.
x() );
112 const double dx = edgePt1.
x() - edgePt0.
x();
113 point.
setX( edgePt0.
x() + ( dx * ( point.
y() - edgePt0.
y() ) ) / dy );
125 double softAngle = std::atan2( point.
y() - previousPt.
y(),
126 point.
x() - previousPt.
x() );
127 double deltaAngle = 0;
131 deltaAngle = std::atan2( previousPt.
y() - penultimatePt.
y(),
132 previousPt.
x() - penultimatePt.
x() );
133 softAngle -= deltaAngle;
135 int quo = std::round( softAngle / commonAngle );
136 if ( std::fabs( softAngle - quo * commonAngle ) * 180.0 * M_1_PI <= SOFT_CONSTRAINT_TOLERANCE_DEGREES )
139 softAngle = quo * commonAngle;
142 const double dist = std::fabs( std::cos( softAngle + deltaAngle ) * ( previousPt.
y() - point.
y() )
143 - std::sin( softAngle + deltaAngle ) * ( previousPt.
x() - point.
x() ) );
154 bool angleLocked =
false, angleRelative =
false;
155 double angleValueDeg = 0;
174 double angleValue = angleValueDeg * M_PI / 180;
178 angleValue += std::atan2( previousPt.
y() - penultimatePt.
y(),
179 previousPt.
x() - penultimatePt.
x() );
182 double cosa = std::cos( angleValue );
183 double sina = std::sin( angleValue );
184 double v = ( point.
x() - previousPt.
x() ) * cosa + ( point.
y() - previousPt.
y() ) * sina;
202 point.
setY( previousPt.
y() + x * sina / cosa );
218 point.
setX( previousPt.
x() + y * cosa / sina );
223 point.
setX( previousPt.
x() + cosa * v );
224 point.
setY( previousPt.
y() + sina * v );
232 const double x1 = previousPt.
x();
233 const double y1 = previousPt.
y();
234 const double x2 = previousPt.
x() + cosa;
235 const double y2 = previousPt.
y() + sina;
237 const double x3 = edgePt0.
x();
238 const double y3 = edgePt0.
y();
239 const double x4 = edgePt1.
x();
240 const double y4 = edgePt1.
y();
242 const double d = ( x1 - x2 ) * ( y3 - y4 ) - ( y1 - y2 ) * ( x3 - x4 );
246 if ( std::fabs( d ) > 0.01 )
248 point.
setX( ( ( x3 - x4 ) * ( x1 * y2 - y1 * x2 ) - ( x1 - x2 ) * ( x3 * y4 - y3 * x4 ) ) / d );
249 point.
setY( ( ( y3 - y4 ) * ( x1 * y2 - y1 * x2 ) - ( y1 - y2 ) * ( x3 * y4 - y3 * x4 ) ) / d );
276 const double dist = std::sqrt( point.
sqrDist( previousPt ) );
286 point.
set( previousPt.
x() + ( point.
x() - previousPt.
x() ) * vP,
287 previousPt.
y() + ( point.
y() - previousPt.
y() ) * vP );
301 QgsDebugMsgLevel( QString(
"previous point: %1 %2" ).arg( previousPt.
x() ).arg( previousPt.
y() ), 4 );
302 QgsDebugMsgLevel( QString(
"penultimate point: %1 %2" ).arg( penultimatePt.
x() ).arg( penultimatePt.
y() ), 4 );
313 QgsDebugMsg(
"Constraints (locked / relative / value" );
314 QgsDebugMsg( QString(
"Angle: %1 %2 %3" ).arg( angleConstraint.locked ).arg( angleConstraint.relative ).arg( angleConstraint.value ) );
315 QgsDebugMsg( QString(
"Distance: %1 %2 %3" ).arg( distanceConstraint.locked ).arg( distanceConstraint.relative ).arg( distanceConstraint.value ) );
316 QgsDebugMsg( QString(
"X: %1 %2 %3" ).arg( xConstraint.locked ).arg( xConstraint.relative ).arg( xConstraint.value ) );
317 QgsDebugMsg( QString(
"Y: %1 %2 %3" ).arg( yConstraint.locked ).arg( yConstraint.relative ).arg( yConstraint.value ) );
void set(double x, double y)
Sets the x and y value of the point.
QgsCadUtils::AlignMapPointConstraint yConstraint
Constraint for Y coordinate.
A class to represent a 2D point.
int softLockCommonAngle
Angle (in degrees) to which we have soft-locked ourselves (if not set it is -1)
Interface that allows rejection of some matches in intersection queries (e.g.
bool qgsDoubleNear(double a, double b, double epsilon=4 *DBL_EPSILON)
Compare two doubles (but allow some difference)
QgsPointLocator::Match edgeMatch
Snapped segment - only valid if actually used for something.
double sqrDist(double x, double y) const
Returns the squared distance between this point a specified x, y coordinate.
bool locked
Whether the constraint is active, i.e. should be considered.
QgsCadUtils::AlignMapPointConstraint distanceConstraint
Constraint for distance.
#define QgsDebugMsgLevel(str, level)
void setY(double y)
Sets the y value of the point.
Structure defining all constraints for alignMapPoint() method.
void edgePoints(QgsPointXY &pt1, QgsPointXY &pt2) const
Only for a valid edge match - obtain endpoints of the edge.
QgsCadUtils::AlignMapPointConstraint commonAngleConstraint
Constraint for soft lock to a common angle.
virtual bool acceptMatch(const QgsPointLocator::Match &match)=0
QgsPointXY finalMapPoint
map point aligned according to the constraints
double value
Numeric value of the constraint (coordinate/distance in map units or angle in degrees) ...
void setX(double x)
Sets the x value of the point.
Structure returned from alignMapPoint() method.
double mapUnitsPerPixel
Map units/pixel ratio from map canvas. Needed for.
void dump() const
Dumps the context's properties, for debugging.
QgsPointXY point() const
for vertex / edge match coords depending on what class returns it (geom.cache: layer coords...
static bool lineCircleIntersection(const QgsPointXY ¢er, const double radius, const QgsPointXY &linePoint1, const QgsPointXY &linePoint2, QgsPointXY &intersection)
Compute the intersection of a line and a circle.
QgsCadUtils::AlignMapPointConstraint xConstraint
Constraint for X coordinate.
QgsCadUtils::AlignMapPointConstraint angleConstraint
Constraint for angle.
bool valid
Whether the combination of constraints is actually valid.
QgsSnappingUtils * snappingUtils
Snapping utils that will be used to snap point to map. Must not be null.
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.
QgsPointLocator::Match snapToMap(QPoint point, QgsPointLocator::MatchFilter *filter=nullptr)
Snap to map according to the current configuration. Optional filter allows discarding unwanted matche...
bool relative
Whether the value is relative to previous value.
QList< QgsPointXY > cadPointList
List of recent CAD points in map coordinates.