2018-06-29 23:36:51 +02:00
|
|
|
/*
|
2019-08-03 19:43:48 +02:00
|
|
|
* This software is licensed under the terms of the MIT License.
|
2018-06-29 23:36:51 +02:00
|
|
|
* See COPYING for further information.
|
|
|
|
* ---
|
2024-05-16 23:30:41 +02:00
|
|
|
* Copyright (c) 2011-2024, Lukas Weber <laochailan@web.de>.
|
|
|
|
* Copyright (c) 2012-2024, Andrei Alexeyev <akari@taisei-project.org>.
|
2018-06-29 23:36:51 +02:00
|
|
|
*/
|
|
|
|
|
2021-08-12 23:09:01 +02:00
|
|
|
#pragma once
|
2018-06-29 23:36:51 +02:00
|
|
|
#include "taisei.h"
|
|
|
|
|
|
|
|
#include "geometry.h"
|
2023-02-09 15:57:47 +01:00
|
|
|
#include "list.h"
|
2024-06-05 23:53:30 +02:00
|
|
|
#include "memory/mempool.h"
|
2018-06-29 23:36:51 +02:00
|
|
|
|
|
|
|
typedef struct RectPack RectPack;
|
2019-08-02 19:50:41 +02:00
|
|
|
typedef struct RectPackSection RectPackSection;
|
2024-06-05 23:53:30 +02:00
|
|
|
typedef MEMPOOL(RectPackSection) RectPackSectionPool;
|
|
|
|
typedef struct RectPackSectionSource RectPackSectionSource;
|
2018-06-29 23:36:51 +02:00
|
|
|
|
2023-02-09 15:57:47 +01:00
|
|
|
struct RectPackSection {
|
|
|
|
LIST_INTERFACE(RectPackSection);
|
|
|
|
RectPackSection *parent;
|
|
|
|
RectPackSection *sibling;
|
|
|
|
RectPackSection *children[2];
|
2024-06-05 23:53:30 +02:00
|
|
|
Rect rect;
|
2023-02-09 15:57:47 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct RectPack {
|
|
|
|
RectPackSection root;
|
|
|
|
RectPackSection *unused_sections;
|
|
|
|
};
|
|
|
|
|
2024-06-05 23:53:30 +02:00
|
|
|
struct RectPackSectionSource {
|
|
|
|
RectPackSectionPool *pool;
|
|
|
|
MemArena *arena;
|
|
|
|
};
|
2019-08-02 19:50:41 +02:00
|
|
|
|
2024-06-05 23:53:30 +02:00
|
|
|
void rectpack_init(RectPack *rp, double width, double height)
|
|
|
|
attr_nonnull_all;
|
2019-08-02 19:50:41 +02:00
|
|
|
|
2024-06-05 23:53:30 +02:00
|
|
|
RectPackSection *rectpack_add(
|
|
|
|
RectPack *rp,
|
|
|
|
RectPackSectionSource secsrc,
|
|
|
|
double width,
|
|
|
|
double height,
|
|
|
|
bool allow_rotation
|
|
|
|
) attr_nonnull(1);
|
2024-03-20 07:57:08 +01:00
|
|
|
|
2019-08-02 19:50:41 +02:00
|
|
|
Rect rectpack_section_rect(RectPackSection *s)
|
|
|
|
attr_nonnull(1);
|
|
|
|
|
2024-06-05 23:53:30 +02:00
|
|
|
void rectpack_reclaim(RectPack *rp, RectPackSectionSource secsrc, RectPackSection *s)
|
|
|
|
attr_nonnull(1, 3);
|
2019-01-23 21:10:43 +01:00
|
|
|
|
2019-09-17 13:35:29 +02:00
|
|
|
bool rectpack_is_empty(RectPack *rp)
|
|
|
|
attr_nonnull(1);
|