misc.cpp
author insilmaril
Thu, 01 Oct 2009 13:23:20 +0000
changeset 800 959bd133cd1a
parent 792 7d67be709091
child 802 f076fdec767d
permissions -rw-r--r--
preparing sortFilter
insilmaril@139
     1
#include <math.h>
insilmaril@139
     2
insilmaril@0
     3
#include <qregexp.h>
insilmaril@792
     4
//#include <qpoint.h>
insilmaril@164
     5
#include <stdlib.h>
insilmaril@0
     6
insilmaril@0
     7
#include "misc.h"
insilmaril@0
     8
insilmaril@792
     9
#include "geometry.h"
insilmaril@792
    10
insilmaril@129
    11
QString qpointToString (const QPoint &p)
insilmaril@792
    12
{ return "(" + QString("%1").arg(p.x()) +","+ QString ("%1").arg (p.y()) +")"; }
insilmaril@0
    13
insilmaril@792
    14
QString qpointFToString (const QPointF &p)
insilmaril@792
    15
{ return "(" + QString("%1").arg(p.x()) +","+ QString ("%1").arg (p.y()) +")"; }
insilmaril@792
    16
insilmaril@792
    17
QString VectorToString (const Vector &p)
insilmaril@792
    18
{ return "(" + QString("%1").arg(p.x()) +","+ QString ("%1").arg (p.y()) +")"; }
insilmaril@408
    19
insilmaril@0
    20
ostream &operator<< (ostream &stream, QPoint const &p)
insilmaril@0
    21
{ 
insilmaril@366
    22
	stream << "("<<p.x()<<","<<p.y()<<")";
insilmaril@366
    23
	return stream;
insilmaril@0
    24
}
insilmaril@0
    25
insilmaril@408
    26
ostream &operator<< (ostream &stream, QPointF const &p)
insilmaril@408
    27
{ 
insilmaril@408
    28
	stream << "("<<p.x()<<","<<p.y()<<")";
insilmaril@408
    29
	return stream;
insilmaril@408
    30
}
insilmaril@408
    31
insilmaril@792
    32
ostream &operator<< (ostream &stream, Vector const &p)
insilmaril@792
    33
{ 
insilmaril@792
    34
	stream << "("<<p.x()<<","<<p.y()<<")";
insilmaril@792
    35
	return stream;
insilmaril@792
    36
}
insilmaril@792
    37
insilmaril@408
    38
qreal getAngle(const QPointF &p)
insilmaril@0
    39
{	
insilmaril@0
    40
	// Calculate angle of vector to y-axis
insilmaril@0
    41
	if (p.y()==0)
insilmaril@0
    42
	{
insilmaril@0
    43
		if (p.x()>=0)
insilmaril@0
    44
			return M_PI_2;
insilmaril@0
    45
		else
insilmaril@0
    46
			return 3* M_PI_2;
insilmaril@0
    47
	} else
insilmaril@0
    48
	{
insilmaril@0
    49
		if (p.y()>0) 
insilmaril@408
    50
			return (qreal)(M_PI  - atan ( (qreal)(p.x()) / (qreal)(p.y()) ) );
insilmaril@0
    51
		else	
insilmaril@0
    52
			if (p.x()<0)
insilmaril@408
    53
				return (qreal)( 2*M_PI - atan ( (qreal)(p.x()) / (qreal)(p.y()) ) );
insilmaril@0
    54
			else	
insilmaril@408
    55
				return (qreal)( - atan ( (qreal)(p.x()) / (qreal)(p.y()) ) );
insilmaril@0
    56
	}	
insilmaril@0
    57
}
insilmaril@0
    58
insilmaril@408
    59
qreal max(qreal a, qreal b)
insilmaril@0
    60
{
insilmaril@0
    61
	if (a>b)
insilmaril@0
    62
		return a;
insilmaril@0
    63
	return b;
insilmaril@0
    64
}
insilmaril@0
    65