<commit_before>// Copyright 2014 <NAME>. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package engi

import "math"

// A rather basic camera
type Camera struct {
	DeadzoneSize Point
	pos, to      Point
	tracking     *Entity // The entity that is currently being followed
}

func (cam *Camera) FollowEntity(entity *Entity) {
	cam.tracking = entity
	var space *SpaceComponent
	if !cam.tracking.GetComponent(&space) {
		return
	}

	cam.to = space.Position
	cam.centerCam(Width(), Height(), 1, space)
}

func (cam *Camera) Update(dt float32) {
	if cam.tracking != nil {
		var space *SpaceComponent
		if !cam.tracking.GetComponent(&space) {
			return
		}
		cam.centerCam(Width(), Height(), 0.09, space)
	}
}

func (cam *Camera) centerCam(width, height, lerp float32, space *SpaceComponent) {
	cam.to.X += ((space.Position.X + space.Width/2) - (cam.to.X + width/2)) * lerp
	cam.to.Y += ((space.Position.Y + space.Height/2) - (cam.to.Y + height/2)) * lerp

	dWidth := cam.DeadzoneSize.X
	dHeight := cam.DeadzoneSize.Y

	if dWidth == 0 {
		dWidth = 200
	}

	if dHeight == 0 {
		dHeight = 200
	}

	minX, minY := cam.to.X-(dWidth/2), cam.to.Y-(dHeight/2)
	maxX, maxY := minX+dWidth, minY+dHeight

	if cam.pos.X < minX || cam.pos.X > maxX {
		cam.pos.X = Clamp(floorFloat32(minX), WorldBounds.Min.X, WorldBounds.Max.X-width)
	}

	if cam.pos.Y < minY || cam.pos.Y > maxY {
		cam.pos.Y = Clamp(floorFloat32(minY), WorldBounds.Min.Y, WorldBounds.Max.Y-height)
	}
}

func floorFloat32(i float32) float32 {
	return float32(math.Floor(float64(i)))
}<commit_msg>camera: use points for position of min/max<commit_after>// Copyright 2014 <NAME>. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package engi

import "math"

// A rather basic camera
type Camera struct {
	DeadzoneSize Point
	pos, to      Point
	tracking     *Entity // The entity that is currently being followed
}

func (cam *Camera) FollowEntity(entity *Entity) {
	cam.tracking = entity
	var space *SpaceComponent
	if !cam.tracking.GetComponent(&space) {
		return
	}

	cam.to = space.Position
	cam.centerCam(Width(), Height(), 1, space)
}

func (cam *Camera) Update(dt float32) {
	if cam.tracking != nil {
		var space *SpaceComponent
		if !cam.tracking.GetComponent(&space) {
			return
		}
		cam.centerCam(Width(), Height(), 0.09, space)
	}
}

func (cam *Camera) centerCam(width, height, lerp float32, space *SpaceComponent) {
	cam.to.X += ((space.Position.X + space.Width/2) - (cam.to.X + width/2)) * lerp
	cam.to.Y += ((space.Position.Y + space.Height/2) - (cam.to.Y + height/2)) * lerp

	dWidth := cam.DeadzoneSize.X
	dHeight := cam.DeadzoneSize.Y

	if dWidth == 0 {
		dWidth = 200
	}

	if dHeight == 0 {
		dHeight = 200
	}
	min, max := Point{}, Point{}

	min.X, min.Y = cam.to.X-(dWidth/2), cam.to.Y-(dHeight/2)
	max.X, max.Y = min.X+dWidth, min.Y+dHeight

	if cam.pos.X < min.X || cam.pos.X > min.Y {
		cam.pos.X = Clamp(floorFloat32(min.X), WorldBounds.Min.X, WorldBounds.Max.X-width)
	}

	if cam.pos.Y < max.X || cam.pos.Y > max.Y {
		cam.pos.Y = Clamp(floorFloat32(min.Y), WorldBounds.Min.Y, WorldBounds.Max.Y-height)
	}
}

func floorFloat32(i float32) float32 {
	return float32(math.Floor(float64(i)))
}
{'fraction_non_alphanumeric': 0.1513415737111848, 'fraction_numerical': 0.02411817907747965, 'mean_word_length': 3.435828877005348, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '4567294', 'n_tokens_mistral': 1336, 'n_tokens_neox': 1230, 'n_words': 320}