-
Notifications
You must be signed in to change notification settings - Fork 0
/
Search.cpp
74 lines (68 loc) · 1.5 KB
/
Search.cpp
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
71
72
73
74
#include "Search.h"
#include "geometry.h"
using namespace std;
void clearPoint(Point& p)
{
p.x = p.y = 0.0;
}
void clearTriangle(Triangle& tr)
{
for (int i = 0; i < 3; i++)
clearPoint(tr.vertexes[i]);
tr.area = 0.0;
tr.perimetr = 0.0;
}
void findAndInsert(Triangle* &trArray, int lenght, const Triangle& triangle)
{
int pos;
for (pos = lenght - 1; pos >= 0; pos--)
{
if (triangle.area <= trArray[pos].area)
break;
}
pos++;
if (pos == lenght)
return;
for (int m = lenght - 2; m >= pos; m--)
trArray[m + 1] = trArray[m];
trArray[pos] = triangle;
}
void findAndInsert2(Triangle* &trArray, int lenght, const Triangle& triangle)
{
int pos;
for (pos = lenght - 1; pos >= 0; pos--)
{
if (triangle.perimetr <= trArray[pos].perimetr)
break;
}
pos++;
if (pos == lenght)
return;
for (int m = lenght - 2; m >= pos; m--)
trArray[m + 1] = trArray[m];
trArray[pos] = triangle;
}
void searchLargestTriangles(const Point* pointArray, int pointNum, Triangle* trArray, int maxTrNum)
{
if (maxTrNum <= 0)
return;
for (int i = 0; i < maxTrNum; i++)
clearTriangle(trArray[i]);
Triangle tr;
for (int i = 0; i < pointNum; i++)
{
tr.vertexes[0] = pointArray[i];
for (int j = i + 1; j < pointNum; j++)
{
tr.vertexes[1] = pointArray[j];
for (int k = j + 1; k < pointNum; k++)
{
tr.vertexes[2] = pointArray[k];
tr.area = calcTringleArea(tr);
tr.perimetr = calcTringlePerim(tr);
//findAndInsert(trArray, maxTrNum, tr);
findAndInsert2(trArray, maxTrNum, tr);
}
}
}
}