派生自 Algorithm/baseDetector

Scheaven
2021-06-03 168af40fe9a3cc81c6ee16b3e81f154780c36bdb
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//
// Created by Scheaven on 2020/5/31.
//
#ifndef GEOMETRY_UTIL_H
#define GEOMETRY_UTIL_H
 
#include <stdlib.h>
#include <math.h>
 
#include <iostream>
#include <cmath>
#include <cstring>
#include "assert.h"
 
typedef struct _Point
{
public:
    float x;
    float y;
 
public:
    _Point(float x, float y);
    _Point();
}SPoint;
 
// 多边形区域结构
typedef struct _PInfo
{
    SPoint* point;
    int count;
}RegInfo;
 
float calDistance(SPoint A, SPoint B);
 
 
//作用:判断点是否在多边形内
//p指目标点, ptPolygon指多边形的点集合, nCount指多边形的边数
bool Pt_in_Polygon(SPoint point, RegInfo* polygon);
 
 
 
/*
 * 多边形部分,判断多边形重叠率的计算
 */
#define MAX_POINT_POLYGON 64
 
struct Polygon {
    SPoint pt[MAX_POINT_POLYGON];
    int     n;
 
    Polygon(int n_ = 0 ) { assert(n_>= 0 && n_ < MAX_POINT_POLYGON); n = n_;}
    virtual ~Polygon() {}
 
    void clear() { n = 0; }
    void add(const SPoint &p) {if(n < MAX_POINT_POLYGON) pt[n++] = p;}
    void push_back(const SPoint &p) {add(p);}
    int size() const { return n;}
    SPoint getCenter() const ;
    const SPoint & operator[] (int index) const { assert(index >= 0 && index < n); return pt[index];}
    SPoint& operator[] (int index) { assert(index >= 0 && index < n); return pt[index]; }
    void pointsOrdered() ;
    float area() const ;
    bool pointIsInPolygon(SPoint p) const ;
};
 
 
void intersectPolygonSHPC(const Polygon * sub,const Polygon* clip,Polygon* res) ;
void intersectPolygonSHPC(const Polygon & sub,const Polygon& clip,Polygon& res) ;
 
#endif //GEOMETRY_UTIL_H