예제 #1
0
transition::transition(node * n1, node * n2,QString name,QString lastId)
{
    this->n1 = n1;
    this->n2 = n2;
    this->name = new QString(name);
    this->id = new QString(generateId(lastId));
    this->p1 = new QPointF(getP1());
    this->p2 = new QPointF(getP2());

    nodesAreCircles = false;
}
예제 #2
0
Logical LineClass::intersectsRect(const RectangleClass rect)
{
	double l,r,t,b;
	double top_intersection;
	double bottom_intersection;
	double toptrianglepoint;
	double bottomtrianglepoint;
	double m;
	double c;
	double x0,x1;
	double y0,y1;


	l = rect.left;
	r = rect.right;
	t = rect.top;
	b = rect.bottom;

	Point start = getP1(), end = getP2();

	x0 = start.getX();
	y0 = start.getY();
	x1 = end.getX();
	y1 = end.getY();

	//case where x0 == x1 or y0 == y1
	if(x0 == x1 || y0 == y1)
	{
		//test individual side of the object in question
		LineClass top(rect.left, rect.top, rect.right, rect.top);
		if(intersects(top))
		{
			return yes;
		}

		LineClass bottom(rect.left, rect.bottom, rect.right, rect.bottom);
		if(intersects(bottom))
		{
			return yes;
		}

		/*LineClass left(rect.left, rect.top, rect.left, rect.bottom);
		if(intersects(left))
		{
			return yes;
		}

		LineClass right(rect.right, rect.top, rect.right, rect.bottom);
		if(intersects(right))
		{
			return yes;
		}*/
		return no;
	}

	// Calculate m and c for the equation for the line (y = mx+c)
	m = (y1 - y0) / (x1 - x0);
	c = y0 - (m * x0);

	// if the line is going up from right to left then the top intersect point is on the left
	if(m>0)
	{
		top_intersection = (m * l  + c);
		bottom_intersection = (m * r  + c);
	}
	// otherwise it's on the right
	else
	{
		top_intersection = (m * r  + c);
		bottom_intersection = (m * l  + c);
	}

	// work out the top and bottom extents for the triangle
	if(y0<y1)
	{
		toptrianglepoint = y0;
		bottomtrianglepoint = y1;
	}
	else
	{
		toptrianglepoint = y1;
		bottomtrianglepoint = y0;
	}

	double topoverlap;
	double botoverlap;

	// and calculate the overlap between those two bounds
	topoverlap = top_intersection > toptrianglepoint ? top_intersection : toptrianglepoint;
	botoverlap = bottom_intersection < bottomtrianglepoint ? bottom_intersection : bottomtrianglepoint;

	// (topoverlap<botoverlap) :
	// if the intersection isn't the right way up then we have no overlap

	// (!((botoverlap<t) || (topoverlap>b)) :
	// If the bottom overlap is higher than the top of the rectangle or the top overlap is
	// lower than the bottom of the rectangle we don't have intersection. So return the negative
	// of that. Much faster than checking each of the points is within the bounds of the rectangle.
	return (topoverlap < botoverlap) && (!((botoverlap < t) || (topoverlap >b )));
}
예제 #3
0
int segmVe::operator==(segmVe & s1)
{
    return ((getP1() == s1.getP1()) && (getP2() == s1.getP2()));
}
예제 #4
0
float ToneMap::getProbability(int v)
{
    return (param_omegas_[0] * getP1(v) + param_omegas_[1] * getP2(v) + param_omegas_[2] * getP3(v));
}
예제 #5
0
void transition::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){

    option = NULL; //pour éviter un warning
    widget = NULL; //pour éviter un warning

    /*---------------------
    * Variables du painter
    ---------------------*/
    QPen pen;
    pen.setWidth(WIDTHLINE);
    pen.setColor(LINECOLOR);

    QBrush brush;
    brush.setColor(LINECOLOR);
    brush.setStyle(Qt::SolidPattern);

    QFont font(FONTNAME, FONTSIZE);
    QFontMetrics fm(font);
    int widthOfName = fm.width(*name); //récupération des dimenssion du text
   // int heightOfName = fm.height();


    painter->setPen(pen);
    painter->setFont(font);

    /*-----------------------------------------------------
    * dessine la ligne de du polygon (triangle de la fleche)
    ------------------------------------------------------*/

    /*-- IMPLIQUE QUE ON A CONSTRUIE L'OBJET AVEC LES NOEUD EN PARAMETTRE */
    QLineF line(getP1(),getP2());
    painter->drawLine(line);

    QPointF destPoint = line.p2().toPoint();
    int arrowSize =  6;
    double angle = ::acos(line.dx() / line.length());
    if (line.dy() >= 0){
        angle = TwoPi - angle;
    }

    QPointF destArrowP1 = destPoint + QPointF(    sin(angle - Pi / 3)      * arrowSize, cos(angle - Pi / 3)      * arrowSize);
    QPointF destArrowP2 = destPoint + QPointF(    sin(angle - Pi + Pi / 3) * arrowSize, cos(angle - Pi + Pi / 3) * arrowSize);

    QPolygonF tmp_polygon;
    tmp_polygon << line.p2() << destArrowP1 << destArrowP2;

    QPainterPath path;
    path.addPolygon(tmp_polygon);

    painter->drawPolygon(tmp_polygon);
    painter->fillPath(path, brush);

    /*------------------
    * dessine le texte
    -------------------*/

    int x = (line.p2().x() + line.p1().x())/2;
    int y =  (line.p2().y() + line.p1().y())/2;
    QPointF midlePoint(x,y);

    QString tmp_name = " "+(*name); //met un espace avant le nom afin de le décalé un peut de la ligne
    pen.setColor(TEXTCOLOR);
    painter->setPen(pen);
    painter->drawText(midlePoint.x()-widthOfName/2,midlePoint.y(),tmp_name);


}