Point struct for geometry library

Правка en1, от brycesandlund, 2016-09-29 06:37:27

(This post is primarily for ACM-ICPC, since you don't need to type in code for online contests.)

My current geometry library uses a Pt struct with members x and y. However, many times I just use a pair instead as this avoids needing to type the struct code and a comparator if you need sorting. However, if you're writing enough geometry functions, it's quicker to write and easier to read with .x and .y instead of .first and .second. I'm now considering doing something like the following:

typedef long long T;
typedef pair<T, T> Pt;
#define x first
#define y second

Pt operator - (Pt a, Pt b) { return Pt(a.x-b.x, a.y-b.y); }

T dot(Pt a, Pt b) { return a.x*b.x + a.y*b.y; }

double dist(Pt a, Pt b) {
    return sqrt(dot(a-b,a-b));
}

This kind of gives the best of both worlds; however, it has some strange side effects. I am wondering if the community has an opinion on what is the best to use, or if there is a different trick I can make use of.

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en1 Английский brycesandlund 2016-09-29 06:37:27 1019 Initial revision (published)