Compare commits
280 commits
master
...
master-bac
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
573541ba2d | ||
|
|
8d167b960a | ||
|
|
8fc76a81f3 | ||
|
|
1508d11573 | ||
|
|
068348b3e3 | ||
|
|
762268387e | ||
|
|
aecc75828b | ||
|
|
fcd5eb2d2a | ||
|
|
cce8f0e1bc | ||
|
|
cfb56e184c | ||
|
|
047d67c4fa | ||
|
|
03b2b5d038 | ||
|
|
54dcbcb46b | ||
|
|
7cf3328a40 | ||
|
|
1508a51cde | ||
|
|
3e37f0cd3d | ||
|
|
89cca1b90e | ||
|
|
e71b8a5230 | ||
|
|
89d5a6d87c | ||
|
|
e9a4801d9e | ||
|
|
b2c393d23a | ||
|
|
e028ad1a41 | ||
|
|
4ad40058f9 | ||
|
|
72c4740f82 | ||
|
|
49cfe70c0d | ||
|
|
450a816b2b | ||
|
|
e3757770c8 | ||
|
|
2fb319840c | ||
|
|
4b7f1ad6a2 | ||
|
|
c1ccef6fbb | ||
|
|
32f53294d3 | ||
|
|
ae4f7eea33 | ||
|
|
bce1dbacc2 | ||
|
|
9e7704a446 | ||
|
|
7158be5890 | ||
|
|
559c91a144 | ||
|
|
b8f125b472 | ||
|
|
05ac11b24c | ||
|
|
378ff3f568 | ||
|
|
8f62c8f387 | ||
|
|
3dce41ea39 | ||
|
|
1cfa41b787 | ||
|
|
85a27a8975 | ||
|
|
06a02222ff | ||
|
|
4dafc07b08 | ||
|
|
9160e343c3 | ||
|
|
7321acfb3d | ||
|
|
29df264479 | ||
|
|
e8001cd95b | ||
|
|
19706ed738 | ||
|
|
119e610db6 | ||
|
|
5d96d6905f | ||
|
|
a0a40f1d04 | ||
|
|
55f5537a67 | ||
|
|
3fd3211f46 | ||
|
|
3d09f86258 | ||
|
|
bafe6a7f43 | ||
|
|
787681d320 | ||
|
|
e45cf0ff46 | ||
|
|
ab8d1a86a4 | ||
|
|
54dbfab71c | ||
|
|
bedbe25876 | ||
|
|
947d465d11 | ||
|
|
d80dfd895d | ||
|
|
eb079e1386 | ||
|
|
c41dcf9efa | ||
|
|
9cfae3fe3e | ||
|
|
9e339defd6 | ||
|
|
47ad484089 | ||
|
|
aafecb8359 | ||
|
|
be6b821a40 | ||
|
|
738ce1d914 | ||
|
|
6148ff15d2 | ||
|
|
7c7171f470 | ||
|
|
86f81fb534 | ||
|
|
7332e72bb2 | ||
|
|
add66e6cac | ||
|
|
acaa086943 | ||
|
|
55daf0f303 | ||
|
|
e937d189df | ||
|
|
c737f41d8a | ||
|
|
7927226484 | ||
|
|
0fb9326c08 | ||
|
|
5d9e270aa9 | ||
|
|
4c66704830 | ||
|
|
9a9262f6d0 | ||
|
|
430ba869d0 | ||
|
|
fe908fe0bc | ||
|
|
d9618e862e | ||
|
|
569ef734c4 | ||
|
|
893a07e924 | ||
|
|
aa53a4addb | ||
|
|
d7bc7e10ab | ||
|
|
b986cb2eff | ||
|
|
223f32a2b8 | ||
|
|
0a239578a1 | ||
|
|
c908c7b397 | ||
|
|
fb9b714353 | ||
|
|
de70d4b00f | ||
|
|
5f0ce77fca | ||
|
|
70daeeea54 | ||
|
|
476da8bb92 | ||
|
|
37b4993b70 | ||
|
|
f3bc272eae | ||
|
|
b2f5c0193a | ||
|
|
752243c7e9 | ||
|
|
29280949a8 | ||
|
|
e41714c2bb | ||
|
|
59b1d0b89a | ||
|
|
b342f4fd8c | ||
|
|
bb5cbfdfe2 | ||
|
|
87d8ce84dc | ||
|
|
ccdc8efd99 | ||
|
|
bcaef2489a | ||
|
|
3cdc5fbbef | ||
|
|
0f4a67e244 | ||
|
|
11402f577a | ||
|
|
0f6fa035aa | ||
|
|
57d5bc61ed | ||
|
|
b8bab2264f | ||
|
|
be0177b1b0 | ||
|
|
e6f535fe6e | ||
|
|
1ead32d84a | ||
|
|
65cb26a627 | ||
|
|
00d8fa0886 | ||
|
|
ecaa2bbdfb | ||
|
|
c2ad9ce501 | ||
|
|
aa2d8f1200 | ||
|
|
5d94ddd774 | ||
|
|
da74d27135 | ||
|
|
37ae4b2abb | ||
|
|
afe32d6014 | ||
|
|
ffafeba6c2 | ||
|
|
80fcbe4e2c | ||
|
|
d7d809c222 | ||
|
|
8ac49dc50b | ||
|
|
cce9609ced | ||
|
|
ac4f08c67c | ||
|
|
23e7ecb812 | ||
|
|
20ac8620e6 | ||
|
|
b906e0e66c | ||
|
|
49c67eb028 | ||
|
|
fdb861b299 | ||
|
|
828096de17 | ||
|
|
e628e7c1e2 | ||
|
|
ad543c304d | ||
|
|
ed3421321c | ||
|
|
f666416696 | ||
|
|
3ba4bef93b | ||
|
|
3bed74df87 | ||
|
|
63b0560375 | ||
|
|
1d9ef2aa6c | ||
|
|
35387395eb | ||
|
|
e6d77c639b | ||
|
|
a9a810c197 | ||
|
|
4f88c45c9e | ||
|
|
81a2247bf2 | ||
|
|
dd6b63acb1 | ||
|
|
41aa8daeb2 | ||
|
|
1f1dc001a1 | ||
|
|
93b02416de | ||
|
|
312419936e | ||
|
|
d2bb8cdd6a | ||
|
|
7112002e30 | ||
|
|
656da1fd76 | ||
|
|
38957e678b | ||
|
|
7ed6b1f33c | ||
|
|
060aaecbeb | ||
|
|
fae4d83f97 | ||
|
|
14cb588948 | ||
|
|
7d8cf66b27 | ||
|
|
a3399fdc56 | ||
|
|
7932887f43 | ||
|
|
3b50001daf | ||
|
|
83d51d3e83 | ||
|
|
f7f0d6e5be | ||
|
|
f146ddd307 | ||
|
|
69cdf43909 | ||
|
|
7298858c96 | ||
|
|
dec6a9dc73 | ||
|
|
db73ffb439 | ||
|
|
34a8d4eafd | ||
|
|
2722a25036 | ||
|
|
81e16e1c50 | ||
|
|
f7fd0c5942 | ||
|
|
023c3908e0 | ||
|
|
a5f4d7149a | ||
|
|
5d7a343a20 | ||
|
|
d5ff875497 | ||
|
|
231b30b2cb | ||
|
|
7b325244c5 | ||
|
|
c7d3b15758 | ||
|
|
5a55011911 | ||
|
|
b7a89b714e | ||
|
|
fc20f3594d | ||
|
|
826713c212 | ||
|
|
0542b7ba2e | ||
|
|
efbb09f8ba | ||
|
|
744c01c5d0 | ||
|
|
43e374f269 | ||
|
|
93a90e0291 | ||
|
|
3396e69b47 | ||
|
|
7af12ee1a0 | ||
|
|
2e0d0e0050 | ||
|
|
414d4e6411 | ||
|
|
97f79a6483 | ||
|
|
cfb4c0cfcc | ||
|
|
c284a12ade | ||
|
|
3e9365b1ee | ||
|
|
517dc83c85 | ||
|
|
e00ab4059c | ||
|
|
0e41a6e4fd | ||
|
|
97525efacb | ||
|
|
94d47ba390 | ||
|
|
8d990a0132 | ||
|
|
2810e06b3e | ||
|
|
5cf467a421 | ||
|
|
01b6f9099c | ||
|
|
616441e049 | ||
|
|
b205438601 | ||
|
|
e6d9439ba9 | ||
|
|
0a886bd8a8 | ||
|
|
43fe34dcbf | ||
|
|
7d49642376 | ||
|
|
01b7d96ebd | ||
|
|
6fcfa075f8 | ||
|
|
d888aeb2b4 | ||
|
|
92f34e2a99 | ||
|
|
424787c735 | ||
|
|
eb712a352d | ||
|
|
5fab9ee507 | ||
|
|
9c8771a378 | ||
|
|
9a7e44a96d | ||
|
|
112fea2f04 | ||
|
|
f9d62c324d | ||
|
|
55571ca3dd | ||
|
|
b06e1da529 | ||
|
|
0cefb47b66 | ||
|
|
a918c83ec1 | ||
|
|
2c8e1470d1 | ||
|
|
64e1f78739 | ||
|
|
ba95747ef9 | ||
|
|
3575cbc543 | ||
|
|
01ba8160ef | ||
|
|
939e365a4f | ||
|
|
803ce23169 | ||
|
|
00bc875846 | ||
|
|
5f186164a0 | ||
|
|
3a68e70f03 | ||
|
|
e9c6a97a07 | ||
|
|
3770c72ec0 | ||
|
|
c4a7f91d56 | ||
|
|
6db1406d68 | ||
|
|
e81449eddf | ||
|
|
7595ae3926 | ||
|
|
e9dbee6667 | ||
|
|
fa4d1d72dc | ||
|
|
0301f608bd | ||
|
|
a543568e1d | ||
|
|
576a3565f7 | ||
|
|
62cb2bb8b7 | ||
|
|
8e00882bb3 | ||
|
|
df3767df29 | ||
|
|
90998e2279 | ||
|
|
6bca7431b7 | ||
|
|
91b00817e3 | ||
|
|
d80ea40848 | ||
|
|
bedd88be2e | ||
|
|
bc892da992 | ||
|
|
fabceb52d3 | ||
|
|
b68539cc0c | ||
|
|
44bad77e93 | ||
|
|
e63843c6bb | ||
|
|
692994c2d3 | ||
|
|
facc17ec1b | ||
|
|
4c9691e192 | ||
|
|
c75cb9fb48 | ||
|
|
d362d8c3b3 | ||
|
|
eb9210de1c | ||
|
|
9cf541a6ba |
23 changed files with 19 additions and 797 deletions
6
.gitmodules
vendored
6
.gitmodules
vendored
|
|
@ -22,9 +22,3 @@
|
|||
[submodule "Externals/implot"]
|
||||
path = Externals/implot
|
||||
url = https://github.com/epezent/implot.git
|
||||
[submodule "Externals/googletest"]
|
||||
path = Externals/googletest
|
||||
url = https://github.com/google/googletest.git
|
||||
[submodule "Externals/benchmark"]
|
||||
path = Externals/benchmark
|
||||
url = https://github.com/google/benchmark.git
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
project(Containers)
|
||||
|
||||
include(GoogleTest)
|
||||
|
||||
### ---------------------- Static Library --------------------- ###
|
||||
file(GLOB SOURCES "./private/*.cpp")
|
||||
file(GLOB HEADERS "./public/*.hpp")
|
||||
|
|
@ -18,7 +16,6 @@ file(GLOB TEST_SOURCES
|
|||
./tests/ListTest.cpp
|
||||
./tests/MapTest.cpp
|
||||
./tests/TreeTest.cpp
|
||||
./tests/RingBufferByte.cpp
|
||||
./tests/Tests.cpp
|
||||
)
|
||||
|
||||
|
|
@ -27,10 +24,5 @@ target_link_libraries(Tests${PROJECT_NAME} ${PROJECT_NAME} UnitTest++)
|
|||
add_test(NAME Tests${PROJECT_NAME} COMMAND Tests${PROJECT_NAME})
|
||||
|
||||
|
||||
add_executable(testLinearRingBuffer ./tests/testLinearRingBuffer.cpp)
|
||||
target_link_libraries(testLinearRingBuffer ${PROJECT_NAME} gtest)
|
||||
gtest_discover_tests(testLinearRingBuffer)
|
||||
|
||||
|
||||
add_executable(AVLTreeSpeedTest ./tests/AVLTreeProfiling.cpp)
|
||||
target_link_libraries(AVLTreeSpeedTest ${PROJECT_NAME})
|
||||
|
|
@ -1,65 +0,0 @@
|
|||
#include <cstdint>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdexcept>
|
||||
#include <cstring>
|
||||
|
||||
namespace lrbm {
|
||||
static int create_memfd(const char* name) {
|
||||
int fd = syscall(SYS_memfd_create, name, 0);
|
||||
if (fd == -1) throw std::runtime_error("memfd_create failed");
|
||||
return fd;
|
||||
}
|
||||
|
||||
std::pair<void*, size_t> create_linear_ring(size_t size) {
|
||||
const size_t page = sysconf(_SC_PAGESIZE);
|
||||
|
||||
size_t aligned = (size + page - 1) & ~(page - 1);
|
||||
|
||||
// Create RAM-backed file descriptor
|
||||
int fd = create_memfd("linear_ring");
|
||||
if (ftruncate(fd, aligned) != 0) throw std::runtime_error("ftruncate failed");
|
||||
|
||||
// Reserve 2× VA space
|
||||
uint8_t* base = (uint8_t*) mmap(nullptr, aligned * 2, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
|
||||
if (base == MAP_FAILED) throw std::runtime_error("mmap reserve failed");
|
||||
|
||||
// First mapping
|
||||
void* p1 = mmap(base, aligned, PROT_READ | PROT_WRITE, MAP_FIXED | MAP_SHARED, fd, 0);
|
||||
if (p1 != base) throw std::runtime_error("first mmap failed");
|
||||
|
||||
// Mirror mapping
|
||||
void* p2 = mmap(base + aligned, aligned, PROT_READ | PROT_WRITE, MAP_FIXED | MAP_SHARED, fd, 0);
|
||||
if (p2 != base + aligned) throw std::runtime_error("mirror mmap failed");
|
||||
|
||||
close(fd);
|
||||
return { base, aligned }; // linear region [buf][buf]
|
||||
}
|
||||
|
||||
void destroy_linear_ring(void* base, size_t size) { munmap(base, size); }
|
||||
|
||||
// void test() {
|
||||
// const size_t RING_SIZE = 4096;
|
||||
// uint8_t* ring = (uint8_t*) create_linear_ring(RING_SIZE);
|
||||
|
||||
// printf("Linear ring created at %p (size = %zu)\n", ring, RING_SIZE);
|
||||
|
||||
// const char* msg = "HELLO_LINEAR_RING";
|
||||
// size_t msg_len = strlen(msg);
|
||||
|
||||
// size_t head = RING_SIZE - 4; // force boundary crossing
|
||||
// std::memcpy(ring + head, msg, msg_len);
|
||||
|
||||
// char out[64];
|
||||
// std::memcpy(out, ring + head, msg_len);
|
||||
// out[msg_len] = 0;
|
||||
|
||||
// printf("Expected: %s\n", msg);
|
||||
// printf("Readback: %s\n", out);
|
||||
|
||||
// if (std::strcmp(msg, out) == 0) printf("SUCCESS: Linear-address ring works!\n");
|
||||
// else printf("FAILURE: Ring broken!\n");
|
||||
// }
|
||||
}
|
||||
|
|
@ -1,54 +0,0 @@
|
|||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <sys/mman.h>
|
||||
|
||||
#include "liniar_ring.hpp"
|
||||
|
||||
class LinearRingBuffer {
|
||||
public:
|
||||
LinearRingBuffer(size_t size, size_t history) {
|
||||
const auto& [mem, aligned_size] = lrbm::create_linear_ring(size);
|
||||
|
||||
mem_ = (uint8_t*) mem;
|
||||
memSize_ = aligned_size;
|
||||
bufferSize_ = size;
|
||||
historySize_ = history;
|
||||
|
||||
write_ptr_ = mem_;
|
||||
read_ptr_ = mem_;
|
||||
}
|
||||
|
||||
~LinearRingBuffer() { lrbm::destroy_linear_ring((void*) mem_, memSize_ * 2); }
|
||||
|
||||
uint8_t* write_data() { return write_ptr_; }
|
||||
uint8_t* read_data() { return read_ptr_; }
|
||||
|
||||
void write_advance(size_t bytes) { write_ptr_ = advancePointer(write_ptr_, bytes); }
|
||||
void read_advance(size_t bytes) { read_ptr_ = advancePointer(read_ptr_, bytes); }
|
||||
|
||||
void read_reset_with_history() {
|
||||
const auto offset = size_t(write_ptr_ - mem_);
|
||||
|
||||
if (historySize_ < offset) {
|
||||
read_ptr_ = write_ptr_ - historySize_;
|
||||
return;
|
||||
}
|
||||
|
||||
read_ptr_ = mem_ + (memSize_ + offset - historySize_);
|
||||
}
|
||||
|
||||
private:
|
||||
inline uint8_t* advancePointer(const uint8_t* ptr, size_t bytes) {
|
||||
return mem_ + (size_t(ptr - mem_) + bytes) % memSize_;
|
||||
}
|
||||
|
||||
size_t bufferSize_ = 0;
|
||||
size_t historySize_ = 0;
|
||||
size_t memSize_ = 0;
|
||||
|
||||
uint8_t* mem_ = nullptr;
|
||||
|
||||
uint8_t* read_ptr_ = 0;
|
||||
uint8_t* write_ptr_ = 0;
|
||||
};
|
||||
|
|
@ -1,127 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
#include <stdexcept>
|
||||
#include <vector>
|
||||
|
||||
template <bool ALLOW_BUFFER_OVERRIDE>
|
||||
class RingBufferByte {
|
||||
public:
|
||||
explicit RingBufferByte(size_t maxCapacity) { buffer_.resize(maxCapacity); }
|
||||
|
||||
~RingBufferByte() = default;
|
||||
|
||||
void pushBack(const uint8_t* buffer, size_t size) {
|
||||
const auto REQUIRED_SIZE = size + sizeof(size);
|
||||
const auto DEPOSIT = static_cast<int>(freeSpace()) - static_cast<int>(REQUIRED_SIZE);
|
||||
|
||||
if (DEPOSIT < 0) {
|
||||
if (ALLOW_BUFFER_OVERRIDE) {
|
||||
freeupSpace(static_cast<size_t>(-DEPOSIT));
|
||||
} else {
|
||||
throw std::runtime_error("ring buffer overflow");
|
||||
}
|
||||
}
|
||||
|
||||
push(reinterpret_cast<const uint8_t*>(&size), sizeof(size));
|
||||
push(buffer, size);
|
||||
}
|
||||
|
||||
[[nodiscard]] auto frontSize() const -> size_t {
|
||||
size_t size = 0;
|
||||
|
||||
if (dataSize() < sizeof(size)) {
|
||||
throw std::runtime_error("no data in the buffer");
|
||||
}
|
||||
|
||||
peek(reinterpret_cast<uint8_t*>(&size), sizeof(size));
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
auto popFront(uint8_t* buffer) -> size_t {
|
||||
size_t size = 0;
|
||||
|
||||
if (dataSize() < sizeof(size)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
pop(reinterpret_cast<uint8_t*>(&size), sizeof(size));
|
||||
pop(buffer, size);
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
void clear() {
|
||||
end_ = 0;
|
||||
start_ = 0;
|
||||
}
|
||||
|
||||
[[nodiscard]] bool empty() const { return start_ == end_; }
|
||||
|
||||
private:
|
||||
void push(const uint8_t* buffer, size_t size) {
|
||||
for (size_t simpleIdx = 0; simpleIdx < size; simpleIdx++) {
|
||||
buffer_[end_++] = buffer == nullptr ? 0 : buffer[simpleIdx];
|
||||
|
||||
if (end_ == buffer_.size()) {
|
||||
end_ = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void pop(uint8_t* buffer, size_t size) {
|
||||
for (size_t sampleIdx = 0; sampleIdx < size; sampleIdx++) {
|
||||
if (buffer != nullptr) {
|
||||
buffer[sampleIdx] = buffer_[start_];
|
||||
}
|
||||
|
||||
start_++;
|
||||
|
||||
if (start_ == buffer_.size()) {
|
||||
start_ = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void peek(uint8_t* buffer, size_t size) const {
|
||||
auto iter = start_;
|
||||
for (size_t sampleIdx = 0; sampleIdx < size; sampleIdx++) {
|
||||
buffer[sampleIdx] = buffer_[iter++];
|
||||
|
||||
if (iter == buffer_.size()) {
|
||||
iter = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void freeupSpace(size_t additionalRequiredSpace) {
|
||||
const auto CURRENT_DEPOSIT = freeSpace();
|
||||
|
||||
while (CURRENT_DEPOSIT + additionalRequiredSpace >= freeSpace()) {
|
||||
popFront(nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
[[nodiscard]] size_t freeSpace() const {
|
||||
if (start_ > end_) {
|
||||
return start_ - end_;
|
||||
}
|
||||
|
||||
const auto OUT = buffer_.size() - (end_ - start_);
|
||||
return OUT;
|
||||
}
|
||||
|
||||
[[nodiscard]] size_t dataSize() const { return buffer_.size() - freeSpace(); }
|
||||
|
||||
[[nodiscard]] bool hasSpace(unsigned int length) const { return freeSpace() > length; }
|
||||
|
||||
std::vector<uint8_t> buffer_;
|
||||
|
||||
size_t end_ = 0;
|
||||
size_t start_ = 0;
|
||||
};
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
|
||||
#include <cstddef>
|
||||
#include <utility>
|
||||
|
||||
namespace lrbm {
|
||||
std::pair<void*, size_t> create_linear_ring(size_t size);
|
||||
void destroy_linear_ring(void* base, size_t size);
|
||||
void test();
|
||||
}
|
||||
|
|
@ -1,69 +0,0 @@
|
|||
|
||||
#include "Tests.hpp"
|
||||
#include "RingBufferByte.hpp"
|
||||
|
||||
SUITE(RingBufferBytes) {
|
||||
TEST(Simple) {
|
||||
|
||||
using Data = std::vector<uint8_t>;
|
||||
using DataStorage = std::vector<Data>;
|
||||
|
||||
constexpr auto BUFFER_SIZE = 395;
|
||||
constexpr auto MAX_MSG_SIZE = 31;
|
||||
constexpr auto ITERATIONS = 100000;
|
||||
|
||||
DataStorage pushed;
|
||||
DataStorage popped;
|
||||
|
||||
RingBufferByte<true> buffer(BUFFER_SIZE);
|
||||
|
||||
Data randomSamples(MAX_MSG_SIZE);
|
||||
|
||||
for (auto idx = 0; idx < MAX_MSG_SIZE; idx++) {
|
||||
randomSamples[idx] = (idx + 5 * 31) % 13;
|
||||
}
|
||||
|
||||
const auto PUSH = [&](RingBufferByte<true>& buffer, DataStorage* storage) {
|
||||
const Data& pushedSample = randomSamples;
|
||||
|
||||
buffer.pushBack(pushedSample.data(), pushedSample.size());
|
||||
|
||||
if (storage) {
|
||||
storage->push_back(pushedSample);
|
||||
}
|
||||
};
|
||||
|
||||
const auto POP = [](RingBufferByte<true>& buffer, DataStorage* storage) {
|
||||
const auto poppedSampleSize = buffer.frontSize();
|
||||
|
||||
Data poppedSample(poppedSampleSize);
|
||||
|
||||
const auto SIZE = buffer.popFront(poppedSample.data());
|
||||
|
||||
CHECK(poppedSample.size() == SIZE);
|
||||
|
||||
if (storage) {
|
||||
storage->push_back(poppedSample);
|
||||
}
|
||||
};
|
||||
|
||||
for (auto iteration = 0; iteration < ITERATIONS; iteration++) {
|
||||
PUSH(buffer, nullptr);
|
||||
}
|
||||
|
||||
while (!buffer.empty()) {
|
||||
POP(buffer, nullptr);
|
||||
}
|
||||
|
||||
for (auto iteration = 0; iteration < ITERATIONS; iteration++) {
|
||||
PUSH(buffer, &pushed);
|
||||
POP(buffer, &popped);
|
||||
}
|
||||
|
||||
CHECK(pushed.size() == popped.size());
|
||||
|
||||
for (auto idx = 0; idx < popped.size(); idx++) {
|
||||
CHECK(pushed[idx] == popped[idx]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,188 +0,0 @@
|
|||
#include "LinearRingBuffer.hpp"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <cstring>
|
||||
#include <cstdint>
|
||||
#include <random>
|
||||
|
||||
static void fill(void* ptr, size_t n, uint8_t value) { std::memset(ptr, value, n); }
|
||||
|
||||
static bool check(const void* ptr, size_t n, uint8_t value) {
|
||||
const uint8_t* p = static_cast<const uint8_t*>(ptr);
|
||||
for (size_t i = 0; i < n; ++i) {
|
||||
if (p[i] != value) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool expect_mem_eq(const void* ptr, size_t n, uint8_t value) {
|
||||
const uint8_t* p = static_cast<const uint8_t*>(ptr);
|
||||
for (size_t i = 0; i < n; ++i) {
|
||||
if (p[i] != value) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
using Data = std::vector<uint8_t>;
|
||||
using DataStorage = std::vector<Data>;
|
||||
|
||||
typedef ::testing::Types<
|
||||
std::integral_constant<size_t, 64>,
|
||||
std::integral_constant<size_t, 128>,
|
||||
std::integral_constant<size_t, 1000>,
|
||||
std::integral_constant<size_t, 4096>,
|
||||
std::integral_constant<size_t, 4096 * 2>>
|
||||
BufferSizes;
|
||||
|
||||
template <typename TypeParam>
|
||||
class LinearRingBufferTest : public ::testing::Test {
|
||||
protected:
|
||||
LinearRingBuffer rb;
|
||||
|
||||
LinearRingBufferTest() :
|
||||
historySize_(10),
|
||||
rb(size_t(TypeParam::value), size_t(historySize_)) {}
|
||||
|
||||
static constexpr auto ITERATIONS = TypeParam::value * 10;
|
||||
|
||||
size_t messagesPushed_ = 0;
|
||||
size_t historySize_ = 0;
|
||||
|
||||
auto iterations() { return ITERATIONS; }
|
||||
|
||||
auto historySize() { return historySize_; }
|
||||
|
||||
size_t randomSize() {
|
||||
static std::random_device rnd;
|
||||
std::uniform_int_distribution<size_t> dist(0, 1000);
|
||||
return dist(rnd);
|
||||
}
|
||||
|
||||
auto write_and_advance(size_t messageSize, DataStorage* storage) {
|
||||
Data pushedSample(messageSize);
|
||||
|
||||
for (auto idx = 0; idx < messageSize; idx++) {
|
||||
pushedSample[idx] = (idx + messagesPushed_++ * 53) % 321;
|
||||
}
|
||||
|
||||
std::memcpy(this->rb.write_data(), pushedSample.data(), pushedSample.size());
|
||||
this->rb.write_advance(pushedSample.size());
|
||||
|
||||
if (storage) {
|
||||
storage->push_back(pushedSample);
|
||||
}
|
||||
};
|
||||
|
||||
auto read_and_advance(size_t messageSize, DataStorage* storage) {
|
||||
Data poppedSample(messageSize);
|
||||
|
||||
std::memcpy(poppedSample.data(), this->rb.read_data(), poppedSample.size());
|
||||
|
||||
this->rb.read_advance(poppedSample.size());
|
||||
|
||||
if (storage) {
|
||||
storage->push_back(poppedSample);
|
||||
}
|
||||
};
|
||||
|
||||
auto reset_with_history() { this->rb.read_reset_with_history(); };
|
||||
|
||||
auto read_with_history(size_t messageSize, DataStorage* storage) {
|
||||
Data poppedSample(messageSize);
|
||||
|
||||
std::memcpy(poppedSample.data(), this->rb.read_data(), poppedSample.size());
|
||||
|
||||
if (storage) {
|
||||
storage->push_back(poppedSample);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
TYPED_TEST_SUITE(LinearRingBufferTest, BufferSizes);
|
||||
|
||||
TYPED_TEST(LinearRingBufferTest, LinearWriteAcrossBoundary) {
|
||||
constexpr size_t N = TypeParam::value;
|
||||
|
||||
if (N % 4096 != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto* base = this->rb.write_data();
|
||||
|
||||
size_t half = N - 16;
|
||||
fill(base, half, 0xAA);
|
||||
fill(base + half, 32, 0xBB);
|
||||
|
||||
EXPECT_EQ(expect_mem_eq(base, 16, 0xBB), true);
|
||||
EXPECT_EQ(expect_mem_eq(base + 16, half - 16, 0xAA), true);
|
||||
EXPECT_EQ(expect_mem_eq(base + half, 32, 0xBB), true);
|
||||
}
|
||||
|
||||
TYPED_TEST(LinearRingBufferTest, Chase) {
|
||||
|
||||
DataStorage pushed;
|
||||
DataStorage popped;
|
||||
|
||||
static constexpr auto MSG_SIZE = 31;
|
||||
|
||||
for (auto iteration = 0; iteration < this->iterations(); iteration++) {
|
||||
this->write_and_advance(MSG_SIZE, &pushed);
|
||||
this->read_and_advance(MSG_SIZE, &popped);
|
||||
}
|
||||
|
||||
ASSERT_EQ(pushed.size(), popped.size());
|
||||
|
||||
for (auto idx = 0; idx < popped.size(); idx++) {
|
||||
ASSERT_EQ(pushed[idx], popped[idx]);
|
||||
}
|
||||
}
|
||||
|
||||
Data makeMessageWithHistory(const Data& prev, const Data& current, size_t historySize) {
|
||||
if (historySize > prev.size()) historySize = prev.size();
|
||||
|
||||
std::vector<uint8_t> result;
|
||||
|
||||
result.reserve(historySize + current.size());
|
||||
|
||||
result.insert(result.end(), prev.end() - historySize, prev.end());
|
||||
result.insert(result.end(), current.begin(), current.end());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
TYPED_TEST(LinearRingBufferTest, History) {
|
||||
|
||||
DataStorage pushed;
|
||||
DataStorage popped;
|
||||
|
||||
pushed.push_back(Data(this->historySize()));
|
||||
|
||||
static constexpr auto MAX_MSG_SIZE = 111;
|
||||
|
||||
for (auto iteration = 0; iteration < this->iterations(); iteration++) {
|
||||
|
||||
const auto MSG_SIZE = this->historySize() + this->randomSize() % MAX_MSG_SIZE;
|
||||
|
||||
auto prevPushed = pushed.back();
|
||||
pushed.clear();
|
||||
|
||||
this->reset_with_history();
|
||||
|
||||
this->write_and_advance(MSG_SIZE, &pushed);
|
||||
auto currentPushed = pushed.back();
|
||||
|
||||
this->read_with_history(this->historySize() + MSG_SIZE, &popped);
|
||||
auto poppedWithHistory = popped.back();
|
||||
popped.clear();
|
||||
|
||||
auto correctResult = makeMessageWithHistory(prevPushed, currentPushed, this->historySize());
|
||||
|
||||
ASSERT_EQ(correctResult, poppedWithHistory);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
|
|
@ -1,188 +0,0 @@
|
|||
#include "LinearRingBuffer.hpp"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <cstring>
|
||||
#include <cstdint>
|
||||
#include <random>
|
||||
|
||||
static void fill(void* ptr, size_t n, uint8_t value) { std::memset(ptr, value, n); }
|
||||
|
||||
static bool check(const void* ptr, size_t n, uint8_t value) {
|
||||
const uint8_t* p = static_cast<const uint8_t*>(ptr);
|
||||
for (size_t i = 0; i < n; ++i) {
|
||||
if (p[i] != value) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool expect_mem_eq(const void* ptr, size_t n, uint8_t value) {
|
||||
const uint8_t* p = static_cast<const uint8_t*>(ptr);
|
||||
for (size_t i = 0; i < n; ++i) {
|
||||
if (p[i] != value) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
using Data = std::vector<uint8_t>;
|
||||
using DataStorage = std::vector<Data>;
|
||||
|
||||
typedef ::testing::Types<
|
||||
std::integral_constant<size_t, 64>,
|
||||
std::integral_constant<size_t, 128>,
|
||||
std::integral_constant<size_t, 1000>,
|
||||
std::integral_constant<size_t, 4096>,
|
||||
std::integral_constant<size_t, 4096 * 2>>
|
||||
BufferSizes;
|
||||
|
||||
template <typename TypeParam>
|
||||
class LinearRingBufferTest : public ::testing::Test {
|
||||
protected:
|
||||
LinearRingBuffer rb;
|
||||
|
||||
LinearRingBufferTest() :
|
||||
historySize_(10),
|
||||
rb(size_t(TypeParam::value), size_t(historySize_)) {}
|
||||
|
||||
static constexpr auto ITERATIONS = TypeParam::value * 10;
|
||||
|
||||
size_t messagesPushed_ = 0;
|
||||
size_t historySize_ = 0;
|
||||
|
||||
auto iterations() { return ITERATIONS; }
|
||||
|
||||
auto historySize() { return historySize_; }
|
||||
|
||||
size_t randomSize() {
|
||||
static std::random_device rnd;
|
||||
std::uniform_int_distribution<size_t> dist(0, 1000);
|
||||
return dist(rnd);
|
||||
}
|
||||
|
||||
auto write_and_advance(size_t messageSize, DataStorage* storage) {
|
||||
Data pushedSample(messageSize);
|
||||
|
||||
for (auto idx = 0; idx < messageSize; idx++) {
|
||||
pushedSample[idx] = (idx + messagesPushed_++ * 53) % 321;
|
||||
}
|
||||
|
||||
std::memcpy(this->rb.write_data(), pushedSample.data(), pushedSample.size());
|
||||
this->rb.write_advance(pushedSample.size());
|
||||
|
||||
if (storage) {
|
||||
storage->push_back(pushedSample);
|
||||
}
|
||||
};
|
||||
|
||||
auto read_and_advance(size_t messageSize, DataStorage* storage) {
|
||||
Data poppedSample(messageSize);
|
||||
|
||||
std::memcpy(poppedSample.data(), this->rb.read_data(), poppedSample.size());
|
||||
|
||||
this->rb.read_advance(poppedSample.size());
|
||||
|
||||
if (storage) {
|
||||
storage->push_back(poppedSample);
|
||||
}
|
||||
};
|
||||
|
||||
auto reset_with_history() { this->rb.read_reset_with_history(); };
|
||||
|
||||
auto read_with_history(size_t messageSize, DataStorage* storage) {
|
||||
Data poppedSample(messageSize);
|
||||
|
||||
std::memcpy(poppedSample.data(), this->rb.read_data(), poppedSample.size());
|
||||
|
||||
if (storage) {
|
||||
storage->push_back(poppedSample);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
TYPED_TEST_SUITE(LinearRingBufferTest, BufferSizes);
|
||||
|
||||
TYPED_TEST(LinearRingBufferTest, LinearWriteAcrossBoundary) {
|
||||
constexpr size_t N = TypeParam::value;
|
||||
|
||||
if (N % 4096 != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto* base = this->rb.write_data();
|
||||
|
||||
size_t half = N - 16;
|
||||
fill(base, half, 0xAA);
|
||||
fill(base + half, 32, 0xBB);
|
||||
|
||||
EXPECT_EQ(expect_mem_eq(base, 16, 0xBB), true);
|
||||
EXPECT_EQ(expect_mem_eq(base + 16, half - 16, 0xAA), true);
|
||||
EXPECT_EQ(expect_mem_eq(base + half, 32, 0xBB), true);
|
||||
}
|
||||
|
||||
TYPED_TEST(LinearRingBufferTest, Chase) {
|
||||
|
||||
DataStorage pushed;
|
||||
DataStorage popped;
|
||||
|
||||
static constexpr auto MSG_SIZE = 31;
|
||||
|
||||
for (auto iteration = 0; iteration < this->iterations(); iteration++) {
|
||||
this->write_and_advance(MSG_SIZE, &pushed);
|
||||
this->read_and_advance(MSG_SIZE, &popped);
|
||||
}
|
||||
|
||||
ASSERT_EQ(pushed.size(), popped.size());
|
||||
|
||||
for (auto idx = 0; idx < popped.size(); idx++) {
|
||||
ASSERT_EQ(pushed[idx], popped[idx]);
|
||||
}
|
||||
}
|
||||
|
||||
Data makeMessageWithHistory(const Data& prev, const Data& current, size_t historySize) {
|
||||
if (historySize > prev.size()) historySize = prev.size();
|
||||
|
||||
std::vector<uint8_t> result;
|
||||
|
||||
result.reserve(historySize + current.size());
|
||||
|
||||
result.insert(result.end(), prev.end() - historySize, prev.end());
|
||||
result.insert(result.end(), current.begin(), current.end());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
TYPED_TEST(LinearRingBufferTest, History) {
|
||||
|
||||
DataStorage pushed;
|
||||
DataStorage popped;
|
||||
|
||||
pushed.push_back(Data(this->historySize()));
|
||||
|
||||
static constexpr auto MAX_MSG_SIZE = 111;
|
||||
|
||||
for (auto iteration = 0; iteration < this->iterations(); iteration++) {
|
||||
|
||||
const auto MSG_SIZE = this->historySize() + this->randomSize() % MAX_MSG_SIZE;
|
||||
|
||||
auto prevPushed = pushed.back();
|
||||
pushed.clear();
|
||||
|
||||
this->reset_with_history();
|
||||
|
||||
this->write_and_advance(MSG_SIZE, &pushed);
|
||||
auto currentPushed = pushed.back();
|
||||
|
||||
this->read_with_history(this->historySize() + MSG_SIZE, &popped);
|
||||
auto poppedWithHistory = popped.back();
|
||||
popped.clear();
|
||||
|
||||
auto correctResult = makeMessageWithHistory(prevPushed, currentPushed, this->historySize());
|
||||
|
||||
ASSERT_EQ(correctResult, poppedWithHistory);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
|
|
@ -10,8 +10,6 @@
|
|||
|
||||
using namespace tp;
|
||||
|
||||
#include <filesystem>
|
||||
|
||||
void loadImage(Buffer<halnf>& output, const char* name) {
|
||||
int x, y, channels_in_file;
|
||||
unsigned char* loadedImage = stbi_load(name, &x, &y, &channels_in_file, 4);
|
||||
|
|
@ -30,9 +28,7 @@ void loadImage(Buffer<halnf>& output, const char* name) {
|
|||
void loadNN(FCNN& nn) {
|
||||
ArchiverLocalConnection<true> archiver;
|
||||
|
||||
if (std::filesystem::exists(std::filesystem::path("NumRec.wb"))) {
|
||||
archiver.connection.connect(LocalConnection::Location("NumRec.wb"), LocalConnection::Type(true));
|
||||
}
|
||||
|
||||
if (archiver.connection.getConnectionStatus().isOpened()) {
|
||||
archiver % nn;
|
||||
|
|
@ -60,7 +56,7 @@ void executeCmd(const char* imageName) {
|
|||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
const char* imageName = "tmp2.png";
|
||||
const char* imageName = "digit.png";
|
||||
|
||||
if (argc == 2) {
|
||||
imageName = argv[1];
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
#include <filesystem>
|
||||
#include "FCNN.hpp"
|
||||
#include "LocalConnection.hpp"
|
||||
|
||||
|
|
@ -72,9 +71,7 @@ struct NumberRec {
|
|||
{
|
||||
ArchiverLocalConnection<true> archiver;
|
||||
|
||||
if (std::filesystem::exists(std::filesystem::path("NumRec.wb"))) {
|
||||
archiver.connection.connect(LocalConnection::Location("NumRec.wb"), LocalConnection::Type(true));
|
||||
}
|
||||
|
||||
if (archiver.connection.getConnectionStatus().isOpened()) {
|
||||
archiver % nn;
|
||||
|
|
@ -218,7 +215,7 @@ int main() {
|
|||
|
||||
auto batchSize = trainRange.idxDiff() / numBatches;
|
||||
|
||||
for (auto epoch : IterRange(10)) {
|
||||
for (auto epoch : IterRange(1)) {
|
||||
printf("Epoch %i\n", epoch.index());
|
||||
|
||||
for (auto batchIdx : IterRange(trainRange.idxDiff() / batchSize)) {
|
||||
|
|
@ -244,5 +241,5 @@ int main() {
|
|||
// app.displayImage(i);
|
||||
}
|
||||
|
||||
printf("\n\nIncorrect - %i out of %i error percentage (%f)\n\n", errors, testRange.idxDiff(), (halnf) errors / (halnf) testRange.idxDiff());
|
||||
printf("\n\nIncorrect - %i out of %i (%f)\n\n", errors, testRange.idxDiff(), (halnf) errors / (halnf) testRange.idxDiff());
|
||||
}
|
||||
2
Externals/CMakeLists.txt
vendored
2
Externals/CMakeLists.txt
vendored
|
|
@ -54,5 +54,3 @@ add_library(${PROJECT_NAME} INTERFACE)
|
|||
target_include_directories(${PROJECT_NAME} INTERFACE ./imageIO/)
|
||||
|
||||
add_subdirectory(lalr)
|
||||
|
||||
add_subdirectory(googletest)
|
||||
|
|
|
|||
1
Externals/benchmark
vendored
1
Externals/benchmark
vendored
|
|
@ -1 +0,0 @@
|
|||
Subproject commit c3f86578bb2081b52cee9d51615912ca4aa52fe4
|
||||
1
Externals/googletest
vendored
1
Externals/googletest
vendored
|
|
@ -1 +0,0 @@
|
|||
Subproject commit 1b96fa13f549387b7549cc89e1a785cf143a1a50
|
||||
2
Externals/lalr
vendored
2
Externals/lalr
vendored
|
|
@ -1 +1 @@
|
|||
Subproject commit 498612239713a6dbbf9f26b8e412e985538a0650
|
||||
Subproject commit 6d16a6bb60490a2ee4e86f689c86e647b300c7fb
|
||||
|
|
@ -82,19 +82,6 @@ void Canvas::frame(RectF rec, const RGBA& col, halnf round) {
|
|||
// nvgFill(mContext->vg);
|
||||
}
|
||||
|
||||
void Canvas::line(Vec2F start, Vec2F end, const RGBA& col, halnf thickness) {
|
||||
start += mOrigin;
|
||||
end += mOrigin;
|
||||
|
||||
nvgBeginPath(mContext->vg);
|
||||
nvgFillColor(mContext->vg, { col.r, col.g, col.b, col.a});
|
||||
nvgMoveTo(mContext->vg, start.x, start.y);
|
||||
nvgLineTo(mContext->vg, end.x, end.y);
|
||||
nvgStrokeWidth(mContext->vg, thickness);
|
||||
nvgStrokeColor(mContext->vg, { col.r, col.g, col.b, col.a });
|
||||
nvgStroke(mContext->vg);
|
||||
}
|
||||
|
||||
void Canvas::circle(Vec2F pos, halnf size, const RGBA& col) {
|
||||
pos += mOrigin;
|
||||
|
||||
|
|
|
|||
|
|
@ -75,7 +75,6 @@ namespace tp {
|
|||
void circle(Vec2F pos, halnf size, const RGBA& col);
|
||||
void text(const char*, const RectF&, halnf size, Align, halnf padding, const RGBA&);
|
||||
void colorWheel(const RectF& rec, const ColorWheel& colorWheel);
|
||||
void line(Vec2F start, Vec2F end, const RGBA& col, halnf thickness);
|
||||
|
||||
ImageHandle createImageFromTextId(ualni id, Vec2F size);
|
||||
void updateTextureID(ImageHandle handle, ualni id);
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ target_link_libraries(${PROJECT_NAME} PUBLIC Graphics Connection Widgets)
|
|||
target_link_libraries(${PROJECT_NAME} PUBLIC ${BINDINGS_LIBS})
|
||||
|
||||
file(COPY "library" DESTINATION "${CMAKE_BINARY_DIR}/${PROJECT_NAME}")
|
||||
file(COPY "applications/Font.ttf" DESTINATION "${CMAKE_BINARY_DIR}/${PROJECT_NAME}/rsc/")
|
||||
file(COPY "applications/Font.ttf" DESTINATION "${CMAKE_BINARY_DIR}/${PROJECT_NAME}/")
|
||||
|
||||
### -------------------------- Applications -------------------------- ###
|
||||
add_executable(libView ./applications/Entry.cpp)
|
||||
|
|
|
|||
|
|
@ -465,15 +465,8 @@ namespace tp {
|
|||
}
|
||||
|
||||
// Matrix Properties
|
||||
MVec toGlobal(const MVec &in) const { return i * in.x + j * in.y; }
|
||||
|
||||
Mat toGlobal(const Mat &in) const { return {toGlobal(in.i), toGlobal(in.j)}; }
|
||||
|
||||
MVec toLocal(const MVec &in) const { return transform(in); }
|
||||
|
||||
MVec transform(const MVec& in) const { return MVec(i.x * in.x + i.y * in.y, j.x * in.x + j.y * in.y); }
|
||||
|
||||
// ???
|
||||
Mat transform(const Mat& in) const {
|
||||
Mat out;
|
||||
out.i.x = i.x * in.i.x + j.x * in.i.y;
|
||||
|
|
|
|||
|
|
@ -70,29 +70,6 @@ namespace tp {
|
|||
return *this;
|
||||
}
|
||||
|
||||
Rect<Type>& adjust(tp::halnf left, tp::halnf bottom, tp::halnf right, tp::halnf top) {
|
||||
x += left;
|
||||
y += bottom;
|
||||
size.x += -left + right;
|
||||
size.y += -bottom + top;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Rect<Type> adjusted(tp::halnf left, tp::halnf bottom, tp::halnf right, tp::halnf top) const {
|
||||
return Rect<Type>(*this).adjust(left, bottom, right, top);
|
||||
}
|
||||
|
||||
[[nodiscard]] halnf left() const { return x; }
|
||||
[[nodiscard]] halnf bottom() { return y; }
|
||||
[[nodiscard]] halnf top() { return y + size.y; }
|
||||
[[nodiscard]] halnf right() { return x + size.x; }
|
||||
|
||||
static Rect fromPoints(const Vec2<Type>& p1, const Vec2<Type>& p2) {
|
||||
tp::Vec2F min = {tp::min(p1.x, p2.x), tp::min(p1.y, p2.y)};
|
||||
tp::Vec2F max = {tp::max(p1.x, p2.x), tp::max(p1.y, p2.y)};
|
||||
return { min, max - min };
|
||||
}
|
||||
|
||||
bool operator==(const Rect<Type>& rect) const { return (pos == rect.pos && size == rect.size); }
|
||||
|
||||
bool isEnclosedIn(const Rect<Type>& rect, bool aParent = false) const {
|
||||
|
|
@ -207,23 +184,13 @@ namespace tp {
|
|||
}
|
||||
|
||||
void expand(const Vec2<Type>& point) {
|
||||
if (point.x < x) {
|
||||
size.x += x - point.x;
|
||||
x = point.x;
|
||||
}
|
||||
pos.x = min(point.x, pos.x);
|
||||
pos.y = min(point.y, pos.y);
|
||||
|
||||
if (point.y < y) {
|
||||
size.y += y - point.y;
|
||||
y = point.y;
|
||||
}
|
||||
|
||||
if (point.x > x + size.x) {
|
||||
size.x = point.x - x;
|
||||
}
|
||||
|
||||
if (point.y > y + size.y) {
|
||||
size.y = point.y - y;
|
||||
}
|
||||
auto p = pos + size;
|
||||
p.x = max(point.x, p.x);
|
||||
p.y = max(point.y, p.y);
|
||||
size = p - pos;
|
||||
}
|
||||
|
||||
void expand(const Rect<Type>& rect) {
|
||||
|
|
|
|||
|
|
@ -19,4 +19,4 @@ add_executable(Sketch3DApp ./applications/Entry.cpp)
|
|||
target_link_libraries(Sketch3DApp ${PROJECT_NAME})
|
||||
|
||||
file(COPY "rsc" DESTINATION "${CMAKE_BINARY_DIR}/${PROJECT_NAME}/")
|
||||
file(COPY "applications/Font.ttf" DESTINATION "${CMAKE_BINARY_DIR}/${PROJECT_NAME}/rsc")
|
||||
file(COPY "applications/Font.ttf" DESTINATION "${CMAKE_BINARY_DIR}/${PROJECT_NAME}/")
|
||||
|
|
|
|||
|
|
@ -14,4 +14,4 @@ add_executable(WidgetsExample examples/Example.cpp)
|
|||
target_link_libraries(WidgetsExample ${PROJECT_NAME} ${GLEW_LIB})
|
||||
target_include_directories(WidgetsExample PUBLIC ../Externals/glfw/include ${GLEW_INCLUDE_DIR})
|
||||
|
||||
file(COPY "examples/Font.ttf" DESTINATION "${CMAKE_BINARY_DIR}/${PROJECT_NAME}/rsc")
|
||||
file(COPY "examples/Font.ttf" DESTINATION "${CMAKE_BINARY_DIR}/${PROJECT_NAME}/")
|
||||
|
|
@ -10,7 +10,6 @@ namespace tp {
|
|||
WidgetApplication() = default;
|
||||
|
||||
void setRoot(Widget* widget);
|
||||
virtual void debugUI();
|
||||
|
||||
private:
|
||||
void processFrame(EventHandler* eventHandler, halnf deltaTime) override;
|
||||
|
|
@ -18,6 +17,8 @@ namespace tp {
|
|||
void drawFrame(Canvas* canvas) override;
|
||||
bool forceNewFrame() override ;
|
||||
|
||||
private:
|
||||
void debugUI();
|
||||
|
||||
private:
|
||||
halnf mDebugSplitFactor = 0.7;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue