panlei
2019-11-07 0bd35e1e48e8e17c5eccfc92d706730619d5437f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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
}