some improvments
This commit is contained in:
@@ -89,9 +89,9 @@ func NewCubicBezierPath() CubicBezierPath {
|
||||
return bpath
|
||||
}
|
||||
|
||||
func (this CubicBezierPath) AppendCurve(curve CubicBezierCurve) CubicBezierPath {
|
||||
this.Curves = append(this.Curves, curve)
|
||||
return this
|
||||
func (c CubicBezierPath) AppendCurve(curve CubicBezierCurve) CubicBezierPath {
|
||||
c.Curves = append(c.Curves, curve)
|
||||
return c
|
||||
}
|
||||
|
||||
func (bpath CubicBezierPath) Copy() CubicBezierPath {
|
||||
|
||||
@@ -11,36 +11,36 @@ func NewPath() Path {
|
||||
return path
|
||||
}
|
||||
|
||||
func (this Path) AppendPoint(point Point) Path {
|
||||
this.Points = append(this.Points, point)
|
||||
return this
|
||||
func (p Path) AppendPoint(point Point) Path {
|
||||
p.Points = append(p.Points, point)
|
||||
return p
|
||||
}
|
||||
|
||||
func (this Path) RemovePoint(number int) Path {
|
||||
if number < 1 || number > len(this.Points) {
|
||||
return this
|
||||
func (p Path) RemovePoint(number int) Path {
|
||||
if number < 1 || number > len(p.Points) {
|
||||
return p
|
||||
}
|
||||
|
||||
idx := number - 1
|
||||
this.Points = append(this.Points[:idx], this.Points[idx+1:]...)
|
||||
return this
|
||||
p.Points = append(p.Points[:idx], p.Points[idx+1:]...)
|
||||
return p
|
||||
}
|
||||
|
||||
func (this Path) Length() int {
|
||||
return len(this.Points)
|
||||
func (p Path) Length() int {
|
||||
return len(p.Points)
|
||||
}
|
||||
|
||||
func (this Path) GetPointNumber(number int) Point {
|
||||
if number < 1 || number > len(this.Points) {
|
||||
func (p Path) GetPointNumber(number int) Point {
|
||||
if number < 1 || number > len(p.Points) {
|
||||
return Point{}
|
||||
}
|
||||
return this.Points[number-1]
|
||||
return p.Points[number-1]
|
||||
}
|
||||
|
||||
func (path Path) Copy() Path {
|
||||
func (p Path) Copy() Path {
|
||||
pathcopy := Path{}
|
||||
pathcopy.Points = []Point{}
|
||||
for _, p := range path.Points {
|
||||
for _, p := range p.Points {
|
||||
pathcopy.Points = append(pathcopy.Points, p)
|
||||
}
|
||||
return pathcopy
|
||||
|
||||
@@ -21,10 +21,10 @@ func (p Point) Add(dx, dy float64) Point {
|
||||
}
|
||||
|
||||
// Add vector to a point.
|
||||
func (this Point) AddVector(v Vector) Point {
|
||||
this.X += v.Dx
|
||||
this.Y += v.Dy
|
||||
return this
|
||||
func (p Point) AddVector(v Vector) Point {
|
||||
p.X += v.Dx
|
||||
p.Y += v.Dy
|
||||
return p
|
||||
}
|
||||
|
||||
func (p Point) String() string {
|
||||
|
||||
@@ -43,13 +43,13 @@ func (v Vector) Rotate(phi float64) Vector {
|
||||
}
|
||||
|
||||
// Change the sign of the vector: -vector.
|
||||
func (this Vector) Flip() Vector {
|
||||
mag := this.Magnitude()
|
||||
theta := this.GetPolarAngle()
|
||||
func (v Vector) Flip() Vector {
|
||||
mag := v.Magnitude()
|
||||
theta := v.GetPolarAngle()
|
||||
|
||||
this.Dx = mag * math.Cos(theta+math.Pi)
|
||||
this.Dy = mag * math.Sin(theta+math.Pi)
|
||||
return this
|
||||
v.Dx = mag * math.Cos(theta+math.Pi)
|
||||
v.Dy = mag * math.Sin(theta+math.Pi)
|
||||
return v
|
||||
}
|
||||
|
||||
func (v Vector) FlipY() Vector {
|
||||
@@ -62,19 +62,19 @@ func (v Vector) FlipX() Vector {
|
||||
return v
|
||||
}
|
||||
|
||||
func (this Vector) Scale(factor float64) Vector {
|
||||
mag := this.Magnitude()
|
||||
theta := this.GetPolarAngle()
|
||||
func (v Vector) Scale(factor float64) Vector {
|
||||
mag := v.Magnitude()
|
||||
theta := v.GetPolarAngle()
|
||||
|
||||
this.Dx = factor * mag * math.Cos(theta)
|
||||
this.Dy = factor * mag * math.Sin(theta)
|
||||
return this
|
||||
v.Dx = factor * mag * math.Cos(theta)
|
||||
v.Dy = factor * mag * math.Sin(theta)
|
||||
return v
|
||||
}
|
||||
|
||||
func (this Vector) Magnitude() float64 {
|
||||
return math.Sqrt(math.Pow(this.Dx, 2.0) + math.Pow(this.Dy, 2.0))
|
||||
func (v Vector) Magnitude() float64 {
|
||||
return math.Sqrt(math.Pow(v.Dx, 2.0) + math.Pow(v.Dy, 2.0))
|
||||
}
|
||||
|
||||
func (this Vector) GetPolarAngle() float64 {
|
||||
return math.Atan2(this.Dy, this.Dx)
|
||||
func (v Vector) GetPolarAngle() float64 {
|
||||
return math.Atan2(v.Dy, v.Dx)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user