typedef struct { double x, y; } vec;
typedef struct { int n; vec* v; } polygon_t, *polygon;
#define BIN_V(op, xx, yy) vec v##op(vec a, vec b) { \
vec c; c.x = xx; c.y = yy; return c; }
#define BIN_S(op, r) double v##op(vec a, vec b) { return r; }
BIN_V(sub, a.x - b.x, a.y - b.y);
BIN_V(add, a.x + b.x, a.y + b.y);
BIN_S(dot, a.x * b.x + a.y * b.y);
BIN_S(cross, a.x * b.y - a.y * b.x);
vec testPoints[] = {
{1, 1},
{3, 3},
{3, 5},
{5, 2},
{6, 3},
{7, 4}
};
What does the array of structs at last work? I don't quite understand how {1, 1} become a vec.
If I want to have a vector<vec> allPoints, how can I push a vec into this vector? This doesn't work allPoints.push_back({1, 2});, as well as allPoints.push_back(new vec(1, 2));
typedef structin C++.