mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-26 03:38:55 +01:00
Rename ColorGeometry -> ColorM, GeometryMatrix -> GeoM (#27)
This commit is contained in:
parent
951eac3452
commit
ffab448d40
@ -18,24 +18,24 @@ import (
|
|||||||
"math"
|
"math"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ColorMatrixDim is a dimension of a ColorMatrix.
|
// ColorMDim is a dimension of a ColorM.
|
||||||
const ColorMatrixDim = 5
|
const ColorMDim = 5
|
||||||
|
|
||||||
// A ColorMatrix represents a matrix to transform coloring when rendering an image.
|
// A ColorM represents a matrix to transform coloring when rendering an image.
|
||||||
//
|
//
|
||||||
// A ColorMatrix is applied to the source alpha color
|
// A ColorM is applied to the source alpha color
|
||||||
// while an Image's pixels' format is alpha premultiplied.
|
// while an Image's pixels' format is alpha premultiplied.
|
||||||
// Before applying a matrix, a color is un-multiplied, and after applying the matrix,
|
// Before applying a matrix, a color is un-multiplied, and after applying the matrix,
|
||||||
// the color is multiplied again.
|
// the color is multiplied again.
|
||||||
//
|
//
|
||||||
// The initial value is identity.
|
// The initial value is identity.
|
||||||
type ColorMatrix struct {
|
type ColorM struct {
|
||||||
initialized bool
|
initialized bool
|
||||||
es [ColorMatrixDim - 1][ColorMatrixDim]float64
|
es [ColorMDim - 1][ColorMDim]float64
|
||||||
}
|
}
|
||||||
|
|
||||||
func colorMatrixEsI() [ColorMatrixDim - 1][ColorMatrixDim]float64 {
|
func colorMatrixEsI() [ColorMDim - 1][ColorMDim]float64 {
|
||||||
return [ColorMatrixDim - 1][ColorMatrixDim]float64{
|
return [ColorMDim - 1][ColorMDim]float64{
|
||||||
{1, 0, 0, 0, 0},
|
{1, 0, 0, 0, 0},
|
||||||
{0, 1, 0, 0, 0},
|
{0, 1, 0, 0, 0},
|
||||||
{0, 0, 1, 0, 0},
|
{0, 0, 1, 0, 0},
|
||||||
@ -43,12 +43,12 @@ func colorMatrixEsI() [ColorMatrixDim - 1][ColorMatrixDim]float64 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c ColorMatrix) dim() int {
|
func (c ColorM) dim() int {
|
||||||
return ColorMatrixDim
|
return ColorMDim
|
||||||
}
|
}
|
||||||
|
|
||||||
// Element returns a value of a matrix at (i, j).
|
// Element returns a value of a matrix at (i, j).
|
||||||
func (c ColorMatrix) Element(i, j int) float64 {
|
func (c ColorM) Element(i, j int) float64 {
|
||||||
if !c.initialized {
|
if !c.initialized {
|
||||||
if i == j {
|
if i == j {
|
||||||
return 1
|
return 1
|
||||||
@ -59,29 +59,29 @@ func (c ColorMatrix) Element(i, j int) float64 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Concat multiplies a color matrix with the other color matrix.
|
// Concat multiplies a color matrix with the other color matrix.
|
||||||
func (c *ColorMatrix) Concat(other ColorMatrix) {
|
func (c *ColorM) Concat(other ColorM) {
|
||||||
if !c.initialized {
|
if !c.initialized {
|
||||||
c.es = colorMatrixEsI()
|
c.es = colorMatrixEsI()
|
||||||
c.initialized = true
|
c.initialized = true
|
||||||
}
|
}
|
||||||
result := ColorMatrix{}
|
result := ColorM{}
|
||||||
mul(&other, c, &result)
|
mul(&other, c, &result)
|
||||||
*c = result
|
*c = result
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add adds a color matrix with the other color matrix.
|
// Add adds a color matrix with the other color matrix.
|
||||||
func (c *ColorMatrix) Add(other ColorMatrix) {
|
func (c *ColorM) Add(other ColorM) {
|
||||||
if !c.initialized {
|
if !c.initialized {
|
||||||
c.es = colorMatrixEsI()
|
c.es = colorMatrixEsI()
|
||||||
c.initialized = true
|
c.initialized = true
|
||||||
}
|
}
|
||||||
result := ColorMatrix{}
|
result := ColorM{}
|
||||||
add(&other, c, &result)
|
add(&other, c, &result)
|
||||||
*c = result
|
*c = result
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetElement sets an element at (i, j).
|
// SetElement sets an element at (i, j).
|
||||||
func (c *ColorMatrix) SetElement(i, j int, element float64) {
|
func (c *ColorM) SetElement(i, j int, element float64) {
|
||||||
if !c.initialized {
|
if !c.initialized {
|
||||||
c.es = colorMatrixEsI()
|
c.es = colorMatrixEsI()
|
||||||
c.initialized = true
|
c.initialized = true
|
||||||
@ -90,13 +90,13 @@ func (c *ColorMatrix) SetElement(i, j int, element float64) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Monochrome returns a color matrix to make an image monochrome.
|
// Monochrome returns a color matrix to make an image monochrome.
|
||||||
func Monochrome() ColorMatrix {
|
func Monochrome() ColorM {
|
||||||
const r = 6968.0 / 32768.0
|
const r = 6968.0 / 32768.0
|
||||||
const g = 23434.0 / 32768.0
|
const g = 23434.0 / 32768.0
|
||||||
const b = 2366.0 / 32768.0
|
const b = 2366.0 / 32768.0
|
||||||
return ColorMatrix{
|
return ColorM{
|
||||||
initialized: true,
|
initialized: true,
|
||||||
es: [ColorMatrixDim - 1][ColorMatrixDim]float64{
|
es: [ColorMDim - 1][ColorMDim]float64{
|
||||||
{r, g, b, 0, 0},
|
{r, g, b, 0, 0},
|
||||||
{r, g, b, 0, 0},
|
{r, g, b, 0, 0},
|
||||||
{r, g, b, 0, 0},
|
{r, g, b, 0, 0},
|
||||||
@ -106,10 +106,10 @@ func Monochrome() ColorMatrix {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ScaleColor returns a color matrix that scales a color matrix by the given color (r, g, b, a).
|
// ScaleColor returns a color matrix that scales a color matrix by the given color (r, g, b, a).
|
||||||
func ScaleColor(r, g, b, a float64) ColorMatrix {
|
func ScaleColor(r, g, b, a float64) ColorM {
|
||||||
return ColorMatrix{
|
return ColorM{
|
||||||
initialized: true,
|
initialized: true,
|
||||||
es: [ColorMatrixDim - 1][ColorMatrixDim]float64{
|
es: [ColorMDim - 1][ColorMDim]float64{
|
||||||
{r, 0, 0, 0, 0},
|
{r, 0, 0, 0, 0},
|
||||||
{0, g, 0, 0, 0},
|
{0, g, 0, 0, 0},
|
||||||
{0, 0, b, 0, 0},
|
{0, 0, b, 0, 0},
|
||||||
@ -119,10 +119,10 @@ func ScaleColor(r, g, b, a float64) ColorMatrix {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TranslateColor returns a color matrix that translates a color matrix by the given color (r, g, b, a).
|
// TranslateColor returns a color matrix that translates a color matrix by the given color (r, g, b, a).
|
||||||
func TranslateColor(r, g, b, a float64) ColorMatrix {
|
func TranslateColor(r, g, b, a float64) ColorM {
|
||||||
return ColorMatrix{
|
return ColorM{
|
||||||
initialized: true,
|
initialized: true,
|
||||||
es: [ColorMatrixDim - 1][ColorMatrixDim]float64{
|
es: [ColorMDim - 1][ColorMDim]float64{
|
||||||
{1, 0, 0, 0, r},
|
{1, 0, 0, 0, r},
|
||||||
{0, 1, 0, 0, g},
|
{0, 1, 0, 0, g},
|
||||||
{0, 0, 1, 0, b},
|
{0, 0, 1, 0, b},
|
||||||
@ -132,14 +132,14 @@ func TranslateColor(r, g, b, a float64) ColorMatrix {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// RotateHue returns a color matrix to rotate the hue
|
// RotateHue returns a color matrix to rotate the hue
|
||||||
func RotateHue(theta float64) ColorMatrix {
|
func RotateHue(theta float64) ColorM {
|
||||||
sin, cos := math.Sincos(theta)
|
sin, cos := math.Sincos(theta)
|
||||||
v1 := cos + (1.0-cos)/3.0
|
v1 := cos + (1.0-cos)/3.0
|
||||||
v2 := (1.0/3.0)*(1.0-cos) - math.Sqrt(1.0/3.0)*sin
|
v2 := (1.0/3.0)*(1.0-cos) - math.Sqrt(1.0/3.0)*sin
|
||||||
v3 := (1.0/3.0)*(1.0-cos) + math.Sqrt(1.0/3.0)*sin
|
v3 := (1.0/3.0)*(1.0-cos) + math.Sqrt(1.0/3.0)*sin
|
||||||
return ColorMatrix{
|
return ColorM{
|
||||||
initialized: true,
|
initialized: true,
|
||||||
es: [ColorMatrixDim - 1][ColorMatrixDim]float64{
|
es: [ColorMDim - 1][ColorMDim]float64{
|
||||||
{v1, v2, v3, 0, 0},
|
{v1, v2, v3, 0, 0},
|
||||||
{v3, v1, v2, 0, 0},
|
{v3, v1, v2, 0, 0},
|
||||||
{v2, v3, v1, 0, 0},
|
{v2, v3, v1, 0, 0},
|
||||||
|
@ -20,9 +20,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestColorInit(t *testing.T) {
|
func TestColorInit(t *testing.T) {
|
||||||
var m ColorMatrix
|
var m ColorM
|
||||||
for i := 0; i < ColorMatrixDim-1; i++ {
|
for i := 0; i < ColorMDim-1; i++ {
|
||||||
for j := 0; j < ColorMatrixDim; j++ {
|
for j := 0; j < ColorMDim; j++ {
|
||||||
got := m.Element(i, j)
|
got := m.Element(i, j)
|
||||||
want := 0.0
|
want := 0.0
|
||||||
if i == j {
|
if i == j {
|
||||||
@ -35,8 +35,8 @@ func TestColorInit(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
m.Add(m)
|
m.Add(m)
|
||||||
for i := 0; i < ColorMatrixDim-1; i++ {
|
for i := 0; i < ColorMDim-1; i++ {
|
||||||
for j := 0; j < ColorMatrixDim; j++ {
|
for j := 0; j < ColorMDim; j++ {
|
||||||
got := m.Element(i, j)
|
got := m.Element(i, j)
|
||||||
want := 0.0
|
want := 0.0
|
||||||
if i == j {
|
if i == j {
|
||||||
|
@ -59,9 +59,9 @@ func (d *debugPrintState) drawText(rt *ebiten.Image, str string, x, y int, c col
|
|||||||
b := float64(cc.B) / math.MaxUint16
|
b := float64(cc.B) / math.MaxUint16
|
||||||
a := float64(cc.A) / math.MaxUint16
|
a := float64(cc.A) / math.MaxUint16
|
||||||
rt.DrawImageAt(d.textImage, x+1, y, &ebiten.DrawImageOptions{
|
rt.DrawImageAt(d.textImage, x+1, y, &ebiten.DrawImageOptions{
|
||||||
DstParts: dsts,
|
DstParts: dsts,
|
||||||
SrcParts: srcs,
|
SrcParts: srcs,
|
||||||
ColorMatrix: ebiten.ScaleColor(r, g, b, a),
|
ColorM: ebiten.ScaleColor(r, g, b, a),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ func update(screen *ebiten.Image) error {
|
|||||||
}
|
}
|
||||||
for i := 0; i < 10; i++ {
|
for i := 0; i < 10; i++ {
|
||||||
op := &ebiten.DrawImageOptions{
|
op := &ebiten.DrawImageOptions{
|
||||||
ColorMatrix: ebiten.ScaleColor(1.0, 1.0, 1.0, 0.5),
|
ColorM: ebiten.ScaleColor(1.0, 1.0, 1.0, 0.5),
|
||||||
}
|
}
|
||||||
if err := tmpRenderTarget.DrawImageAt(ebitenImage, 15+int(float64(i)*diff), 20, op); err != nil {
|
if err := tmpRenderTarget.DrawImageAt(ebitenImage, 15+int(float64(i)*diff), 20, op); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -51,8 +51,8 @@ func drawText(rt *ebiten.Image, images *Images, str string, ox, oy, scale int, c
|
|||||||
locationX += charWidth
|
locationX += charWidth
|
||||||
}
|
}
|
||||||
|
|
||||||
geo := ebiten.ScaleGeometry(float64(scale), float64(scale))
|
geo := ebiten.ScaleGeo(float64(scale), float64(scale))
|
||||||
geo.Concat(ebiten.TranslateGeometry(float64(ox), float64(oy)))
|
geo.Concat(ebiten.TranslateGeo(float64(ox), float64(oy)))
|
||||||
c2 := color.NRGBA64Model.Convert(c).(color.NRGBA64)
|
c2 := color.NRGBA64Model.Convert(c).(color.NRGBA64)
|
||||||
const max = math.MaxUint16
|
const max = math.MaxUint16
|
||||||
r := float64(c2.R) / max
|
r := float64(c2.R) / max
|
||||||
@ -61,10 +61,10 @@ func drawText(rt *ebiten.Image, images *Images, str string, ox, oy, scale int, c
|
|||||||
a := float64(c2.A) / max
|
a := float64(c2.A) / max
|
||||||
clr := ebiten.ScaleColor(r, g, b, a)
|
clr := ebiten.ScaleColor(r, g, b, a)
|
||||||
rt.DrawImage(fontImageId, &ebiten.DrawImageOptions{
|
rt.DrawImage(fontImageId, &ebiten.DrawImageOptions{
|
||||||
DstParts: dsts,
|
DstParts: dsts,
|
||||||
SrcParts: srcs,
|
SrcParts: srcs,
|
||||||
GeometryMatrix: geo,
|
GeoM: geo,
|
||||||
ColorMatrix: clr,
|
ColorM: clr,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,11 +112,11 @@ func (s *GameScene) Draw(r *ebiten.Image, images *Images) {
|
|||||||
|
|
||||||
field := images.GetImage("empty")
|
field := images.GetImage("empty")
|
||||||
w, h := field.Size()
|
w, h := field.Size()
|
||||||
geo := ebiten.ScaleGeometry(float64(fieldWidth)/float64(w), float64(fieldHeight)/float64(h))
|
geo := ebiten.ScaleGeo(float64(fieldWidth)/float64(w), float64(fieldHeight)/float64(h))
|
||||||
geo.Concat(ebiten.TranslateGeometry(20, 20)) // TODO: magic number?
|
geo.Concat(ebiten.TranslateGeo(20, 20)) // TODO: magic number?
|
||||||
r.DrawImage(field, &ebiten.DrawImageOptions{
|
r.DrawImage(field, &ebiten.DrawImageOptions{
|
||||||
GeometryMatrix: geo,
|
GeoM: geo,
|
||||||
ColorMatrix: ebiten.ScaleColor(0.0, 0.0, 0.0, 0.5),
|
ColorM: ebiten.ScaleColor(0.0, 0.0, 0.0, 0.5),
|
||||||
})
|
})
|
||||||
|
|
||||||
s.field.Draw(r, images, 20, 20)
|
s.field.Draw(r, images, 20, 20)
|
||||||
|
@ -75,7 +75,7 @@ func (s *SceneManager) Draw(r *ebiten.Image, images *Images) {
|
|||||||
|
|
||||||
alpha := float64(s.transitionCount) / float64(transitionMaxCount)
|
alpha := float64(s.transitionCount) / float64(transitionMaxCount)
|
||||||
op := &ebiten.DrawImageOptions{
|
op := &ebiten.DrawImageOptions{
|
||||||
ColorMatrix: ebiten.ScaleColor(1, 1, 1, alpha),
|
ColorM: ebiten.ScaleColor(1, 1, 1, alpha),
|
||||||
}
|
}
|
||||||
r.DrawImage(to, op)
|
r.DrawImage(to, op)
|
||||||
}
|
}
|
||||||
|
@ -35,10 +35,10 @@ var (
|
|||||||
|
|
||||||
func update(screen *ebiten.Image) error {
|
func update(screen *ebiten.Image) error {
|
||||||
gophersRenderTarget.DrawImage(gophersImage, &ebiten.DrawImageOptions{
|
gophersRenderTarget.DrawImage(gophersImage, &ebiten.DrawImageOptions{
|
||||||
GeometryMatrix: ebiten.ScaleGeometry(1.0/mosaicRatio, 1.0/mosaicRatio),
|
GeoM: ebiten.ScaleGeo(1.0/mosaicRatio, 1.0/mosaicRatio),
|
||||||
})
|
})
|
||||||
screen.DrawImage(gophersRenderTarget, &ebiten.DrawImageOptions{
|
screen.DrawImage(gophersRenderTarget, &ebiten.DrawImageOptions{
|
||||||
GeometryMatrix: ebiten.ScaleGeometry(mosaicRatio, mosaicRatio),
|
GeoM: ebiten.ScaleGeo(mosaicRatio, mosaicRatio),
|
||||||
})
|
})
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,7 @@ func Update(screen *ebiten.Image) error {
|
|||||||
theta := 2.0 * math.Pi * float64(count%60) / 60.0
|
theta := 2.0 * math.Pi * float64(count%60) / 60.0
|
||||||
clr.Concat(ebiten.RotateHue(theta))
|
clr.Concat(ebiten.RotateHue(theta))
|
||||||
canvasRenderTarget.DrawImageAt(brushRenderTarget, mx, my, &ebiten.DrawImageOptions{
|
canvasRenderTarget.DrawImageAt(brushRenderTarget, mx, my, &ebiten.DrawImageOptions{
|
||||||
ColorMatrix: clr,
|
ColorM: clr,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,12 +41,12 @@ func update(screen *ebiten.Image) error {
|
|||||||
srcs = append(srcs, image.Rect(0, i, w, i+1))
|
srcs = append(srcs, image.Rect(0, i, w, i+1))
|
||||||
}
|
}
|
||||||
maxWidth := float64(w) + float64(h)*0.75
|
maxWidth := float64(w) + float64(h)*0.75
|
||||||
geo := ebiten.TranslateGeometry(-maxWidth/2, -float64(h)/2)
|
geo := ebiten.TranslateGeo(-maxWidth/2, -float64(h)/2)
|
||||||
geo.Concat(ebiten.TranslateGeometry(screenWidth/2, screenHeight/2))
|
geo.Concat(ebiten.TranslateGeo(screenWidth/2, screenHeight/2))
|
||||||
screen.DrawImage(gophersImage, &ebiten.DrawImageOptions{
|
screen.DrawImage(gophersImage, &ebiten.DrawImageOptions{
|
||||||
DstParts: dsts,
|
DstParts: dsts,
|
||||||
SrcParts: srcs,
|
SrcParts: srcs,
|
||||||
GeometryMatrix: geo,
|
GeoM: geo,
|
||||||
})
|
})
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -50,14 +50,14 @@ func update(screen *ebiten.Image) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
w, h := gophersImage.Size()
|
w, h := gophersImage.Size()
|
||||||
geo := ebiten.TranslateGeometry(-float64(w)/2, -float64(h)/2)
|
geo := ebiten.TranslateGeo(-float64(w)/2, -float64(h)/2)
|
||||||
scaleX := math.Pow(1.05, float64(horizontalCount))
|
scaleX := math.Pow(1.05, float64(horizontalCount))
|
||||||
scaleY := math.Pow(1.05, float64(verticalCount))
|
scaleY := math.Pow(1.05, float64(verticalCount))
|
||||||
geo.Concat(ebiten.ScaleGeometry(scaleX, scaleY))
|
geo.Concat(ebiten.ScaleGeo(scaleX, scaleY))
|
||||||
geo.Concat(ebiten.RotateGeometry(float64(count%720) * 2 * math.Pi / 720))
|
geo.Concat(ebiten.RotateGeo(float64(count%720) * 2 * math.Pi / 720))
|
||||||
geo.Concat(ebiten.TranslateGeometry(screenWidth/2, screenHeight/2))
|
geo.Concat(ebiten.TranslateGeo(screenWidth/2, screenHeight/2))
|
||||||
if err := screen.DrawImage(gophersImage, &ebiten.DrawImageOptions{
|
if err := screen.DrawImage(gophersImage, &ebiten.DrawImageOptions{
|
||||||
GeometryMatrix: geo,
|
GeoM: geo,
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -18,30 +18,30 @@ import (
|
|||||||
"math"
|
"math"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GeometryMatrixDim is a dimension of a GeometryMatrix.
|
// GeoMDim is a dimension of a GeoM.
|
||||||
const GeometryMatrixDim = 3
|
const GeoMDim = 3
|
||||||
|
|
||||||
// A GeometryMatrix represents a matrix to transform geometry when rendering an image.
|
// A GeoM represents a matrix to transform geometry when rendering an image.
|
||||||
//
|
//
|
||||||
// The initial value is identity.
|
// The initial value is identity.
|
||||||
type GeometryMatrix struct {
|
type GeoM struct {
|
||||||
initialized bool
|
initialized bool
|
||||||
es [GeometryMatrixDim - 1][GeometryMatrixDim]float64
|
es [GeoMDim - 1][GeoMDim]float64
|
||||||
}
|
}
|
||||||
|
|
||||||
func geometryMatrixEsI() [GeometryMatrixDim - 1][GeometryMatrixDim]float64 {
|
func geometryMatrixEsI() [GeoMDim - 1][GeoMDim]float64 {
|
||||||
return [GeometryMatrixDim - 1][GeometryMatrixDim]float64{
|
return [GeoMDim - 1][GeoMDim]float64{
|
||||||
{1, 0, 0},
|
{1, 0, 0},
|
||||||
{0, 1, 0},
|
{0, 1, 0},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g GeometryMatrix) dim() int {
|
func (g GeoM) dim() int {
|
||||||
return GeometryMatrixDim
|
return GeoMDim
|
||||||
}
|
}
|
||||||
|
|
||||||
// Element returns a value of a matrix at (i, j).
|
// Element returns a value of a matrix at (i, j).
|
||||||
func (g GeometryMatrix) Element(i, j int) float64 {
|
func (g GeoM) Element(i, j int) float64 {
|
||||||
if !g.initialized {
|
if !g.initialized {
|
||||||
if i == j {
|
if i == j {
|
||||||
return 1
|
return 1
|
||||||
@ -52,29 +52,29 @@ func (g GeometryMatrix) Element(i, j int) float64 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Concat multiplies a geometry matrix with the other geometry matrix.
|
// Concat multiplies a geometry matrix with the other geometry matrix.
|
||||||
func (g *GeometryMatrix) Concat(other GeometryMatrix) {
|
func (g *GeoM) Concat(other GeoM) {
|
||||||
if !g.initialized {
|
if !g.initialized {
|
||||||
g.es = geometryMatrixEsI()
|
g.es = geometryMatrixEsI()
|
||||||
g.initialized = true
|
g.initialized = true
|
||||||
}
|
}
|
||||||
result := GeometryMatrix{}
|
result := GeoM{}
|
||||||
mul(&other, g, &result)
|
mul(&other, g, &result)
|
||||||
*g = result
|
*g = result
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add adds a geometry matrix with the other geometry matrix.
|
// Add adds a geometry matrix with the other geometry matrix.
|
||||||
func (g *GeometryMatrix) Add(other GeometryMatrix) {
|
func (g *GeoM) Add(other GeoM) {
|
||||||
if !g.initialized {
|
if !g.initialized {
|
||||||
g.es = geometryMatrixEsI()
|
g.es = geometryMatrixEsI()
|
||||||
g.initialized = true
|
g.initialized = true
|
||||||
}
|
}
|
||||||
result := GeometryMatrix{}
|
result := GeoM{}
|
||||||
add(&other, g, &result)
|
add(&other, g, &result)
|
||||||
*g = result
|
*g = result
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetElement sets an element at (i, j).
|
// SetElement sets an element at (i, j).
|
||||||
func (g *GeometryMatrix) SetElement(i, j int, element float64) {
|
func (g *GeoM) SetElement(i, j int, element float64) {
|
||||||
if !g.initialized {
|
if !g.initialized {
|
||||||
g.es = geometryMatrixEsI()
|
g.es = geometryMatrixEsI()
|
||||||
g.initialized = true
|
g.initialized = true
|
||||||
@ -82,9 +82,9 @@ func (g *GeometryMatrix) SetElement(i, j int, element float64) {
|
|||||||
g.es[i][j] = element
|
g.es[i][j] = element
|
||||||
}
|
}
|
||||||
|
|
||||||
// ScaleGeometry returns a matrix that scales a geometry matrix by (x, y).
|
// ScaleGeo returns a matrix that scales a geometry matrix by (x, y).
|
||||||
func ScaleGeometry(x, y float64) GeometryMatrix {
|
func ScaleGeo(x, y float64) GeoM {
|
||||||
return GeometryMatrix{
|
return GeoM{
|
||||||
initialized: true,
|
initialized: true,
|
||||||
es: [2][3]float64{
|
es: [2][3]float64{
|
||||||
{x, 0, 0},
|
{x, 0, 0},
|
||||||
@ -93,9 +93,9 @@ func ScaleGeometry(x, y float64) GeometryMatrix {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TranslateGeometry returns a matrix taht translates a geometry matrix by (tx, ty).
|
// TranslateGeo returns a matrix taht translates a geometry matrix by (tx, ty).
|
||||||
func TranslateGeometry(tx, ty float64) GeometryMatrix {
|
func TranslateGeo(tx, ty float64) GeoM {
|
||||||
return GeometryMatrix{
|
return GeoM{
|
||||||
initialized: true,
|
initialized: true,
|
||||||
es: [2][3]float64{
|
es: [2][3]float64{
|
||||||
{1, 0, tx},
|
{1, 0, tx},
|
||||||
@ -104,10 +104,10 @@ func TranslateGeometry(tx, ty float64) GeometryMatrix {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// RotateGeometry returns a matrix that rotates a geometry matrix by theta.
|
// RotateGeo returns a matrix that rotates a geometry matrix by theta.
|
||||||
func RotateGeometry(theta float64) GeometryMatrix {
|
func RotateGeo(theta float64) GeoM {
|
||||||
sin, cos := math.Sincos(theta)
|
sin, cos := math.Sincos(theta)
|
||||||
return GeometryMatrix{
|
return GeoM{
|
||||||
initialized: true,
|
initialized: true,
|
||||||
es: [2][3]float64{
|
es: [2][3]float64{
|
||||||
{cos, -sin, 0},
|
{cos, -sin, 0},
|
||||||
|
@ -20,9 +20,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestGeometryInit(t *testing.T) {
|
func TestGeometryInit(t *testing.T) {
|
||||||
var m GeometryMatrix
|
var m GeoM
|
||||||
for i := 0; i < GeometryMatrixDim-1; i++ {
|
for i := 0; i < GeoMDim-1; i++ {
|
||||||
for j := 0; j < GeometryMatrixDim; j++ {
|
for j := 0; j < GeoMDim; j++ {
|
||||||
got := m.Element(i, j)
|
got := m.Element(i, j)
|
||||||
want := 0.0
|
want := 0.0
|
||||||
if i == j {
|
if i == j {
|
||||||
@ -35,8 +35,8 @@ func TestGeometryInit(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
m.Add(m)
|
m.Add(m)
|
||||||
for i := 0; i < GeometryMatrixDim-1; i++ {
|
for i := 0; i < GeoMDim-1; i++ {
|
||||||
for j := 0; j < GeometryMatrixDim; j++ {
|
for j := 0; j < GeoMDim; j++ {
|
||||||
got := m.Element(i, j)
|
got := m.Element(i, j)
|
||||||
want := 0.0
|
want := 0.0
|
||||||
if i == j {
|
if i == j {
|
||||||
@ -50,7 +50,7 @@ func TestGeometryInit(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestGeometryAssign(t *testing.T) {
|
func TestGeometryAssign(t *testing.T) {
|
||||||
m := ScaleGeometry(1, 1) // Create elements explicitly
|
m := ScaleGeo(1, 1) // Create elements explicitly
|
||||||
m2 := m
|
m2 := m
|
||||||
m.SetElement(0, 0, 0)
|
m.SetElement(0, 0, 0)
|
||||||
got := m2.Element(0, 0)
|
got := m2.Element(0, 0)
|
||||||
@ -61,8 +61,8 @@ func TestGeometryAssign(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestGeometryConcat(t *testing.T) {
|
func TestGeometryConcat(t *testing.T) {
|
||||||
matrix1 := ScaleGeometry(2, 2)
|
matrix1 := ScaleGeo(2, 2)
|
||||||
matrix2 := TranslateGeometry(1, 1)
|
matrix2 := TranslateGeo(1, 1)
|
||||||
|
|
||||||
matrix3 := matrix1
|
matrix3 := matrix1
|
||||||
matrix3.Concat(matrix2)
|
matrix3.Concat(matrix2)
|
||||||
|
@ -67,7 +67,7 @@ func (c *graphicsContext) postUpdate() error {
|
|||||||
|
|
||||||
scale := float64(c.screenScale)
|
scale := float64(c.screenScale)
|
||||||
options := &DrawImageOptions{
|
options := &DrawImageOptions{
|
||||||
GeometryMatrix: ScaleGeometry(scale, scale),
|
GeoM: ScaleGeo(scale, scale),
|
||||||
}
|
}
|
||||||
if err := c.defaultR.drawImage(c.screen, options); err != nil {
|
if err := c.defaultR.drawImage(c.screen, options); err != nil {
|
||||||
return err
|
return err
|
||||||
|
14
image.go
14
image.go
@ -67,8 +67,8 @@ func (i *innerImage) drawImage(img *innerImage, options *DrawImageOptions) error
|
|||||||
image.Rect(0, 0, w, h),
|
image.Rect(0, 0, w, h),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
geo := options.GeometryMatrix
|
geo := options.GeoM
|
||||||
clr := options.ColorMatrix
|
clr := options.ColorM
|
||||||
|
|
||||||
if err := i.framebuffer.SetAsViewport(); err != nil {
|
if err := i.framebuffer.SetAsViewport(); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -168,7 +168,7 @@ func (i *Image) DrawImageAt(image *Image, x, y int, options *DrawImageOptions) (
|
|||||||
if options == nil {
|
if options == nil {
|
||||||
options = &DrawImageOptions{}
|
options = &DrawImageOptions{}
|
||||||
}
|
}
|
||||||
options.GeometryMatrix.Concat(TranslateGeometry(float64(x), float64(y)))
|
options.GeoM.Concat(TranslateGeo(float64(x), float64(y)))
|
||||||
return i.drawImage(image.inner, options)
|
return i.drawImage(image.inner, options)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -213,8 +213,8 @@ func (i *Image) At(x, y int) color.Color {
|
|||||||
|
|
||||||
// A DrawImageOptions presents options to render an image on an image.
|
// A DrawImageOptions presents options to render an image on an image.
|
||||||
type DrawImageOptions struct {
|
type DrawImageOptions struct {
|
||||||
DstParts []image.Rectangle
|
DstParts []image.Rectangle
|
||||||
SrcParts []image.Rectangle
|
SrcParts []image.Rectangle
|
||||||
GeometryMatrix GeometryMatrix
|
GeoM GeoM
|
||||||
ColorMatrix ColorMatrix
|
ColorM ColorM
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user