misc.cpp
author insilmaril
Thu, 03 Sep 2009 08:52:00 +0000
changeset 790 133e2ed6b9c5
parent 789 d85834ad8c54
child 792 7d67be709091
permissions -rw-r--r--
More work on xLinks
insilmaril@139
     1
#include <math.h>
insilmaril@139
     2
insilmaril@0
     3
#include <qregexp.h>
insilmaril@0
     4
#include <qpoint.h>
insilmaril@164
     5
#include <stdlib.h>
insilmaril@0
     6
insilmaril@0
     7
#include "misc.h"
insilmaril@0
     8
insilmaril@129
     9
QString qpointToString (const QPoint &p)
insilmaril@129
    10
{
insilmaril@129
    11
	return "(" + QString("%1").arg(p.x()) +","+ QString ("%1").arg (p.y()) +")";
insilmaril@129
    12
}
insilmaril@0
    13
insilmaril@408
    14
QString qpointfToString (const QPointF &p)
insilmaril@408
    15
{
insilmaril@408
    16
	return "(" + QString("%1").arg(p.x()) +","+ QString ("%1").arg (p.y()) +")";
insilmaril@408
    17
}
insilmaril@408
    18
insilmaril@0
    19
ostream &operator<< (ostream &stream, QPoint const &p)
insilmaril@0
    20
{ 
insilmaril@366
    21
	stream << "("<<p.x()<<","<<p.y()<<")";
insilmaril@366
    22
	return stream;
insilmaril@0
    23
}
insilmaril@0
    24
insilmaril@408
    25
ostream &operator<< (ostream &stream, QPointF const &p)
insilmaril@408
    26
{ 
insilmaril@408
    27
	stream << "("<<p.x()<<","<<p.y()<<")";
insilmaril@408
    28
	return stream;
insilmaril@408
    29
}
insilmaril@408
    30
insilmaril@408
    31
qreal getAngle(const QPointF &p)
insilmaril@0
    32
{	
insilmaril@0
    33
	// Calculate angle of vector to y-axis
insilmaril@0
    34
	if (p.y()==0)
insilmaril@0
    35
	{
insilmaril@0
    36
		if (p.x()>=0)
insilmaril@0
    37
			return M_PI_2;
insilmaril@0
    38
		else
insilmaril@0
    39
			return 3* M_PI_2;
insilmaril@0
    40
	} else
insilmaril@0
    41
	{
insilmaril@0
    42
		if (p.y()>0) 
insilmaril@408
    43
			return (qreal)(M_PI  - atan ( (qreal)(p.x()) / (qreal)(p.y()) ) );
insilmaril@0
    44
		else	
insilmaril@0
    45
			if (p.x()<0)
insilmaril@408
    46
				return (qreal)( 2*M_PI - atan ( (qreal)(p.x()) / (qreal)(p.y()) ) );
insilmaril@0
    47
			else	
insilmaril@408
    48
				return (qreal)( - atan ( (qreal)(p.x()) / (qreal)(p.y()) ) );
insilmaril@0
    49
	}	
insilmaril@0
    50
}
insilmaril@0
    51
insilmaril@408
    52
qreal max(qreal a, qreal b)
insilmaril@0
    53
{
insilmaril@0
    54
	if (a>b)
insilmaril@0
    55
		return a;
insilmaril@0
    56
	return b;
insilmaril@0
    57
}
insilmaril@0
    58