3131#include " atlas_texture.h"
3232
3333int AtlasTexture::get_width () const {
34- if (region .size .width == 0 ) {
34+ if (rounded_region .size .width == 0 ) {
3535 if (atlas.is_valid ()) {
3636 return atlas->get_width ();
3737 }
3838 return 1 ;
3939 } else {
40- return region .size .width + margin.size .width ;
40+ return rounded_region .size .width + margin.size .width ;
4141 }
4242}
4343
4444int AtlasTexture::get_height () const {
45- if (region .size .height == 0 ) {
45+ if (rounded_region .size .height == 0 ) {
4646 if (atlas.is_valid ()) {
4747 return atlas->get_height ();
4848 }
4949 return 1 ;
5050 } else {
51- return region .size .height + margin.size .height ;
51+ return rounded_region .size .height + margin.size .height ;
5252 }
5353}
5454
@@ -94,6 +94,7 @@ void AtlasTexture::set_region(const Rect2 &p_region) {
9494 return ;
9595 }
9696 region = p_region;
97+ rounded_region = Rect2 (p_region.position , p_region.size .floor ());
9798 emit_changed ();
9899}
99100
@@ -123,7 +124,7 @@ bool AtlasTexture::has_filter_clip() const {
123124}
124125
125126Rect2 AtlasTexture::_get_region_rect () const {
126- Rect2 rc = region ;
127+ Rect2 rc = rounded_region ;
127128 if (atlas.is_valid ()) {
128129 if (rc.size .width == 0 ) {
129130 rc.size .width = atlas->get_width ();
@@ -196,14 +197,14 @@ bool AtlasTexture::get_rect_region(const Rect2 &p_rect, const Rect2 &p_src_rect,
196197
197198 Rect2 src = p_src_rect;
198199 if (src.size == Size2 ()) {
199- src.size = region .size ;
200+ src.size = rounded_region .size ;
200201 }
201202 if (src.size == Size2 () && atlas.is_valid ()) {
202203 src.size = atlas->get_size ();
203204 }
204205 Vector2 scale = p_rect.size / src.size ;
205206
206- src.position += (region .position - margin.position );
207+ src.position += (rounded_region .position - margin.position );
207208 Rect2 src_clipped = _get_region_rect ().intersection (src);
208209 if (src_clipped.size == Size2 ()) {
209210 return false ;
@@ -227,8 +228,8 @@ bool AtlasTexture::is_pixel_opaque(int p_x, int p_y) const {
227228 return true ;
228229 }
229230
230- int x = p_x + region .position .x - margin.position .x ;
231- int y = p_y + region .position .y - margin.position .y ;
231+ int x = p_x + rounded_region .position .x - margin.position .x ;
232+ int y = p_y + rounded_region .position .y - margin.position .y ;
232233
233234 // Margin edge may outside of atlas.
234235 if (x < 0 || x >= atlas->get_width ()) {
0 commit comments