<commit_before>﻿//Copyright (c) 2007-2016 ppy Pty Ltd <<EMAIL>>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu-framework/master/LICENCE

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using osu.Framework.Graphics.OpenGL.Textures;

namespace osu.Framework.Graphics.Textures
{
    public class TextureAtlas
    {
        private List<Rectangle> subTextureBounds = new List<Rectangle>();
        private TextureGLSingle atlasTexture;

        private int atlasWidth;
        private int atlasHeight;

        private int currentY = 0;

        private bool IsFull
        {
            get
            {
                return false;
            }
        }

        public TextureAtlas(int width, int height)
        {
            this.atlasWidth = width;
            this.atlasHeight = height;
        }

        public void Reset()
        {
            subTextureBounds.Clear();
            currentY = 0;

            atlasTexture?.Dispose();
            atlasTexture = new TextureGLSingle(atlasWidth, atlasHeight);
        }

        private Point FindPosition(int width, int height)
        {
            // Super naive implementation only going from left to right.
            Point res = new Point(0, currentY);

            if (currentY + height > atlasHeight)
            {
                Reset();
                return new Point(0, 0);
            }

            int maxY = currentY;
            foreach (Rectangle bounds in subTextureBounds)
            {
                // +1 is required to prevent aliasing issues with sub-pixel positions while drawing. Bordering edged of other textures can show without it.
                res.X = Math.Max(res.X, bounds.Right + 1);
                maxY = Math.Max(maxY, bounds.Bottom);
            }

            if (res.X + width > atlasWidth)
            {
                // +1 is required to prevent aliasing issues with sub-pixel positions while drawing. Bordering edged of other textures can show without it.
                currentY = maxY + 1;
                subTextureBounds.Clear();
                res = FindPosition(width, height);
            }

            return res;
        }

        internal Texture Add(int width, int height)
        {
            lock(this)<commit_msg>Add more padding around dynamic texture atlases.<commit_after>﻿//Copyright (c) 2007-2016 ppy Pty Ltd <<EMAIL>>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu-framework/master/LICENCE

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using osu.Framework.Graphics.OpenGL.Textures;

namespace osu.Framework.Graphics.Textures
{
    public class TextureAtlas
    {
        private List<Rectangle> subTextureBounds = new List<Rectangle>();
        private TextureGLSingle atlasTexture;

        private int atlasWidth;
        private int atlasHeight;

        private int currentY = 0;

        private bool IsFull
        {
            get
            {
                return false;
            }
        }

        public TextureAtlas(int width, int height)
        {
            this.atlasWidth = width;
            this.atlasHeight = height;
        }

        public void Reset()
        {
            subTextureBounds.Clear();
            currentY = 0;

            atlasTexture?.Dispose();
            atlasTexture = new TextureGLSingle(atlasWidth, atlasHeight);
        }

        private Point FindPosition(int width, int height)
        {
            // Super naive implementation only going from left to right.
            Point res = new Point(0, currentY);

            if (currentY + height > atlasHeight)
            {
                Reset();
                return new Point(0, 0);
            }

            int maxY = currentY;
            foreach (Rectangle bounds in subTextureBounds)
            {
                // +1 is required to prevent aliasing issues with sub-pixel positions while drawing. Bordering edged of other textures can show without it.
                res.X = Math.Max(res.X, bounds.Right + 4);
                maxY = Math.Max(maxY, bounds.Bottom);
            }

            if (res.X + width > atlasWidth)
            {
                // +1 is required to prevent aliasing issues with sub-pixel positions while drawing. Bordering edged of other textures can show without it.
                currentY = maxY + 4;
                subTextureBounds.Clear();
                res = FindPosition(width, height);
            }

            return res;
        }

        internal Texture Add(int width, int height)
        {
            lock(this)
{'fraction_non_alphanumeric': 0.0780559646539028, 'fraction_numerical': 0.0071533768146433835, 'mean_word_length': 1.6707865168539326, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4256233', 'n_tokens_mistral': 1275, 'n_tokens_neox': 1197, 'n_words': 369}