Flutter Engine
The Flutter Engine
rectangle_packer.h
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef FLUTTER_IMPELLER_TYPOGRAPHER_RECTANGLE_PACKER_H_
6#define FLUTTER_IMPELLER_TYPOGRAPHER_RECTANGLE_PACKER_H_
7
8#include "flutter/fml/logging.h"
10
11#include <cstdint>
12
13namespace impeller {
14
15struct IPoint16 {
16 int16_t x() const { return x_; }
17 int16_t y() const { return y_; }
18
19 int16_t x_;
20 int16_t y_;
21};
22
23//------------------------------------------------------------------------------
24/// @brief Packs rectangles into a specified area without rotating them.
25///
27 public:
28 //----------------------------------------------------------------------------
29 /// @brief Return an empty packer with area specified by width and height.
30 ///
31 static std::shared_ptr<RectanglePacker> Factory(int width, int height);
32
33 virtual ~RectanglePacker() {}
34
35 //----------------------------------------------------------------------------
36 /// @brief Attempt to add a rect without moving already placed rectangles.
37 ///
38 /// @param[in] width The width of the rectangle to add.
39 /// @param[in] height The height of the rectangle to add.
40 /// @param[out] loc If successful, will be set to the position of the
41 /// upper-left corner of the rectangle.
42 ///
43 /// @return Return true on success; false on failure.
44 ///
45 virtual bool AddRect(int width, int height, IPoint16* loc) = 0;
46
47 //----------------------------------------------------------------------------
48 /// @brief Returns how much area has been filled with rectangles.
49 ///
50 /// @return Percentage as a decimal between 0.0 and 1.0
51 ///
52 virtual Scalar PercentFull() const = 0;
53
54 //----------------------------------------------------------------------------
55 /// @brief Empty out all previously added rectangles.
56 ///
57 virtual void Reset() = 0;
58
59 protected:
60 RectanglePacker(int width, int height) : width_(width), height_(height) {
61 FML_DCHECK(width >= 0);
62 FML_DCHECK(height >= 0);
63 }
64
65 int width() const { return width_; }
66 int height() const { return height_; }
67
68 private:
69 const int width_;
70 const int height_;
71};
72
73} // namespace impeller
74
75#endif // FLUTTER_IMPELLER_TYPOGRAPHER_RECTANGLE_PACKER_H_
Packs rectangles into a specified area without rotating them.
virtual Scalar PercentFull() const =0
Returns how much area has been filled with rectangles.
virtual void Reset()=0
Empty out all previously added rectangles.
virtual bool AddRect(int width, int height, IPoint16 *loc)=0
Attempt to add a rect without moving already placed rectangles.
RectanglePacker(int width, int height)
static std::shared_ptr< RectanglePacker > Factory(int width, int height)
Return an empty packer with area specified by width and height.
#define FML_DCHECK(condition)
Definition: logging.h:103
float Scalar
Definition: scalar.h:18
int16_t y() const
int16_t x() const