<commit_before>// Copyright 2022 The Ebiten Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package ui

import (
	"fmt"
	"math"
	"sync"
	"sync/atomic"

	"github.com/hajimehoshi/ebiten/v2/internal/affine"
	"github.com/hajimehoshi/ebiten/v2/internal/atlas"
	"github.com/hajimehoshi/ebiten/v2/internal/buffered"
	"github.com/hajimehoshi/ebiten/v2/internal/clock"
	"github.com/hajimehoshi/ebiten/v2/internal/debug"
	"github.com/hajimehoshi/ebiten/v2/internal/graphics"
	"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
	"github.com/hajimehoshi/ebiten/v2/internal/hooks"
)

const screenShader = `package main

var Scale float

func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
	sourceSize := imageSrcTextureSize()
	// texelSize is one pixel size in texel sizes.
	texelSize := 1 / sourceSize
	halfScaledTexelSize := texelSize / 2 / Scale

	// Shift 1/512 [texel] to avoid the tie-breaking issue.
	// As all the vertex positions are aligned to 1/16 [pixel], this shiting should work in most cases.
	pos := texCoord
	p0 := pos - halfScaledTexelSize + (texelSize / 512)
	p1 := pos + halfScaledTexelSize + (texelSize / 512)

	// Texels must be in the source rect, so it is not necessary to check.
	c0 := imageSrc0UnsafeAt(p0)
	c1 := imageSrc0UnsafeAt(vec2(p1.x, p0.y))
	c2 := imageSrc0UnsafeAt(vec2(p0.x, p1.y))
	c3 := imageSrc0UnsafeAt(p1)

	// p is the p1 value in one pixel assuming that the pixel's upper-left is (0, 0) and the lower-right is (1, 1).
	p := fract(p1 * sourceSize)

	// rate indicates how much the 4 colors are mixed. rate is in between [0, 1].
	//
	//     0 <= p < 1/Scale: The rate is in between [0, 1)   
	//     1/Scale <= p:     Don't care. Adjacent colors (e.g. c0 vs c1 in an X direction) should be the same.
	rate := clamp(p*Scale, 0, 1)

	return mix(mix(c0, c1, rate.x), mix(c2, c3, rate.x), rate.y)
}
`

type Game interface {
	NewOffscreenImage(width, height int) *Image
	Layout(outsideWidth, outsideHeight int) (int, int)
	Update() error
	Draw()
}<commit_msg>internal/ui: fix comments<commit_after>// Copyright 2022 The Ebiten Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package ui

import (
	"fmt"
	"math"
	"sync"
	"sync/atomic"

	"github.com/hajimehoshi/ebiten/v2/internal/affine"
	"github.com/hajimehoshi/ebiten/v2/internal/atlas"
	"github.com/hajimehoshi/ebiten/v2/internal/buffered"
	"github.com/hajimehoshi/ebiten/v2/internal/clock"
	"github.com/hajimehoshi/ebiten/v2/internal/debug"
	"github.com/hajimehoshi/ebiten/v2/internal/graphics"
	"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
	"github.com/hajimehoshi/ebiten/v2/internal/hooks"
)

const screenShader = `package main

var Scale float

func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
	sourceSize := imageSrcTextureSize()
	// texelSize is one pixel size in texel sizes.
	texelSize := 1 / sourceSize
	halfScaledTexelSize := texelSize / 2 / Scale

	// Shift 1/512 [texel] to avoid the tie-breaking issue.
	// As all the vertex positions are aligned to 1/16 [pixel], this shiting should work in most cases.
	pos := texCoord
	p0 := pos - halfScaledTexelSize + (texelSize / 512)
	p1 := pos + halfScaledTexelSize + (texelSize / 512)

	// Texels must be in the source rect, so it is not necessary to check.
	c0 := imageSrc0UnsafeAt(p0)
	c1 := imageSrc0UnsafeAt(vec2(p1.x, p0.y))
	c2 := imageSrc0UnsafeAt(vec2(p0.x, p1.y))
	c3 := imageSrc0UnsafeAt(p1)

	// p is the p1 value in one pixel assuming that the pixel's upper-left is (0, 0) and the lower-right is (1, 1).
	p := fract(p1 * sourceSize)

	// rate indicates how much the 4 colors are mixed. rate is in between [0, 1].
	//
	//     0 <= p <= 1/Scale: The rate is in between [0, 1]
	//     1/Scale < p:       Don't care. Adjacent colors (e.g. c0 vs c1 in an X direction) should be the same.
	rate := clamp(p*Scale, 0, 1)

	return mix(mix(c0, c1, rate.x), mix(c2, c3, rate.x), rate.y)
}
`

type Game interface {
	NewOffscreenImage(width, height int) *Image
	Layout(outsideWidth, outsideHeight int) (int, int)
	Update() error
	Draw()
}
{'fraction_non_alphanumeric': 0.11834553730457154, 'fraction_numerical': 0.02968533544429052, 'mean_word_length': 3.6239707227813356, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3062503', 'n_tokens_mistral': 1845, 'n_tokens_neox': 1765, 'n_words': 576}