<commit_before>package three

import (
	"github.com/go-gl/gl"
	"github.com/go-gl/glh"
	"github.com/go-gl/mathgl/mgl32"
)

type boxGeometry struct {
	bufferData    []float32
	buffer        gl.Buffer
	bufferLoaded  bool
	program       gl.Program
	programLoaded bool
	matrixID      gl.UniformLocation

	width  float32
	height float32
	depth  float32
}

func NewBoxGeometry(width, height, depth float32) *boxGeometry {
	bufferData := generateBufferData(width, height, depth)

	return &boxGeometry{
		bufferData:    bufferData,
		programLoaded: false,
		bufferLoaded:  false,
		width:         width,
		height:        height,
		depth:         depth}
}

func NewCubeGeometry(size float32) *boxGeometry {
	return NewBoxGeometry(size, size, size)
}

func generateBufferData(width, height, depth float32) []float32 {
	bufferData := make([]float32, 0)

	halfWidth := width / 2.0
	halfHeight := height / 2.0
	halfDepth := depth / 2.0

	// Bottom plane
	bufferData = append(bufferData, buildPlane(
		mgl32.Vec3{0 - halfWidth, 0 - halfHeight, 0 - halfDepth},
		mgl32.Vec3{0 + halfWidth, 0 - halfHeight, 0 - halfDepth},
		mgl32.Vec3{0 - halfWidth, 0 - halfHeight, 0 + halfDepth},
		mgl32.Vec3{0 + halfWidth, 0 - halfHeight, 0 + halfDepth},
	)...)

	// Side 1
	bufferData = append(bufferData, buildPlane(
		mgl32.Vec3{0 - halfWidth, 0 - halfHeight, 0 - halfDepth},
		mgl32.Vec3{0 + halfWidth, 0 - halfHeight, 0 - halfDepth},
		mgl32.Vec3{0 - halfWidth, 0 + halfHeight, 0 - halfDepth},
		mgl32.Vec3{0 + halfWidth, 0 + halfHeight, 0 - halfDepth},
	)...)

	// Side 2
	bufferData = append(bufferData, buildPlane(
		mgl32.Vec3{0 - halfWidth, 0 - halfHeight, 0 - halfDepth},
		mgl32.Vec3{0 - halfWidth, 0 - halfHeight, 0 + halfDepth},
		mgl32.Vec3{0 - halfWidth, 0 + halfHeight, 0 - halfDepth},
		mgl32.Vec3{0 - halfWidth, 0 + halfHeight, 0 + halfDepth},
	)...)

	// // Side 3
	bufferData = append(bufferData, buildPlane(
		mgl32.Vec3{0 + halfWidth, 0 - halfHeight, 0 - halfDepth},
		mgl32.Vec3{0 + halfWidth, 0 - halfHeight, 0 + halfDepth},
		mgl32.Vec3{0 + halfWidth, 0 + halfHeight, 0 - halfDepth},
		mgl32.Vec3{0 + halfWidth, 0 + halfHeight, 0 + halfDepth},
	)...)

	// // Side 4
	bufferData = append(bufferData, buildPlane(
		mgl32.Vec3{0 - halfWidth, 0 - halfHeight, 0 + halfDepth},
		mgl32.Vec3{0 + halfWidth, 0 - halfHeight, 0 + halfDepth},
		mgl32.Vec3{0 - halfWidth, 0 + halfHeight, 0 + halfDepth},
		mgl32.Vec3{0 + halfWidth, 0 + halfHeight, 0 + halfDepth},
	)...)

	// Top plane
	bufferData = append(bufferData, buildPlane(
		mgl32.Vec3{0 - halfWidth, 0 + halfHeight, 0 - halfDepth},
		mgl32.Vec3{0 + halfWidth, 0 + halfHeight, 0 - halfDepth},
		mgl32.Vec3{0 - halfWidth, 0 + halfHeight, 0 + halfDepth},
		mgl32.Vec3{0 + halfWidth, 0 + halfHeight, 0 + halfDepth},
	)...)

	return bufferData
}

func buildPlane(v1, v2, v3, v4 mgl32.Vec3) []float32 {
	return []float32{
		v1.X(), v1.Y(), v1.Z(),
		v4.X(), v4.Y(), v4.Z(),
		v3.X(), v3.Y(), v3.Z(),
		v1.X(), v1.Y(), v1.Z(),
		v2.X(), v2.Y(), v2.Z(),
		v4.X(), v4.Y(), v4.Z(),
	}
}

func (bg *boxGeometry) updateBuffer() {
	bg.bufferData = generateBufferData(bg.width, bg.height, bg.depth)
	bg.bufferLoaded = false
}

func (bg *boxGeometry) Program() gl.Program {
	if !bg.programLoaded {
		vShader := glh.Shader{gl.VERTEX_SHADER, loadDataFile("triangle.v.glsl")}
		fShader := glh.Shader{gl.FRAGMENT_SHADER, loadDataFile("triangle.f.glsl")}
		bg.program = glh.NewProgram(vShader, fShader)
		bg.matrixID = bg.program.GetUniformLocation("MVP")

		bg.programLoaded = true
	}

	return bg.program
}

func (bg *boxGeometry) MatrixID() gl.UniformLocation {
	return bg.matrixID
}

func (bg *boxGeometry) Buffer() gl.Buffer {
	if !bg.bufferLoaded {
		bg.buffer = gl.GenBuffer()
		bg.buffer.Bind(gl.ARRAY_BUFFER)
		gl.BufferData(gl.ARRAY_BUFFER, int(glh.Sizeof(gl.FLOAT))*len(bg.bufferData), bg.bufferData, gl.STATIC_DRAW)

		bg.bufferLoaded = true
	}

	return bg.buffer
}

func (bg *boxGeometry) VertexCount() int {
	// 6 sides * 2 (for each triangle)
	return 6 * 2 * 3
}<commit_msg>use hardcoded value for box<commit_after>package three

import (
	"github.com/go-gl/gl"
	"github.com/go-gl/glh"
	"github.com/go-gl/mathgl/mgl32"
)

type boxGeometry struct {
	bufferData    []float32
	buffer        gl.Buffer
	bufferLoaded  bool
	program       gl.Program
	programLoaded bool
	matrixID      gl.UniformLocation

	width  float32
	height float32
	depth  float32
}

func NewBoxGeometry(width, height, depth float32) *boxGeometry {
	bufferData := generateBufferData(width, height, depth)

	return &boxGeometry{
		bufferData:    bufferData,
		programLoaded: false,
		bufferLoaded:  false,
		width:         width,
		height:        height,
		depth:         depth}
}

func NewCubeGeometry(size float32) *boxGeometry {
	return NewBoxGeometry(size, size, size)
}

func generateBufferData(width, height, depth float32) []float32 {
	bufferData := make([]float32, 0)

	halfWidth := width / 2.0
	halfHeight := height / 2.0
	halfDepth := depth / 2.0

	// Bottom plane
	bufferData = append(bufferData, buildPlane(
		mgl32.Vec3{0 - halfWidth, 0 - halfHeight, 0 - halfDepth},
		mgl32.Vec3{0 + halfWidth, 0 - halfHeight, 0 - halfDepth},
		mgl32.Vec3{0 - halfWidth, 0 - halfHeight, 0 + halfDepth},
		mgl32.Vec3{0 + halfWidth, 0 - halfHeight, 0 + halfDepth},
	)...)

	// Side 1
	bufferData = append(bufferData, buildPlane(
		mgl32.Vec3{0 - halfWidth, 0 - halfHeight, 0 - halfDepth},
		mgl32.Vec3{0 + halfWidth, 0 - halfHeight, 0 - halfDepth},
		mgl32.Vec3{0 - halfWidth, 0 + halfHeight, 0 - halfDepth},
		mgl32.Vec3{0 + halfWidth, 0 + halfHeight, 0 - halfDepth},
	)...)

	// Side 2
	bufferData = append(bufferData, buildPlane(
		mgl32.Vec3{0 - halfWidth, 0 - halfHeight, 0 - halfDepth},
		mgl32.Vec3{0 - halfWidth, 0 - halfHeight, 0 + halfDepth},
		mgl32.Vec3{0 - halfWidth, 0 + halfHeight, 0 - halfDepth},
		mgl32.Vec3{0 - halfWidth, 0 + halfHeight, 0 + halfDepth},
	)...)

	// // Side 3
	bufferData = append(bufferData, buildPlane(
		mgl32.Vec3{0 + halfWidth, 0 - halfHeight, 0 - halfDepth},
		mgl32.Vec3{0 + halfWidth, 0 - halfHeight, 0 + halfDepth},
		mgl32.Vec3{0 + halfWidth, 0 + halfHeight, 0 - halfDepth},
		mgl32.Vec3{0 + halfWidth, 0 + halfHeight, 0 + halfDepth},
	)...)

	// // Side 4
	bufferData = append(bufferData, buildPlane(
		mgl32.Vec3{0 - halfWidth, 0 - halfHeight, 0 + halfDepth},
		mgl32.Vec3{0 + halfWidth, 0 - halfHeight, 0 + halfDepth},
		mgl32.Vec3{0 - halfWidth, 0 + halfHeight, 0 + halfDepth},
		mgl32.Vec3{0 + halfWidth, 0 + halfHeight, 0 + halfDepth},
	)...)

	// Top plane
	bufferData = append(bufferData, buildPlane(
		mgl32.Vec3{0 - halfWidth, 0 + halfHeight, 0 - halfDepth},
		mgl32.Vec3{0 + halfWidth, 0 + halfHeight, 0 - halfDepth},
		mgl32.Vec3{0 - halfWidth, 0 + halfHeight, 0 + halfDepth},
		mgl32.Vec3{0 + halfWidth, 0 + halfHeight, 0 + halfDepth},
	)...)

	return bufferData
}

func buildPlane(v1, v2, v3, v4 mgl32.Vec3) []float32 {
	return []float32{
		v1.X(), v1.Y(), v1.Z(),
		v4.X(), v4.Y(), v4.Z(),
		v3.X(), v3.Y(), v3.Z(),
		v1.X(), v1.Y(), v1.Z(),
		v2.X(), v2.Y(), v2.Z(),
		v4.X(), v4.Y(), v4.Z(),
	}
}

func (bg *boxGeometry) updateBuffer() {
	bg.bufferData = generateBufferData(bg.width, bg.height, bg.depth)
	bg.bufferLoaded = false
}

func (bg *boxGeometry) Program() gl.Program {
	if !bg.programLoaded {
		vShader := glh.Shader{gl.VERTEX_SHADER, loadDataFile("triangle.v.glsl")}
		fShader := glh.Shader{gl.FRAGMENT_SHADER, loadDataFile("triangle.f.glsl")}
		bg.program = glh.NewProgram(vShader, fShader)
		bg.matrixID = bg.program.GetUniformLocation("MVP")

		bg.programLoaded = true
	}

	return bg.program
}

func (bg *boxGeometry) MatrixID() gl.UniformLocation {
	return bg.matrixID
}

func (bg *boxGeometry) Buffer() gl.Buffer {
	if !bg.bufferLoaded {
		bg.buffer = gl.GenBuffer()
		bg.buffer.Bind(gl.ARRAY_BUFFER)
		gl.BufferData(gl.ARRAY_BUFFER, int(glh.Sizeof(gl.FLOAT))*len(bg.bufferData), bg.bufferData, gl.STATIC_DRAW)

		bg.bufferLoaded = true
	}

	return bg.buffer
}

func (bg *boxGeometry) VertexCount() int {
	return 36
}
{'fraction_non_alphanumeric': 0.1507946439744713, 'fraction_numerical': 0.05193342510324114, 'mean_word_length': 3.540909090909091, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, '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': '7508086', 'n_tokens_mistral': 3384, 'n_tokens_neox': 3064, 'n_words': 700}