/**
 * This is a helper function which calls the Line->intersect method and adds a new Event.
 */
bool SLIntersectionTest::intersects( Line * a, Line * b ) {
  Point2d * intersection = new Point2d;
  pair<multimap<float, SLEvent *>::iterator,
      multimap<float, SLEvent *>::iterator> range; // a pair of iterators. the return value of multimap.equal_range
  multimap<float, SLEvent *>::iterator it;

  if( ( a )->intersect( b, *intersection ) ) {

    //search if intersection already exists in xstruct.
    range = xStruct.equal_range( intersection->getX() );

    //whats that? Don't know, maybe check if we had the intersection already.
    for( it = range.first; it != range.second; it++ ) {
      if( ( it->second->getType() == INTERSECTION )
          && ( it->second->getCoords() == *intersection )
          && ( ( it->second->getLines()[0] == a )
              || ( it->second->getLines()[0] == b ) )
          && ( ( it->second->getLines()[1] == a )
              || ( it->second->getLines()[1] == b ) ) ) {
        return false;
      }
    }

    xStruct.insert(
        pair<float, SLEvent *>( intersection->getX(),
            new SLEvent( INTERSECTION, *intersection, *a, *b ) ) );
    return true;
  }
  return false;
}
void LevelDesignerController::alignToGrid(void) {
  PolygonList polygonList = _model->getPolygonList();
  for (int k = 0; k < _model->rowCount(); ++k) {
    TreeItem* polygonItem = _model->getItem(_model->index(k, 0));
    std::vector<Point2d> vertices = polygonList.at(k).getVertices();
    for (int i = 0; i < polygonItem->childCount(); ++i) {
      Point2d currVertex = vertices.at(i);

      int oldX = currVertex.getX();
      int oldY = currVertex.getY();

      int extraX = static_cast<int>(oldX)%50;
      int extraY = static_cast<int>(oldY)%50;

      int newX = oldX;
      int newY = oldY;

      if (extraY < 50/3)
        newY = oldY - extraY;// + 5;
      else if (extraY > 50 - 50/3)
        newY = oldY + (50 - extraY);// + 5;

      if (extraX < 50/3)
        newX = oldX - extraX;// + 5;
      else if (extraX > 50 - 50/3)
        newX = oldX + (50 - extraX);// + 5;

      if (oldX != newX || oldY != newY)
        moveVertex(k, i, oldX, oldY, newX, newY);
    }
  }
}
Exemplo n.º 3
0
	// transform the mouse (Window coordinates) to the local coordinates (accordingly to localScreen matrix)
	// reference (local coordinates) is required to set the depth of the mouse cursor in screen
Point3d ViewportUtil::applyLocalWindow(const Point2d &mouse,const Point3d &reference) {
		Point4d ref4d(reference);
		normalizedLocal.transform(&ref4d);
		Point4d result4d(mouse.getX(),mouse.getY(),ref4d.getZ()/ref4d.getW(),1.0);
		localWindow.transform(&result4d);
		Point3d result;
		result.project(result4d);
		return result;
	}
Exemplo n.º 4
0
// CU : depth should be comprised between [-1,1] (depth in normalized device coordinate)
Point3d ViewportUtil::applyLocalWindow(const Point2d &mouse,double depth) {
	Point4d result4d(mouse.getX(),mouse.getY(),depth,1);
//	result4d.print("result4d avant =");
	localWindow.transform(&result4d);
//	localWindow.print("localWindow =");
//	result4d.print("result4d =");
	Point3d result;
	result.project(result4d);
	return result;
}
Exemplo n.º 5
0
double Segment::distance2(const Point2d &p) {
		return distance2(Point3d(p.getX(),p.getY(),0));
}
Exemplo n.º 6
0
void Segment::setAB(const Point2d &aa,const Point2d &bb) {
		a.set(aa.getX(),aa.getY(),0);
		b.set(bb.getX(),bb.getY(),0);
}
Exemplo n.º 7
0
Segment::Segment(const Point2d &aa,const Point2d &bb) {
		init();
		a.set(aa.getX(),aa.getY(),0);
		b.set(bb.getX(),bb.getY(),0);
	}
Exemplo n.º 8
0
#include <catch.hpp>
#include <color.hpp>
#include <point2d.hpp>
#include <circle.hpp>
#include <rectangle.hpp>
#define _USE_MATH_DEFINES
#include <cmath>

int main(int argc, char *argv[])
{
  return Catch::Session().run(argc, argv);
}

TEST_CASE("describe_test", "[test]"){
	Point2d punkt{0.5, 1.0};
	REQUIRE(punkt.getX() == Approx(0.5));
	REQUIRE(punkt.getY() == Approx(1.0));
	Point2d punkt2{1.0, 1.0};
	punkt2.translate(-2.0, -2.0);
	REQUIRE(punkt2.getX() == Approx(-1.0));
	REQUIRE(punkt2.getY() == Approx(-1.0));
	punkt2.rotate(M_PI);
	REQUIRE(punkt2.getX() == Approx(1.0));
	REQUIRE(punkt2.getY() == Approx(1.0));


	Color farbe{1.0, 0.0, 0.0};
	Circle kreis{punkt, 2.0, farbe};
	REQUIRE(kreis.getRadius() == Approx(2.0));
	REQUIRE(kreis.circumference() == Approx(12.56637));
	REQUIRE(kreis.getColor().r == Approx(1.0));
Exemplo n.º 9
0
inline Point2dFloat operator*(const Point2d pt, const float factor)
{
	return Point2dFloat(pt.getX() * factor, pt.getY() * factor);
}
Exemplo n.º 10
0
inline Point2dFloat operator*(const float factor, const Point2d pt)
{
	return Point2dFloat(factor * pt.getX(), factor * pt.getY());
}