<commit_before>package gogame

import (
	"fmt"
	"math"

	"github.com/gopherjs/gopherjs/js"
)

// Surface represents an image or drawable sureface.
type Surface interface {
	GetCanvas() *js.Object
	Blit(source Surface, x, y float64)
	BlitArea(source Surface, area *Rect, x, y float64)
	Fill(*FillStyle)
	Width() int
	Height() int
	//Copy() Surface
	//Scroll(dx, dy int)
	//GetAt(x, y int) Color
	//SetAt(x, y int, Color)
	//SetClip(Rect)
	//GetClip() Rect
	//GetSubsurface(Rect) Surface
	//GetParent() Surface
	GetRect() Rect
	Scale() (x, y float64)
	SetScale(x, y float64)
	Rotation() float64
	SetRotation(radians float64)
	DrawRect(*Rect, Styler)
	DrawCircle(posX, posY, radius float64, s Styler)
	DrawEllipse(*Rect, Styler)
	DrawArc(r *Rect, startRadians, stopRadians float64, s Styler)
	DrawLine(startX, startY, endX, endY float64, s Styler)
	DrawLines(pointList [][2]float64, s Styler)
	//DrawQuadraticCurve(startX, startY, endX, endY, cpX, cpY, float64, s Styler)
	//DrawQuadraticCurves(points [][2]float64, cPoints [][2]float64, s Styler)
	//DrawBezierCurve(startX, startY, endX, endY, cpStartX, cpStartY, cpEndX, cpEndY float64, s Styler)
	//DrawBezierCurves(points [][2]float64, cPoints [][2]float64, s Styler)
	DrawText(text string, x, y float64, s *FontStyler)
}

var _ Surface = &surface{}

type surface struct {
	canvas   *js.Object
	ctx      *js.Object
	rotation float64
	scaleX   float64
	scaleY   float64
}

// NewSurface creates a new Surface.
func NewSurface(width, height float64) Surface {
	canvas := jq("<canvas>").Get(0)
	canvas.Set("width", width)
	canvas.Set("height", height)
	return &surface{
		canvas:   canvas,
		ctx:      canvas.Call("getContext", "2d"),
		rotation: 0,
		scaleX:   1,
		scaleY:   1,
	}
}

// GetCanvas returns the surface as an HTML canvas.
func (s *surface) GetCanvas() *js.Object {
	return s.canvas
}

// Blit draws the given surface to this one at the given position. Source's top-left corner
// fill be drawn at (x, y).
func (s *surface) Blit(source Surface, x, y float64) {
	s.ctx.Call("drawImage", source.GetCanvas(), math.Floor(x), math.Floor(y))
}

// BlitArea draws the given portion of the source surface defined by the Rect to this
// one at the given position.
func (s *surface) BlitArea(source Surface, area *Rect, x, y float64) {
	s.ctx.Call("drawImage", source.GetCanvas(), math.Floor(area.X), math.Floor(area.Y),
		math.Floor(area.W), math.Floor(area.H), math.Floor(x), math.Floor(y), math.Floor(area.W),
		math.Floor(area.H))
}

// Fill fills the whole surface with the given style.
func (s *surface) Fill(style *FillStyle) {
	s.ctx.Call("save")
	style.Style(s.ctx)
	s.ctx.Call("fillRect", 0, 0, s.canvas.Get("width"), s.canvas.Get("height"))
	s.ctx.Call("restore")
}

// Width returns the width of the surface in pixels.
func (s *surface) Width() int {
	return s.canvas.Get("width").Int()
}

// Height returns the height of the surface in pixels.
func (s *surface) Height() int {
	return s.canvas.Get("height").Int()
}

// Scale returns the x and y scales of the this surface.
func (s *surface) Scale() (x, y float64) {
	return s.scaleX, s.scaleY
}

// SetScale sets the x and y scales of this surface.
func (s *surface) SetScale(x, y float64) {
	s.scaleX = x
	s.scaleY = y
}

// Rotation returns the rotation (counter-clockwise) of this surface in radians.
func (s *surface) Rotation() float64 {
	return s.rotation<commit_msg>Make Blit, Width, and Height comments more informative<commit_after>package gogame

import (
	"fmt"
	"math"

	"github.com/gopherjs/gopherjs/js"
)

// Surface represents an image or drawable sureface.
type Surface interface {
	GetCanvas() *js.Object
	Blit(source Surface, x, y float64)
	BlitArea(source Surface, area *Rect, x, y float64)
	Fill(*FillStyle)
	Width() int
	Height() int
	//Copy() Surface
	//Scroll(dx, dy int)
	//GetAt(x, y int) Color
	//SetAt(x, y int, Color)
	//SetClip(Rect)
	//GetClip() Rect
	//GetSubsurface(Rect) Surface
	//GetParent() Surface
	GetRect() Rect
	Scale() (x, y float64)
	SetScale(x, y float64)
	Rotation() float64
	SetRotation(radians float64)
	DrawRect(*Rect, Styler)
	DrawCircle(posX, posY, radius float64, s Styler)
	DrawEllipse(*Rect, Styler)
	DrawArc(r *Rect, startRadians, stopRadians float64, s Styler)
	DrawLine(startX, startY, endX, endY float64, s Styler)
	DrawLines(pointList [][2]float64, s Styler)
	//DrawQuadraticCurve(startX, startY, endX, endY, cpX, cpY, float64, s Styler)
	//DrawQuadraticCurves(points [][2]float64, cPoints [][2]float64, s Styler)
	//DrawBezierCurve(startX, startY, endX, endY, cpStartX, cpStartY, cpEndX, cpEndY float64, s Styler)
	//DrawBezierCurves(points [][2]float64, cPoints [][2]float64, s Styler)
	DrawText(text string, x, y float64, s *FontStyler)
}

var _ Surface = &surface{}

type surface struct {
	canvas   *js.Object
	ctx      *js.Object
	rotation float64
	scaleX   float64
	scaleY   float64
	// if needed we can cache the Rect for GetRect, which would only need to change when
	// scaleX/Y or rotation change.
	// rect *Rect
}

// NewSurface creates a new Surface.
func NewSurface(width, height float64) Surface {
	canvas := jq("<canvas>").Get(0)
	canvas.Set("width", width)
	canvas.Set("height", height)
	return &surface{
		canvas:   canvas,
		ctx:      canvas.Call("getContext", "2d"),
		rotation: 0,
		scaleX:   1,
		scaleY:   1,
	}
}

// GetCanvas returns the surface as an HTML canvas.
func (s *surface) GetCanvas() *js.Object {
	return s.canvas
}

// Blit draws the given surface to this one at the given position. Source's top-left corner
// (according to GetRect) fill be drawn at (x, y).
func (s *surface) Blit(source Surface, x, y float64) {
	// TODO: scale and rotate
	s.ctx.Call("drawImage", source.GetCanvas(), math.Floor(x), math.Floor(y))
}

// BlitArea draws the given portion of the source surface defined by the Rect to this
// one with its top-left corner (according to GetRect) at the given position.
func (s *surface) BlitArea(source Surface, area *Rect, x, y float64) {
	// TODO: scale and rotate
	s.ctx.Call("drawImage", source.GetCanvas(), math.Floor(area.X), math.Floor(area.Y),
		math.Floor(area.W), math.Floor(area.H), math.Floor(x), math.Floor(y), math.Floor(area.W),
		math.Floor(area.H))
}

// Fill fills the whole surface with the given style.
func (s *surface) Fill(style *FillStyle) {
	s.ctx.Call("save")
	style.Style(s.ctx)
	s.ctx.Call("fillRect", 0, 0, s.canvas.Get("width"), s.canvas.Get("height"))
	s.ctx.Call("restore")
}

// Width returns the unrotated, unscaled width of the surface in pixels. To get the width
// after scaling and rotating use GetRect.
func (s *surface) Width() int {
	return s.canvas.Get("width").Int()
}

// Height returns the unrotated, unscaled height of the surface in pixels. To get the height
// after scaling and rotating use GetRect.
func (s *surface) Height() int {
	return s.canvas.Get("height").Int()
}

// Scale returns the x and y scales of the this surface.
func (s *surface) Scale() (x, y float64) {
	return s.scaleX, s.scaleY
}

// SetScale sets the x and y scales of this surface.
func (s *surface) SetScale(x, y float64) {
	s.scaleX = x
	s.scaleY = y
}

// Rotation returns the rotation (counter-clockwise) of this surface in radians.
func (s *surface) Rotation() float64 {
	return s.rotation
{'fraction_non_alphanumeric': 0.13906918933848916, 'fraction_numerical': 0.017677116420383925, 'mean_word_length': 4.1471215351812365, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1614546', 'n_tokens_mistral': 2752, 'n_tokens_neox': 2608, 'n_words': 830}