panlei
2019-11-07 23c837bc4d5b4312c0bb5eb96260c90e887882ac
ruleserver/geoPolygon_test.go
New file
@@ -0,0 +1,38 @@
package ruleserver
import (
   "basic.com/valib/logger.git"
   "encoding/json"
   "fmt"
   "ruleprocess/structure"
   "testing"
)
func TestPgsInterPercent(t *testing.T) {
   areaPoints := json2points("[{\"x\":582,\"y\":11},{\"x\":582,\"y\":525},{\"x\":943,\"y\":525},{\"x\":943,\"y\":11}]")
   widthScale := float64(2688) / 960
   heigthScale := float64(1520) / 540
   rec := structure.Rect{1333, 594,204,274}
   per := PgsInterPercent(areaPoints,rec,widthScale,heigthScale)
   fmt.Println(widthScale,heigthScale,per)
}
// 将字符串格式的坐标序列化为Point格式
func json2points(areaPoints string) []Point {
   var pts []Point
   if areaPoints == "[]" || areaPoints == "" {
      logger.Error("=====================此区域为全部区域")
      pts = append(pts, Point{0, 0})
      pts = append(pts, Point{0, 540})
      pts = append(pts, Point{960, 540})
      pts = append(pts, Point{960, 0})
   } else {
      err := json.Unmarshal([]byte(areaPoints), &pts)
      if err != nil {
         logger.Error("json.Unmarshal错误", err)
         panic("序列化坐标异常,程序退出")
      }
   }
   return pts
}