forked from aseprite/aseprite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
packing_rects.h
53 lines (40 loc) · 1.35 KB
/
packing_rects.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Aseprite Gfx Library
// Copyright (C) 2001-2015 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
#ifndef GFX_TEXTURE_SIZE_H_INCLUDED
#define GFX_TEXTURE_SIZE_H_INCLUDED
#pragma once
#include "gfx/fwd.h"
#include "gfx/rect.h"
#include <vector>
namespace gfx {
// TODO add support for rotations
class PackingRects {
public:
typedef std::vector<Rect> Rects;
typedef Rects::const_iterator const_iterator;
// Iterate over all given rectangles (in the same order they where
// given in addSize() calls).
const_iterator begin() const { return m_rects.begin(); }
const_iterator end() const { return m_rects.end(); }
std::size_t size() const { return m_rects.size(); }
const Rect& operator[](int i) const { return m_rects[i]; }
// Adds a new rectangle.
void add(const Size& sz);
void add(const Rect& rc);
// Returns the best size for the texture.
Size bestFit();
// Rearrange all given rectangles to best fit a texture size.
// Returns true if all rectangles were correctly arranged or false
// if there is not enough space.
bool pack(const Size& size);
// Returns the bounds of the packed area.
const Rect& bounds() const { return m_bounds; }
private:
Rect m_bounds;
Rects m_rects;
};
} // namespace gfx
#endif