misc.cpp
author insilmaril
Tue, 09 Mar 2010 13:09:05 +0000
changeset 833 bfacef6f29c1
parent 819 8f987e376035
permissions -rw-r--r--
Bugfix: Previous checkin caused toggleScroll to fail
     1 #include <math.h>
     2 
     3 #include <qregexp.h>
     4 #include <stdlib.h>
     5 
     6 #include "misc.h"
     7 
     8 #include "geometry.h"
     9 
    10 QString qpointToString (const QPoint &p)
    11 { return "(" + QString("%1").arg(p.x()) +","+ QString ("%1").arg (p.y()) +")"; }
    12 
    13 QString qpointFToString (const QPointF &p)
    14 { return "(" + QString("%1").arg(p.x()) +","+ QString ("%1").arg (p.y()) +")"; }
    15 
    16 QString VectorToString (const Vector &p)
    17 { return "(" + QString("%1").arg(p.x()) +","+ QString ("%1").arg (p.y()) +")"; }
    18 
    19 ostream &operator<< (ostream &stream, QPoint const &p)
    20 { 
    21 	stream << "("<<p.x()<<","<<p.y()<<")";
    22 	return stream;
    23 }
    24 
    25 ostream &operator<< (ostream &stream, QPointF const &p)
    26 { 
    27 	stream << "("<<p.x()<<","<<p.y()<<")";
    28 	return stream;
    29 }
    30 
    31 ostream &operator<< (ostream &stream, QRectF const &r)
    32 { 
    33 	stream << "tL="<<r.topLeft()<<" - (w,h)="<<r.width()<<","<<r.height()<<"  bR="<<r.bottomRight();
    34 	return stream;
    35 }
    36 
    37 ostream &operator<< (ostream &stream, Vector const &p)
    38 { 
    39 	stream << "("<<p.x()<<","<<p.y()<<")";
    40 	return stream;
    41 }
    42 
    43 qreal getAngle(const QPointF &p)
    44 {	
    45 	// Calculate angle of vector to y-axis
    46 	if (p.y()==0)
    47 	{
    48 		if (p.x()>=0)
    49 			return M_PI_2;
    50 		else
    51 			return 3* M_PI_2;
    52 	} else
    53 	{
    54 		if (p.y()>0) 
    55 			return (qreal)(M_PI  - atan ( (qreal)(p.x()) / (qreal)(p.y()) ) );
    56 		else	
    57 			if (p.x()<0)
    58 				return (qreal)( 2*M_PI - atan ( (qreal)(p.x()) / (qreal)(p.y()) ) );
    59 			else	
    60 				return (qreal)( - atan ( (qreal)(p.x()) / (qreal)(p.y()) ) );
    61 	}	
    62 }
    63 
    64 qreal max(qreal a, qreal b)
    65 {
    66 	if (a>b)
    67 		return a;
    68 	return b;
    69 }
    70