-
Notifications
You must be signed in to change notification settings - Fork 2
/
vgen_centroid.h
75 lines (66 loc) · 2.06 KB
/
vgen_centroid.h
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
75
// .___
// ___ __ ____ ___ ___ ____ __| _/
// \ \/ // __ \\ \/ // __ \ / __ |
// \ /\ ___/ > <\ ___// /_/ |
// \_/ \___ >__/\_ \\___ >____ |
// \/ \/ \/ \/ __ .__
// ____ ____ ____ ________________ _/ |_|__| ____ ____
// / ___\_/ __ \ / \_/ __ \_ __ \__ \\ __\ |/ _ \ / \
// / /_/ > ___/| | \ ___/| | \// __ \| | | ( <_> ) | \
// \___ / \___ >___| /\___ >__| (____ /__| |__|\____/|___| /
// /_____/ \/ \/ \/ \/ \/
//
// (c) 2016 - 2020 Karsten Schmidt // ASL 2.0 licensed
#ifndef __vgen_centroid_h__
#define __vgen_centroid_h__
#include <vgen_math.h>
vector2 vg_centroid(const vector2 pts[]) {
int n = len(pts);
vector2 c = {0, 0};
for (int i = 0; i < n; i++) {
c += pts[i];
}
return c / n;
}
vector vg_centroid(const vector pts[]) {
int n = len(pts);
vector c = {0, 0, 0};
for (int i = 0; i < n; i++) {
c += pts[i];
}
return c / n;
}
vector vg_centroid(int geo; const int pts[]) {
int n = len(pts);
vector c = {0, 0, 0};
for (int i = 0; i < n; i++) {
c += point(geo, "P", pts[i]);
}
return c / n;
}
vector vg_prim_centroid(int geo, prim) {
return vg_centroid(geo, primpoints(geo, prim));
}
int[] vg_add_edge_centroids(int geo; const int pts[]) {
int res[];
int n = len(pts);
resize(res, n);
for (int i = n - 1, j = 0; j < n; i = j, j++) {
res[i] = addpoint(
geo, vg_mix(point(geo, "P", pts[i]), point(geo, "P", pts[j])));
}
return res;
}
int[] vg_add_edge_centroids_uv(int geo; const int pts[]) {
int res[];
int n = len(pts);
resize(res, n);
for (int i = n - 1, j = 0; j < n; i = j, j++) {
res[i] = addpoint(
geo, vg_mix(point(geo, "P", pts[i]), point(geo, "P", pts[j])));
vector2 uv = vg_mix(point(geo, "uv", pts[i]), point(geo, "uv", pts[j]));
setpointattrib(geo, "uv", res[i], uv);
}
return res;
}
#endif