代码拉取完成,页面将自动刷新
package xgeo
import (
"errors"
"github.com/golang/geo/r2"
"github.com/spatial-go/geoos/space"
)
type Polygon struct {
r2.Rect
}
func NewPolygon(coords [][]float64) Polygon {
rect := r2.EmptyRect()
if len(coords) > 0 {
points := make([]r2.Point, 0)
for _, v := range coords {
point := r2.Point{
X: v[0],
Y: v[1],
}
points = append(points, point)
}
rect = r2.RectFromPoints(points...)
}
return Polygon{rect}
}
func (p Polygon) Area() (float64, error) {
size := p.Size()
if size.X == size.Y && size.X < 0 {
return 0, errors.New("polygon area err")
}
return size.X * size.Y, nil
}
func (p Polygon) Centroid() space.Point {
point := p.Center()
return space.Point([]float64{point.X, point.Y})
}
func (p Polygon) IsEmpty() bool {
return p.Rect.IsEmpty()
}
func (p Polygon) Intersection(other Polygon) Polygon {
rect := p.Rect.Intersection(other.Rect)
return Polygon{rect}
}
func (p Polygon) Contains(other Polygon) bool {
return p.Rect.Contains(other.Rect)
}
func (p Polygon) InteriorContains(other Polygon) bool {
return p.Rect.InteriorContains(other.Rect)
}
func (p Polygon) Intersects(other Polygon) bool {
return p.Rect.Intersects(other.Rect)
}
func (p Polygon) InteriorIntersects(other Polygon) bool {
return p.Rect.InteriorIntersects(other.Rect)
}
func (p Polygon) ApproxEqual(other Polygon) bool {
return p.Rect.ApproxEqual(other.Rect)
}
func (p Polygon) Union(other Polygon) Polygon {
rect := p.Rect.Union(other.Rect)
return Polygon{rect}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。