diff options
author | crupest <crupest@outlook.com> | 2020-09-12 00:53:51 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2020-09-12 00:53:51 +0800 |
commit | c41e7e63a3d0a4ebe90a536d4c7e7956a3581f02 (patch) | |
tree | 5870f791b0105c1c651d617eb1c00da28d4b2043 /include/cru/platform/GraphBase.hpp | |
parent | f357d11518796b0e0c2c5f23d8eafeda48226af9 (diff) | |
download | cru-c41e7e63a3d0a4ebe90a536d4c7e7956a3581f02.tar.gz cru-c41e7e63a3d0a4ebe90a536d4c7e7956a3581f02.tar.bz2 cru-c41e7e63a3d0a4ebe90a536d4c7e7956a3581f02.zip |
...
Diffstat (limited to 'include/cru/platform/GraphBase.hpp')
-rw-r--r-- | include/cru/platform/GraphBase.hpp | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/include/cru/platform/GraphBase.hpp b/include/cru/platform/GraphBase.hpp index 9f3f8393..186ee9d0 100644 --- a/include/cru/platform/GraphBase.hpp +++ b/include/cru/platform/GraphBase.hpp @@ -258,7 +258,7 @@ struct TextRange final { gsl::index GetStart() const { return position; } gsl::index GetEnd() const { return position + count; } - void SetEnd(gsl::index new_end) { count = new_end - position; } + void AdjustEnd(gsl::index new_end) { count = new_end - position; } TextRange Normalize() const { auto result = *this; @@ -269,6 +269,13 @@ struct TextRange final { return result; } + TextRange CoerceInto(gsl::index min, gsl::index max) const { + auto coerce = [min, max](gsl::index index) { + return index > max ? max : (index < min ? min : index); + }; + return TextRange::FromTwoSides(coerce(GetStart()), coerce(GetEnd())); + } + gsl::index position = 0; gsl::index count = 0; }; |