liuxiaolong
2019-11-07 365f18d49473cb50a66c9af92de1d6794521cac8
ruleserver/geoPolygon.go
@@ -2,6 +2,7 @@
import (
   "math"
   "ruleprocess/structure"
)
func min(num1 float64, num2 float64) float64 {
@@ -42,7 +43,7 @@
//PintIsInPolygon 判断点是否在多边形内部
//point为要判断的坐标点
//polygon是多边形各点数组
func pintIsInPolygon(point Pointfloat, polygon []Point, widthScale float64, heightScale float64) bool {
func pintIsInPolygon(point structure.Pointfloat, polygon []Point, widthScale float64, heightScale float64) bool {
   var nCross int = 0
   for i := 0; i < len(polygon); i++ {
@@ -72,17 +73,17 @@
}
//GetLocation 将一个给定起始坐标,宽度长度的矩形区域均分为n方份并返回中心坐标(n为单边平分数值)和面积
func getLocation(rect Rect, n int) ([]Pointfloat, float64) {
func getLocation(rect structure.Rect, n int) ([]structure.Pointfloat, float64) {
   xArr := make([]float64, n) // 用切片不用数组,数组不能用变量定义长度
   yArr := make([]float64, n)
   pointArr := make([]Pointfloat, 0, n*n)
   pointArr := make([]structure.Pointfloat, 0, n*n)
   for i := 0; i < n; i++ {
      xArr[i] = rect.X + (rect.Width/float64(2*n))*float64(2*i+1)
      yArr[i] = rect.Y + (rect.Height/float64(2*n))*float64(2*i+1)
   }
   for i := 0; i < n; i++ {
      for j := 0; j < n; j++ {
         point := Pointfloat{X: xArr[i], Y: yArr[j]}
         point := structure.Pointfloat{X: xArr[i], Y: yArr[j]}
         pointArr = append(pointArr, point)
      }
   }
@@ -105,7 +106,7 @@
}
//PgsInterPercent calculate percent of two polygon intersection  计算两个多边形的重叠占比
func PgsInterPercent(pgpts []Point, box Rect, widthScale float64, heightScale float64) (percent float64) {
func PgsInterPercent(pgpts []Point, box structure.Rect, widthScale float64, heightScale float64) (percent float64) {
   areapts, areaBox := getLocation(box, 10)
   var count = 0