Skip to content

Commit

Permalink
gofmt -w *.go
Browse files Browse the repository at this point in the history
  • Loading branch information
peterhellberg committed Sep 8, 2023
1 parent e6202e6 commit 7699f00
Show file tree
Hide file tree
Showing 14 changed files with 43 additions and 57 deletions.
11 changes: 6 additions & 5 deletions batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import "image/color"
// Batch is a Target that allows for efficient drawing of many objects with the same Picture.
//
// To put an object into a Batch, just draw it onto it:
// object.Draw(batch)
//
// object.Draw(batch)
type Batch struct {
cont Drawer

Expand All @@ -34,10 +35,10 @@ func NewBatch(container Triangles, pic Picture) *Batch {
// Dirty notifies Batch about an external modification of it's container. If you retain access to
// the Batch's container and change it, call Dirty to notify Batch about the change.
//
// container := &gfx.TrianglesData{}
// batch := gfx.NewBatch(container, nil)
// container.SetLen(10) // container changed from outside of Batch
// batch.Dirty() // notify Batch about the change
// container := &gfx.TrianglesData{}
// batch := gfx.NewBatch(container, nil)
// container.SetLen(10) // container changed from outside of Batch
// batch.Dirty() // notify Batch about the change
func (b *Batch) Dirty() {
b.cont.Dirty()
}
Expand Down
17 changes: 5 additions & 12 deletions cie_lab.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ type CIELab struct {
// CIE-a*2, CIE-b*2 //Color #2 CIE-L*ab values
//
// Delta C* = sqrt( ( CIE-a*2 ^ 2 ) + ( CIE-b*2 ^ 2 ) )
// - sqrt( ( CIE-a*1 ^ 2 ) + ( CIE-b*1 ^ 2 ) )
//
// - sqrt( ( CIE-a*1 ^ 2 ) + ( CIE-b*1 ^ 2 ) )
func (c1 CIELab) DeltaC(c2 CIELab) float64 {
return math.Sqrt(math.Pow(c2.A, 2)+math.Pow(c2.B, 2)) -
math.Sqrt(math.Pow(c1.A, 2)+math.Pow(c1.B, 2))
Expand All @@ -30,14 +29,11 @@ func (c1 CIELab) DeltaC(c2 CIELab) float64 {
// CIE-a*1, CIE-b*1 //Color #1 CIE-L*ab values
// CIE-a*2, CIE-b*2 //Color #2 CIE-L*ab values
//
//
// xDE = sqrt( ( CIE-a*2 ^ 2 ) + ( CIE-b*2 ^ 2 ) )
// - sqrt( ( CIE-a*1 ^ 2 ) + ( CIE-b*1 ^ 2 ) )
// - sqrt( ( CIE-a*1 ^ 2 ) + ( CIE-b*1 ^ 2 ) )
//
// Delta H* = sqrt( ( CIE-a*2 - CIE-a*1 ) ^ 2
// + ( CIE-b*2 - CIE-b*1 ) ^ 2 - ( xDE ^ 2 ) )
//
//
// - ( CIE-b*2 - CIE-b*1 ) ^ 2 - ( xDE ^ 2 ) )
func (c1 CIELab) DeltaH(c2 CIELab) float64 {
xDE := math.Sqrt(math.Pow(c2.A, 2)+math.Pow(c2.B, 2)) -
math.Sqrt(math.Pow(c1.A, 2)+math.Pow(c1.B, 2))
Expand All @@ -52,10 +48,8 @@ func (c1 CIELab) DeltaH(c2 CIELab) float64 {
// CIE-L*2, CIE-a*2, CIE-b*2 //Color #2 CIE-L*ab values
//
// Delta E* = sqrt( ( ( CIE-L*1 - CIE-L*2 ) ^ 2 )
// + ( ( CIE-a*1 - CIE-a*2 ) ^ 2 )
// + ( ( CIE-b*1 - CIE-b*2 ) ^ 2 ) )
//
//
// - ( ( CIE-a*1 - CIE-a*2 ) ^ 2 )
// - ( ( CIE-b*1 - CIE-b*2 ) ^ 2 ) )
func (c1 CIELab) DeltaE(c2 CIELab) float64 {
return math.Sqrt(math.Pow(c1.L*1-c2.L*2, 2) +
math.Pow(c1.A*1-c2.A*2, 2) + math.Pow(c1.B*1-c2.B*2, 2),
Expand All @@ -81,7 +75,6 @@ func (c1 CIELab) DeltaE(c2 CIELab) float64 {
// CIE-L* = ( 116 * var_Y ) - 16
// CIE-a* = 500 * ( var_X - var_Y )
// CIE-b* = 200 * ( var_Y - var_Z )
//
func (xyz XYZ) CIELab(ref XYZ) CIELab {
X := xyz.X / ref.X
Y := xyz.Y / ref.Y
Expand Down
12 changes: 6 additions & 6 deletions circle.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
)

// Circle is a 2D circle. It is defined by two properties:
// - Center vector
// - Radius float64
// - Center vector
// - Radius float64
type Circle struct {
Center Vec
Radius float64
Expand Down Expand Up @@ -130,8 +130,8 @@ func (c Circle) Intersect(d Circle) Circle {
// the perimeters touch.
//
// This function will return a non-zero vector if:
// - The Rect contains the Circle, partially or fully
// - The Circle contains the Rect, partially of fully
// - The Rect contains the Circle, partially or fully
// - The Circle contains the Rect, partially of fully
func (c Circle) IntersectRect(r Rect) Vec {
// Checks if the c.Center is not in the diagonal quadrants of the rectangle
if (r.Min.X <= c.Center.X && c.Center.X <= r.Max.X) || (r.Min.Y <= c.Center.Y && c.Center.Y <= r.Max.Y) {
Expand Down Expand Up @@ -216,8 +216,8 @@ func (c Circle) IntersectRect(r Rect) Vec {
// the perimeters touch.
//
// This function will return a non-zero vector if:
// - The Rect contains the Circle, partially or fully
// - The Circle contains the Rect, partially of fully
// - The Rect contains the Circle, partially or fully
// - The Circle contains the Rect, partially of fully
func (r Rect) IntersectCircle(c Circle) Vec {
return c.IntersectRect(r).Scaled(-1)
}
Expand Down
2 changes: 0 additions & 2 deletions doc.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
/*
Package gfx is a convenience package for dealing with graphics in my pixel drawing experiments.
My experiments are often published under https://gist.github.com/peterhellberg
Usage examples and images can be found in the package README https://github.com/peterhellberg/gfx
*/
package gfx
2 changes: 1 addition & 1 deletion drawer.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ package gfx
//
// To create a Drawer, just assign it's Triangles and Picture fields:
//
// d := gfx.Drawer{Triangles: t, Picture: p}
// d := gfx.Drawer{Triangles: t, Picture: p}
//
// If Triangles is nil, nothing will be drawn. If Picture is nil, Triangles will be drawn without a
// Picture.
Expand Down
2 changes: 0 additions & 2 deletions hunter_lab.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ type HunterLab struct {
// Y = ( ( Hunter-L / Reference-Y ) ^ 2 ) * 100.0
// X = ( Hunter-a / var_Ka * sqrt( Y / Reference-Y ) + ( Y / Reference-Y ) ) * Reference-X
// Z = - ( Hunter-b / var_Kb * sqrt( Y / Reference-Y ) - ( Y / Reference-Y ) ) * Reference-Z
//
func (h HunterLab) XYZ(ref XYZ) XYZ {
Ka := (175.0 / 198.04) * (ref.Y + ref.X)
Kb := (70.0 / 218.11) * (ref.Y + ref.Z)
Expand All @@ -46,7 +45,6 @@ func (h HunterLab) XYZ(ref XYZ) XYZ {
// Hunter-L = 100.0 * sqrt( Y / Reference-Y )
// Hunter-a = var_Ka * ( ( ( X / Reference-X ) - ( Y / Reference-Y ) ) / sqrt( Y / Reference-Y ) )
// Hunter-b = var_Kb * ( ( ( Y / Reference-Y ) - ( Z / Reference-Z ) ) / sqrt( Y / Reference-Y ) )
//
func (xyz XYZ) HunterLab(ref XYZ) HunterLab {
Ka := (175.0 / 198.04) * (ref.Y + ref.X)
Kb := (70.0 / 218.11) * (ref.Y + ref.Z)
Expand Down
18 changes: 9 additions & 9 deletions imdraw.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ import (
// IMDraw, other than a regular BasicTarget, is used to draw shapes. To draw shapes, you first need
// to Push some points to IMDraw:
//
// imd := gfx.NewIMDraw(pic) // use nil pic if you only want to draw primitive shapes
// imd.Push(gfx.V(100, 100))
// imd.Push(gfx.V(500, 100))
// imd := gfx.NewIMDraw(pic) // use nil pic if you only want to draw primitive shapes
// imd.Push(gfx.V(100, 100))
// imd.Push(gfx.V(500, 100))
//
// Once you have Pushed some points, you can use them to draw a shape, such as a line:
//
// imd.Line(20) // draws a 20 units thick line
// imd.Line(20) // draws a 20 units thick line
//
// Set exported fields to change properties of Pushed points:
//
// imd.Color = gfx.RGB(1, 0, 0)
// imd.Push(gfx.V(200, 200))
// imd.Circle(400, 0)
// imd.Color = gfx.RGB(1, 0, 0)
// imd.Push(gfx.V(200, 200))
// imd.Circle(400, 0)
//
// Here is the list of all available point properties (need to be set before Pushing a point):
// - Color - applies to all
Expand Down Expand Up @@ -207,7 +207,7 @@ func (imd *IMDraw) Circle(radius, thickness float64) {
// continues to the high angle. If low<high, the arc will be drawn counterclockwise. Otherwise it
// will be clockwise. The angles are not normalized by any means.
//
// imd.CircleArc(40, 0, 8*math.Pi, 0)
// imd.CircleArc(40, 0, 8*math.Pi, 0)
//
// This line will fill the whole circle 4 times.
func (imd *IMDraw) CircleArc(radius, low, high, thickness float64) {
Expand All @@ -234,7 +234,7 @@ func (imd *IMDraw) Ellipse(radius Vec, thickness float64) {
// angle and continues to the high angle. If low<high, the arc will be drawn counterclockwise.
// Otherwise it will be clockwise. The angles are not normalized by any means.
//
// imd.EllipseArc(gfx.V(100, 50), 0, 8*math.Pi, 0)
// imd.EllipseArc(gfx.V(100, 50), 0, 8*math.Pi, 0)
//
// This line will fill the whole ellipse 4 times.
func (imd *IMDraw) EllipseArc(radius Vec, low, high, thickness float64) {
Expand Down
1 change: 0 additions & 1 deletion linear_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ func (ls LinearScaler) Range(r ...float64) LinearScaler {
//
// OLD PERCENT = (x - OLD MIN) / (OLD MAX - OLD MIN)
// NEW X = ((NEW MAX - NEW MIN) * OLD PERCENT) + NEW MIN
//
func (ls LinearScaler) ScaleFloat64(x float64) float64 {
op := (x - ls.d.Min()) / (ls.d.Max() - ls.d.Min())
nx := ((ls.r.Last() - ls.r.First()) * op) + ls.r.First()
Expand Down
9 changes: 5 additions & 4 deletions matrix.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,25 @@ import (
// Matrix has a handful of useful methods, each of which adds a transformation to the matrix. For
// example:
//
// gfx.IM.Moved(gfx.V(100, 200)).Rotated(gfx.ZV, math.Pi/2)
// gfx.IM.Moved(gfx.V(100, 200)).Rotated(gfx.ZV, math.Pi/2)
//
// This code creates a Matrix that first moves everything by 100 units horizontally and 200 units
// vertically and then rotates everything by 90 degrees around the origin.
//
// Layout is:
// [0] [2] [4]
// [1] [3] [5]
// 0 0 1 (implicit row)
//
// 0 0 1 (implicit row)
type Matrix [6]float64

// IM stands for identity matrix. Does nothing, no transformation.
var IM = Matrix{1, 0, 0, 1, 0, 0}

// String returns a string representation of the Matrix.
//
// m := gfx.IM
// fmt.Println(m) // Matrix(1 0 0 | 0 1 0)
// m := gfx.IM
// fmt.Println(m) // Matrix(1 0 0 | 0 1 0)
func (m Matrix) String() string {
return fmt.Sprintf(
"Matrix(%v %v %v | %v %v %v)",
Expand Down
2 changes: 0 additions & 2 deletions palettes.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,6 @@ var Palette2BitGrayScale = Palette{
//
// A calculated palette using 1 bit for each RGB value.
// It was used by a number of early computers.
//
//
var Palette3Bit = Palette{
{0x00, 0x00, 0x00, 0xFF},
{0xFF, 0x00, 0x00, 0xFF},
Expand Down
12 changes: 6 additions & 6 deletions rect.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ func (r Rect) CenterOrigin(v Vec, z float64) Vec3 {

// String returns the string representation of the Rect.
//
// r := gfx.R(100, 50, 200, 300)
// r.String() // returns "gfx.R(100, 50, 200, 300)"
// fmt.Println(r) // gfx.R(100, 50, 200, 300)
// r := gfx.R(100, 50, 200, 300)
// r.String() // returns "gfx.R(100, 50, 200, 300)"
// fmt.Println(r) // gfx.R(100, 50, 200, 300)
func (r Rect) String() string {
return fmt.Sprintf("gfx.R(%v, %v, %v, %v)", r.Min.X, r.Min.Y, r.Max.X, r.Max.Y)
}
Expand Down Expand Up @@ -115,9 +115,9 @@ func (r Rect) Moved(delta Vec) Rect {
// Resized returns the Rect resized to the given size while keeping the position of the given
// anchor.
//
// r.Resized(r.Min, size) // resizes while keeping the position of the lower-left corner
// r.Resized(r.Max, size) // same with the top-right corner
// r.Resized(r.Center(), size) // resizes around the center
// r.Resized(r.Min, size) // resizes while keeping the position of the lower-left corner
// r.Resized(r.Max, size) // same with the top-right corner
// r.Resized(r.Center(), size) // resizes around the center
//
// This function does not make sense for resizing a rectangle of zero area and will panic. Use
// ResizedMin in the case of zero area.
Expand Down
3 changes: 1 addition & 2 deletions simplex.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@ import (
//
// This could be speeded up even further, but it's useful as it is.
//
// Version 2012-03-09
// # Version 2012-03-09
//
// This code was placed in the public domain by its original author,
// Stefan Gustavson. You may use it as you see fit, but
// attribution is appreciated.
//
type SimplexNoise struct {
perm []uint8
permMod12 []uint8
Expand Down
5 changes: 2 additions & 3 deletions vec3.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ import (
//
// Create vectors with the V3 constructor:
//
// u := gfx.V3(1, 2, 3)
// v := gfx.V3(8, -3, 4)
//
// u := gfx.V3(1, 2, 3)
// v := gfx.V3(8, -3, 4)
type Vec3 struct {
X, Y, Z float64
}
Expand Down
4 changes: 2 additions & 2 deletions xyz.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (

// ColorToXYZ converts a color into XYZ.
//
//R, G and B (Standard RGB) input range = 0 ÷ 255
//X, Y and Z output refer to a D65/2° standard illuminant.
// R, G and B (Standard RGB) input range = 0 ÷ 255
// X, Y and Z output refer to a D65/2° standard illuminant.
func ColorToXYZ(c color.Color) XYZ {
r, g, b := floatRGB(c)

Expand Down

0 comments on commit 7699f00

Please sign in to comment.