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);
    }
  }
}
	// 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;
	}
// 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;
}
Exemple #4
0
double Segment::distance2(const Point2d &p) {
		return distance2(Point3d(p.getX(),p.getY(),0));
}
Exemple #5
0
void Segment::setAB(const Point2d &aa,const Point2d &bb) {
		a.set(aa.getX(),aa.getY(),0);
		b.set(bb.getX(),bb.getY(),0);
}
Exemple #6
0
Segment::Segment(const Point2d &aa,const Point2d &bb) {
		init();
		a.set(aa.getX(),aa.getY(),0);
		b.set(bb.getX(),bb.getY(),0);
	}
Exemple #7
0
#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));
	REQUIRE(kreis.getCenter().getX() == Approx(0.5));
Exemple #8
0
inline Point2dFloat operator*(const Point2d pt, const float factor)
{
	return Point2dFloat(pt.getX() * factor, pt.getY() * factor);
}
Exemple #9
0
inline Point2dFloat operator*(const float factor, const Point2d pt)
{
	return Point2dFloat(factor * pt.getX(), factor * pt.getY());
}