minor, mostly stylistic, changes
This commit is contained in:
parent
2e4c6018c9
commit
6b9ea45e96
10
geometry.go
10
geometry.go
|
@ -263,7 +263,7 @@ func (r Rect) Union(s Rect) Rect {
|
||||||
// Layout is:
|
// Layout is:
|
||||||
// [0] [2] [4]
|
// [0] [2] [4]
|
||||||
// [1] [3] [5]
|
// [1] [3] [5]
|
||||||
// 0 0 1 [implicit row]
|
// 0 0 1 (implicit row)
|
||||||
type Matrix [6]float64
|
type Matrix [6]float64
|
||||||
|
|
||||||
// IM stands for identity matrix. Does nothing, no transformation.
|
// IM stands for identity matrix. Does nothing, no transformation.
|
||||||
|
@ -332,11 +332,9 @@ func (m Matrix) Project(u Vec) Vec {
|
||||||
|
|
||||||
// Unproject does the inverse operation to Project.
|
// Unproject does the inverse operation to Project.
|
||||||
//
|
//
|
||||||
// It turns out that multiplying a vector by the inverse matrix of m
|
// It turns out that multiplying a vector by the inverse matrix of m can be nearly-accomplished by
|
||||||
// can be nearly-accomplished by subtracting the translate part of the
|
// subtracting the translate part of the matrix and multplying by the inverse of the top-left 2x2
|
||||||
// matrix and multplying by the inverse of the top-left 2x2 matrix,
|
// matrix, and the inverse of a 2x2 matrix is simple enough to just be inlined in the computation.
|
||||||
// and the inverse of a 2x2 matrix is simple enough to just be
|
|
||||||
// inlined in the computation.
|
|
||||||
//
|
//
|
||||||
// Time complexity is O(1).
|
// Time complexity is O(1).
|
||||||
func (m Matrix) Unproject(u Vec) Vec {
|
func (m Matrix) Unproject(u Vec) Vec {
|
||||||
|
|
|
@ -260,8 +260,8 @@ func (imd *IMDraw) getAndClearPoints() []point {
|
||||||
// use one of the existing pools so we don't reallocate as often
|
// use one of the existing pools so we don't reallocate as often
|
||||||
if len(imd.pool) > 0 {
|
if len(imd.pool) > 0 {
|
||||||
pos := len(imd.pool) - 1
|
pos := len(imd.pool) - 1
|
||||||
imd.points = imd.pool[pos]
|
imd.points = imd.pool[pos][:0]
|
||||||
imd.pool = imd.pool[0:pos]
|
imd.pool = imd.pool[:pos]
|
||||||
} else {
|
} else {
|
||||||
imd.points = nil
|
imd.points = nil
|
||||||
}
|
}
|
||||||
|
@ -306,7 +306,7 @@ func (imd *IMDraw) fillRectangle() {
|
||||||
in: (a.in + b.in) / 2,
|
in: (a.in + b.in) / 2,
|
||||||
}
|
}
|
||||||
|
|
||||||
for k, p := range []point{a, b, c, a, b, d} {
|
for k, p := range [...]point{a, b, c, a, b, d} {
|
||||||
(*imd.tri)[j+k].Position = p.pos
|
(*imd.tri)[j+k].Position = p.pos
|
||||||
(*imd.tri)[j+k].Color = p.col
|
(*imd.tri)[j+k].Color = p.col
|
||||||
(*imd.tri)[j+k].Picture = p.pic
|
(*imd.tri)[j+k].Picture = p.pic
|
||||||
|
@ -316,6 +316,7 @@ func (imd *IMDraw) fillRectangle() {
|
||||||
|
|
||||||
imd.applyMatrixAndMask(off)
|
imd.applyMatrixAndMask(off)
|
||||||
imd.batch.Dirty()
|
imd.batch.Dirty()
|
||||||
|
|
||||||
imd.restorePoints(points)
|
imd.restorePoints(points)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -339,6 +340,7 @@ func (imd *IMDraw) outlineRectangle(thickness float64) {
|
||||||
imd.pushPt(pixel.V(b.pos.X, a.pos.Y), mid)
|
imd.pushPt(pixel.V(b.pos.X, a.pos.Y), mid)
|
||||||
imd.polyline(thickness, true)
|
imd.polyline(thickness, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
imd.restorePoints(points)
|
imd.restorePoints(points)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -354,7 +356,7 @@ func (imd *IMDraw) fillPolygon() {
|
||||||
imd.tri.SetLen(imd.tri.Len() + 3*(len(points)-2))
|
imd.tri.SetLen(imd.tri.Len() + 3*(len(points)-2))
|
||||||
|
|
||||||
for i, j := 1, off; i+1 < len(points); i, j = i+1, j+3 {
|
for i, j := 1, off; i+1 < len(points); i, j = i+1, j+3 {
|
||||||
for k, p := range []int{0, i, i + 1} {
|
for k, p := range [...]int{0, i, i + 1} {
|
||||||
tri := &(*imd.tri)[j+k]
|
tri := &(*imd.tri)[j+k]
|
||||||
tri.Position = points[p].pos
|
tri.Position = points[p].pos
|
||||||
tri.Color = points[p].col
|
tri.Color = points[p].col
|
||||||
|
@ -365,6 +367,7 @@ func (imd *IMDraw) fillPolygon() {
|
||||||
|
|
||||||
imd.applyMatrixAndMask(off)
|
imd.applyMatrixAndMask(off)
|
||||||
imd.batch.Dirty()
|
imd.batch.Dirty()
|
||||||
|
|
||||||
imd.restorePoints(points)
|
imd.restorePoints(points)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -407,6 +410,7 @@ func (imd *IMDraw) fillEllipseArc(radius pixel.Vec, low, high float64) {
|
||||||
imd.applyMatrixAndMask(off)
|
imd.applyMatrixAndMask(off)
|
||||||
imd.batch.Dirty()
|
imd.batch.Dirty()
|
||||||
}
|
}
|
||||||
|
|
||||||
imd.restorePoints(points)
|
imd.restorePoints(points)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -506,6 +510,7 @@ func (imd *IMDraw) outlineEllipseArc(radius pixel.Vec, low, high, thickness floa
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
imd.restorePoints(points)
|
imd.restorePoints(points)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -617,5 +622,6 @@ func (imd *IMDraw) polyline(thickness float64, closed bool) {
|
||||||
imd.fillEllipseArc(pixel.V(thickness/2, thickness/2), normal.Angle(), normal.Angle()-math.Pi)
|
imd.fillEllipseArc(pixel.V(thickness/2, thickness/2), normal.Angle(), normal.Angle()-math.Pi)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
imd.restorePoints(points)
|
imd.restorePoints(points)
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,15 +90,13 @@ func (c *Canvas) MakePicture(p pixel.Picture) pixel.TargetPicture {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetMatrix sets a Matrix that every point will be projected by.
|
// SetMatrix sets a Matrix that every point will be projected by.
|
||||||
// pixel.Matrix is 3x2 with an implicit 0, 0, 1 row after it. So
|
|
||||||
// [0] [2] [4] [0] [3] [6]
|
|
||||||
// [1] [3] [5] => [1] [4] [7]
|
|
||||||
// 0 0 1 0 0 1
|
|
||||||
// since all matrix ops are affine, the last row never changes,
|
|
||||||
// and we don't need to copy it
|
|
||||||
//
|
|
||||||
func (c *Canvas) SetMatrix(m pixel.Matrix) {
|
func (c *Canvas) SetMatrix(m pixel.Matrix) {
|
||||||
for i, j := range [6]int{ 0, 1, 3, 4, 6, 7} {
|
// pixel.Matrix is 3x2 with an implicit 0, 0, 1 row after it. So
|
||||||
|
// [0] [2] [4] [0] [3] [6]
|
||||||
|
// [1] [3] [5] => [1] [4] [7]
|
||||||
|
// 0 0 1 0 0 1
|
||||||
|
// since all matrix ops are affine, the last row never changes, and we don't need to copy it
|
||||||
|
for i, j := range [...]int{0, 1, 3, 4, 6, 7} {
|
||||||
c.mat[j] = float32(m[i])
|
c.mat[j] = float32(m[i])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue