2017-04-12 21:37:20 +00:00
|
|
|
/*
|
|
|
|
* This file is subject to the terms and conditions defined in
|
|
|
|
* file 'LICENSE.md', which is part of this source code package.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package draw
|
|
|
|
|
2019-03-19 22:36:08 +02:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2019-05-16 23:08:40 +03:00
|
|
|
"github.com/unidoc/unipdf/v3/pdf/internal/transform"
|
2019-03-19 22:36:08 +02:00
|
|
|
)
|
2017-04-12 21:37:20 +00:00
|
|
|
|
2019-04-18 22:35:03 +03:00
|
|
|
// Point represents a two-dimensional point.
|
2017-04-12 21:37:20 +00:00
|
|
|
type Point struct {
|
|
|
|
X float64
|
|
|
|
Y float64
|
|
|
|
}
|
|
|
|
|
2019-04-18 22:35:03 +03:00
|
|
|
// NewPoint returns a new point with the coordinates x, y.
|
2017-04-12 21:37:20 +00:00
|
|
|
func NewPoint(x, y float64) Point {
|
2018-12-09 21:25:30 +02:00
|
|
|
return Point{X: x, Y: y}
|
2017-04-12 21:37:20 +00:00
|
|
|
}
|
|
|
|
|
2019-04-18 22:35:03 +03:00
|
|
|
// Add shifts the coordinates of the point with dx, dy and returns the result.
|
2017-04-12 21:37:20 +00:00
|
|
|
func (p Point) Add(dx, dy float64) Point {
|
|
|
|
p.X += dx
|
|
|
|
p.Y += dy
|
|
|
|
return p
|
|
|
|
}
|
|
|
|
|
2018-12-09 20:22:33 +02:00
|
|
|
// AddVector adds vector to a point.
|
2018-12-09 21:25:30 +02:00
|
|
|
func (p Point) AddVector(v Vector) Point {
|
|
|
|
p.X += v.Dx
|
|
|
|
p.Y += v.Dy
|
|
|
|
return p
|
2017-04-12 21:37:20 +00:00
|
|
|
}
|
|
|
|
|
2019-03-19 22:36:08 +02:00
|
|
|
// Rotate returns a new Point at `p` rotated by `theta` degrees.
|
|
|
|
func (p Point) Rotate(theta float64) Point {
|
|
|
|
r := transform.NewPoint(p.X, p.Y).Rotate(theta)
|
|
|
|
return NewPoint(r.X, r.Y)
|
|
|
|
}
|
|
|
|
|
2017-04-12 21:37:20 +00:00
|
|
|
func (p Point) String() string {
|
|
|
|
return fmt.Sprintf("(%.1f,%.1f)", p.X, p.Y)
|
|
|
|
}
|