61 #include "../vmisc/def.h"
62 #include "../vmisc/vmath.h"
63 #include "../ifc/ifcdef.h"
68 #ifdef Q_COMPILER_RVALUE_REFS
73 { std::swap(d, obj.d); }
243 QLineF line = QLineF();
245 line.setAngle(angle);
246 line.setLength(length);
253 QRectF rect = scRect;
254 if (rect.isValid() ==
false)
256 rect = QRectF(0, 0, 1200, 700);
258 if (rect.contains(firstPoint) ==
false)
261 QRectF rectangle(firstPoint.x()-rect.width()/2, firstPoint.y()-rect.height()/2, rect.width(), rect.height());
262 rect = rect.united(rectangle);
264 const qreal diagonal = qSqrt(pow(rect.height(), 2) + pow(rect.width(), 2));
265 const QLineF line =
BuildLine(firstPoint, diagonal, angle);
273 const QPointF endP1 =
BuildRay(p, angle+180, scRect);
274 const QPointF endP2 =
BuildRay(p, angle, scRect);
275 return QLineF(endP1, endP2);
282 return BuildAxis(p1, line.angle(), scRect);
301 const double d = QLineF (p, center).length();
302 const double k = sqrt (
d *
d - radius * radius);
315 qreal x1, y1, x2, y2;
316 rec.getCoords(&x1, &y1, &x2, &y2);
318 QLineF::IntersectType type = line.intersects(QLineF(QPointF(x1, y1), QPointF(x1, y2)), &point);
319 if ( type == QLineF::BoundedIntersection )
323 type = line.intersects(QLineF(QPointF(x1, y1), QPointF(x2, y1)), &point);
324 if ( type == QLineF::BoundedIntersection )
328 type = line.intersects(QLineF(QPointF(x1, y2), QPointF(x2, y2)), &point);
329 if ( type == QLineF::BoundedIntersection )
333 type = line.intersects(QLineF(QPointF(x2, y1), QPointF(x2, y2)), &point);
334 if ( type == QLineF::BoundedIntersection )
349 const double a = - 2.0 * (c2.x() - c1.x());
350 const double b = - 2.0 * (c2.y() - c1.y());
351 const double c = (c2.x() - c1.x())* (c2.x() - c1.x()) + (c2.y() - c1.y()) * (c2.y() - c1.y()) + r1 * r1 - r2 * r2;
353 const double x0 = -a*c/(a*a+b*b);
354 const double y0 = -b*c/(a*a+b*b);
356 if (c*c > r1*r1*(a*a+b*b))
362 p1 = QPointF(x0 + c1.x(), y0 + c1.y());
367 const double d = r1*r1 - c*c/(a*a+b*b);
368 const double mult = sqrt (
d / (a*a+b*b));
370 const double ax = x0 + b * mult;
371 const double bx = x0 - b * mult;
372 const double ay = y0 - a * mult;
373 const double by = y0 + a * mult;
375 p1 = QPointF(ax + c1.x(), ay + c1.y());
376 p2 = QPointF(bx + c1.x(), by + c1.y());
393 if (qFuzzyIsNull(line.length()))
399 qreal a = 0, b = 0, c = 0;
405 const qreal
d = QLineF (center, p).length();
422 const qreal k = qSqrt (qAbs(radius * radius -
d *
d));
423 const qreal t = QLineF (QPointF (0, 0), QPointF (b, - a)).length();
425 p1 =
addVector (p, QPointF (0, 0), QPointF (- b, a), k / t);
426 p2 =
addVector (p, QPointF (0, 0), QPointF (b, - a), k / t);
438 qreal a = 0, b = 0, c = 0;
440 qreal x = point.x() + a;
441 qreal y = b + point.y();
442 QLineF lin (point, QPointF(x, y));
444 QLineF::IntersectType intersect = line.intersects(lin, &p);
445 if (intersect == QLineF::UnboundedIntersection || intersect == QLineF::BoundedIntersection)
458 return QPointF (p.x() + (p2.x() - p1.x()) * k, p.y() + (p2.y() - p1.y()) * k);
472 QPointF p1 = line.p1();
473 *a = line.p2().y() - p1.y();
474 *b = p1.x() - line.p2().x();
475 *c = - *a * p1.x() - *b * p1.y();
487 if (not ( (p1.x() <= t.x() && t.x() <= p2.x()) || (p2.x() <= t.x() && t.x() <= p1.x()) ))
496 if (not ( (p1.y() <= t.y() && t.y() <= p2.y()) || (p2.y() <= t.y() && t.y() <= p1.y()) ))
532 return (p1.x() - t.x()) * (p2.y() - t.y()) - (p1.y() - t.y()) * (p2.x() - t.x());
548 line.setAngle(line.angle() + 90);
557 const double d = QLineF (p, center).length();
581 points << contour << newPoints;
582 for (qint32 i = 0; i < points.size()-1; ++i)
584 QLineF line(points.at(i), points.at(i+1));
585 length += line.length();
587 return qFloor(length);
593 QTransform transform;
600 const QLineF axisOX = QLineF(axis.x2(), axis.y2(), axis.x2() + 100, axis.y2());
602 const qreal angle = axis.angleTo(axisOX);
603 const QPointF p2 = axis.p2();
606 m.translate(p2.x(), p2.y());
608 m.translate(-p2.x(), -p2.y());
612 m.translate(p2.x(), p2.y());
613 m.scale(m.m11(), m.m22()*-1);
614 m.translate(-p2.x(), -p2.y());
618 m.translate(p2.x(), p2.y());
619 m.rotate(-(360-angle));
620 m.translate(-p2.x(), -p2.y());
The VGObject class keep information graphical objects.
static bool IsPointOnLineSegment(const QPointF &t, const QPointF &p1, const QPointF &p2)
IsPointOnLineSegment Check if the point is on the line segment.
static double PerpDotProduct(const QPointF &p1, const QPointF &p2, const QPointF &t)
PerpDotProduct Calculates the area of the parallelogram of the three points. This is actually the sam...
GOType getType() const
getType return object type.
static double GetEpsilon(const QPointF &p1, const QPointF &p2)
GetEpsilon solve the floating-point accuraccy problem.
void setMode(const Draw &value)
setMode set mode creation.
void setType(const GOType &type)
void setIdObject(const quint32 &value)
setIdObject set parent id.
static QLineF BuildAxis(const QPointF &p, const qreal &angle, const QRectF &scRect)
static qint32 LineIntersectCircle(const QPointF ¢er, qreal radius, const QLineF &line, QPointF &p1, QPointF &p2)
LineIntersectCircle find point intersection line and circle.
VGObject()
VGObject default constructor.
static QPointF ClosestPoint(const QLineF &line, const QPointF &point)
ClosestPoint find point projection of point onto line.
virtual QString name() const
name return name graphical object.
VGObject & operator=(const VGObject &obj)
operator = assignment operator.
static QTransform flipTransform(const QLineF &axis)
static void LineCoefficients(const QLineF &line, qreal *a, qreal *b, qreal *c)
LineCoefficients coefficient for equation of segment. Segment equestion ax+by+c=0.
static int IntersectionCircles(const QPointF &c1, double r1, const QPointF &c2, double r2, QPointF &p1, QPointF &p2)
static bool IsPointOnLineviaPDP(const QPointF &t, const QPointF &p1, const QPointF &p2)
IsPointOnLineviaPDP use the perp dot product (PDP) way.
static int PointInCircle(const QPointF &p, const QPointF ¢er, qreal radius)
static QPointF BuildRay(const QPointF &firstPoint, const qreal &angle, const QRectF &scRect)
static QLineF BuildLine(const QPointF &p1, const qreal &length, const qreal &angle)
QSharedDataPointer< VGObjectData > d
void Swap(VGObject &obj) Q_DECL_NOTHROW
quint32 getIdObject() const
getIdObject return parent id.
static QPointF LineIntersectRect(const QRectF &rec, const QLineF &line)
LineIntersectRect find point intersection line and rect.
void setName(const QString &name)
setName set name graphical object.
Draw getMode() const
getMode return mode creation.
quint32 id() const
id return id object.
virtual void setId(const quint32 &id)
setId set id object.
static QPointF addVector(const QPointF &p, const QPointF &p1, const QPointF &p2, qreal k)
static int GetLengthContour(const QVector< QPointF > &contour, const QVector< QPointF > &newPoints)
GetLengthContour return length of contour.
static int ContactPoints(const QPointF &p, const QPointF ¢er, qreal radius, QPointF &p1, QPointF &p2)
quint32 getIdTool() const
static const double accuracyPointOnLine
static Q_REQUIRED_RESULT bool VFuzzyComparePossibleNulls(double p1, double p2)