42 lines
901 B
Go
42 lines
901 B
Go
package model
|
|
|
|
import (
|
|
"image"
|
|
"image/color"
|
|
"image/draw"
|
|
)
|
|
|
|
type Line struct {
|
|
Start image.Point
|
|
End image.Point
|
|
Width int
|
|
Color color.Color
|
|
}
|
|
|
|
func (l *Line) ToSprite() *Sprite {
|
|
img := image.NewRGBA(image.Rect(0, 0, l.End.X-l.Start.X, l.End.Y-l.Start.Y))
|
|
draw.Draw(img, image.Rect(0, 0, l.End.X-l.Start.X, l.End.Y-l.Start.Y), &image.Uniform{l.Color}, image.Point{}, draw.Src)
|
|
return &Sprite{
|
|
Position: l.Start,
|
|
Image: img,
|
|
}
|
|
}
|
|
|
|
type ProjectMatrix struct {
|
|
Matrix [2][2]float64
|
|
}
|
|
|
|
func (p *ProjectMatrix) ProjectPoint(point image.Point) image.Point {
|
|
return image.Point{
|
|
X: int(p.Matrix[0][0]*float64(point.X) + p.Matrix[0][1]*float64(point.Y)),
|
|
Y: int(p.Matrix[1][0]*float64(point.X) + p.Matrix[1][1]*float64(point.Y)),
|
|
}
|
|
}
|
|
|
|
func (p *ProjectMatrix) ProjectLine(line Line) Line {
|
|
return Line{
|
|
Start: p.ProjectPoint(line.Start),
|
|
End: p.ProjectPoint(line.End),
|
|
}
|
|
}
|