Ejemplo n.º 1
0
Rect packIntoPlace(std::list<Vec2>& Skyline, const Vec2& r, std::list<Vec2>::iterator place) {
	float x = 0;
	auto width = r.width();
	//Initialize x
	auto first = Skyline.begin();
	auto last = Skyline.end();
	while (first != last && first != place) {
		x += first->width();
		first++;
	}

	auto newHeight = place->height() + r.height();
	auto rectangle = newRect(Vec2(x, place->height()), r);

	while (place != last && width > 0) {
		if (width >= place->width()) {
			auto newPlace = Skyline.insert(std::next(place), Vec2(place->width(), newHeight));
			Skyline.erase(place);
			place = newPlace;
			width -= place->width();
		}
		else { //need to split skyline
			Skyline.insert(place, Vec2(width, newHeight));
			auto newPlace1 = Skyline.insert(std::next(place), Vec2(place->width() - width, place->height()));
			Skyline.erase(place);
			place = newPlace1;
			width = 0;
		}
		place++;
	}

	return rectangle;
}
Ejemplo n.º 2
0
void computeLostAreas(std::list<Vec2>& Skyline, const Vec2& r, std::list<Vec2>::iterator place, std::vector<Rect>& lostAreas) {
	auto baseHeight = place->height();
	auto width = r.width();
	float x = 0;
	lostAreas.clear();

	//Initialize x
	auto first = Skyline.begin();
	auto last = Skyline.end();
	while (first != last && first != place) {
		x += first->width();
		first++;
	}

	while (place != last) {
		if (place->height() < baseHeight) {
			auto lostHeight = baseHeight - place->height();
			auto lostWidth = width >= place->width() ? place->width() : width;
			Rect lostRect = newRect(Vec2(x, place->height()), Vec2(lostWidth, lostHeight));
			if (lostRect.width() != 0 && lostRect.height() != 0)
				lostAreas.push_back(lostRect);
		}
		width -= place->width();
		x += place->width();
		place++;
		if (width <= 0)
			break;
	}
}