Skip to content

Commit dcb5d0b

Browse files
navrkaldnavrkald
authored andcommitted
Repaired arrow!
1 parent 71bfd6c commit dcb5d0b

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

RegularConvertor/finite_machine/arrow.cpp

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ QWidget *)
150150

151151

152152

153-
centerLine.setLength ( centerLine.length () - myEndItem->getRadius());
153+
//centerLine.setLength ( centerLine.length () - myEndItem->getRadius());
154154

155155
QPointF endPoint = centerLine.p2();
156156
QPointF startPoint = centerLine.p1();
@@ -295,7 +295,6 @@ QPointF Arrow::getEndItemPos() const
295295
{
296296
//QRectF rect = QRectF(endItem()->elipseBoundingRect().topLeft(), endItem()->pos());
297297
return EllipseLineIntersection(endItem()->sceneBoundingRect(), startItem()->sceneBoundingRect().center(), endItem()->sceneBoundingRect().center());
298-
299298
}
300299
}
301300

@@ -558,18 +557,18 @@ t=-------------------
558557
559558
*/
560559

561-
qreal a = elipse.width();
562-
qreal b = elipse.height();
560+
qreal a = elipse.width()/2.0;
561+
qreal b = elipse.height()/2.0;
563562
qreal m = elipse.center().x();
564563
qreal n = elipse.center().y();
565564
qreal x1 = p1.x();
566565
qreal y1 = p1.y();
567566
qreal x2 = p2.x();
568567
qreal y2 = p2.y();
569568

570-
qreal A = b*b*(x2-x1)*(x2-x1) + a*a*(y2-y1)*(y2-y1);
571-
qreal B = +2*b*b*((x2-x1)*x1-(x2-x1)*m) + 2*a*a*((y2-y1)*y1 - (y2-y1)*n);
572-
qreal C = (x1*x1-2*x1*m+m*m)*b*b + (y2*y2-2*y1*n+n*n)*a*a - a*a*b*b;
569+
qreal A = ( x2 - x1 ) * ( x2 - x1 ) * b*b + ( y2 - y1 ) * ( y2 - y1 ) * a*a;
570+
qreal B = ( 2*x1 * ( x2 - x1 ) -2 * ( x2 - x1 ) *m) * b*b + ( 2* y1 * ( y2 - y1 ) -2 * (y2-y1) * n ) * a*a;
571+
qreal C = b*b * ( x1*x1 + m*m -2*x1*m ) + a*a * (y1*y1 + n*n - 2*y1*n) - a*a*b*b;
573572
qreal D = B*B - 4*A*C;
574573

575574
if(D < 0)
@@ -578,23 +577,37 @@ t=-------------------
578577
exit(-1);
579578
}
580579

581-
qreal t1 = (-B + qSqrt(D))/2*A;
580+
qreal t1 = (-B + qSqrt(D))/(2*A);
582581
QPoint intersect1 = QPoint(x1+(x2-x1)*t1,y1+(y2-y1)*t1);
583-
qreal t2 = (-B - qSqrt(D))/2*A;
582+
qreal t2 = (-B - qSqrt(D))/(2*A);
584583
QPoint intersect2 = QPoint(x1+(x2-x1)*t2,y1+(y2-y1)*t2);
585-
584+
qDebug() <<"p1: " << p1;
585+
qDebug() <<"p2: " << p2;
586+
qDebug() << "Intersect: " <<intersect1;
586587
if((t1 >=0 && t1 <= 1 ) || (t2 >= 0 && t2 <= 1) )
587588
{
588589
if((t1 >=0 && t1 <= 1 ) && (t2 >= 0 && t2 <= 1))
589590
return (t1 < t2) ? intersect1 : intersect2;
590591
else if(t1 >=0 && t1 <= 1)
592+
{
593+
qDebug() <<"t1: " << t1;
594+
qDebug() <<"t2: " << t2;
595+
qDebug() << "Intersect: " <<intersect1;
591596
return intersect1;
597+
}
592598
else
599+
{
600+
qDebug() <<"t1: " << t1;
601+
qDebug() <<"t2: "<< t2;
602+
qDebug() <<"Intersect: " << intersect2;
593603
return intersect2;
604+
}
605+
594606
}
595607
else
596608
{
597609
qDebug() << "Fatal eroor: No intersect, returning point [0,0]";
610+
qDebug() << "Max qreal: " << std::numeric_limits<qreal>::max();
598611
qDebug() << t1;
599612
qDebug() << t2;
600613
qDebug() << intersect1;

0 commit comments

Comments
 (0)