Compare commits

..

2 Commits

Author SHA1 Message Date
cc2addf7e2 Added RectRel{,F,F32} methods.
- Instead of a second coordinate (x,y) you can provide the width & height of the rectangle.
2020-05-15 10:24:09 +02:00
cc72cd1171 Added comment with the range of the noise functions. 2020-05-15 10:20:54 +02:00
4 changed files with 17 additions and 0 deletions

View File

@ -30,6 +30,7 @@ func perlinLerp(t, a, b float64) float64 { return a + t*(b-a) }
func perlinAt2D(q [2]float64, rx, ry float64) float64 { return rx*q[0] + ry*q[1] } func perlinAt2D(q [2]float64, rx, ry float64) float64 { return rx*q[0] + ry*q[1] }
// noise2d generates 2-dimensional noise. The result is in range [-sqrt(1/4),sqrt(1/4)].
func (p *Perlin) noise1d(x float64) float64 { func (p *Perlin) noise1d(x float64) float64 {
tx := x + perlinN tx := x + perlinN
bx0 := int(tx) & perlinBM bx0 := int(tx) & perlinBM
@ -44,6 +45,7 @@ func (p *Perlin) noise1d(x float64) float64 {
return perlinLerp(sx, u, v) return perlinLerp(sx, u, v)
} }
// noise2d generates 2-dimensional noise. The result is in range [-sqrt(1/2),sqrt(1/2)].
func (p *Perlin) noise2d(x, y float64) float64 { func (p *Perlin) noise2d(x, y float64) float64 {
tx := x + perlinN tx := x + perlinN
bx0 := int(tx) & perlinBM bx0 := int(tx) & perlinBM

View File

@ -16,6 +16,11 @@ func Rect(x0, y0, x1, y1 int) Rectangle {
return Rectangle{Point{x0, y0}, Point{x1, y1}} return Rectangle{Point{x0, y0}, Point{x1, y1}}
} }
// RectRel is a shorthand function to create a rectangle specifying its width and height instead of a second coordinate.
func RectRel(x, y, w, h int) Rectangle {
return Rectangle{Point{x, y}, Point{x + w, y + h}}
}
// Add translates rectangle r by point p. // Add translates rectangle r by point p.
func (r Rectangle) Add(p Point) Rectangle { func (r Rectangle) Add(p Point) Rectangle {
return Rectangle{ return Rectangle{

View File

@ -17,6 +17,11 @@ func RectF(x0, y0, x1, y1 float64) RectangleF {
return RectangleF{PtF(x0, y0), PtF(x1, y1)} return RectangleF{PtF(x0, y0), PtF(x1, y1)}
} }
// RectRelF is a shorthand function to create a rectangle specifying its width and height instead of a second coordinate.
func RectRelF(x, y, w, h float64) RectangleF {
return RectangleF{PointF{x, y}, PointF{x + w, y + h}}
}
// Add translates rectangle r by point p. // Add translates rectangle r by point p.
func (r RectangleF) Add(p PointF) RectangleF { func (r RectangleF) Add(p PointF) RectangleF {
return RectangleF{ return RectangleF{

View File

@ -17,6 +17,11 @@ func RectF32(x0, y0, x1, y1 float32) RectangleF32 {
return RectangleF32{PtF32(x0, y0), PtF32(x1, y1)} return RectangleF32{PtF32(x0, y0), PtF32(x1, y1)}
} }
// RectRelF32 is a shorthand function to create a rectangle specifying its width and height instead of a second coordinate.
func RectRelF32(x, y, w, h float32) RectangleF32 {
return RectangleF32{PointF32{x, y}, PointF32{x + w, y + h}}
}
// Add translates rectangle r by point p. // Add translates rectangle r by point p.
func (r RectangleF32) Add(p PointF32) RectangleF32 { func (r RectangleF32) Add(p PointF32) RectangleF32 {
return RectangleF32{ return RectangleF32{