summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2022-10-06 09:13:38 +0200
committerStanislaw Halik <sthalik@misaki.pl>2022-10-06 09:13:38 +0200
commit9575f4b78d17ef14f5908708cc4b8b047de70a7d (patch)
tree24995f9117736ea6d0928bf59fd5b4ba3936ef8d
parentb28ab01dceffa15bddedd6a59add89c87af7f289 (diff)
a
-rw-r--r--tile-atlas.cpp16
1 files changed, 6 insertions, 10 deletions
diff --git a/tile-atlas.cpp b/tile-atlas.cpp
index 0e3192ec..ac786bd1 100644
--- a/tile-atlas.cpp
+++ b/tile-atlas.cpp
@@ -22,17 +22,13 @@ tile_atlas::tile_atlas(Containers::StringView name, const ImageView2D& image, Ve
.setSubImage({}, image);
}
-std::array<Vector2, 4> tile_atlas::texcoords_for_id(std::size_t id2) const
+std::array<Vector2, 4> tile_atlas::texcoords_for_id(std::size_t id_) const
{
- const auto tile_size_ = tile_size();
- auto id_ = (int)id2;
- ASSERT(id_ >= 0 && id_ < dims_.product());
- Vector2i id = { id_ % dims_[0], id_ / dims_[0] };
- constexpr Vector2 _05{.5f, .5f};
- constexpr Vector2 _10{1, 1};
- auto p0 = Vector2(id * tile_size_);
- auto p1 = Vector2(tile_size_);
- auto x0 = p0.x(), x1 = p1.x(), y0 = p0.y(), y1 = p1.y();
+ ASSERT(id_ < size());
+ const Vector2i id = { (int)id_ % dims_[0], (int)id_ / dims_[0] };
+ const Vector2 p1(tile_size());
+ const auto p0 = Vector2(id * p1);
+ const auto x0 = p0.x(), x1 = p1.x(), y0 = p0.y(), y1 = p1.y();
return {{
{ x0+x1, y0+y1 }, // bottom right
{ x0+x1, y0 }, // top right