向量和点重载

 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

class Point {
public:
    ll x{}, y{};

    // 代替叉乘
    Point operator[](const Point &point) const {
        return {x * point.y - y * point.x};
    }

    ll operator*(const Point &point) const {
        return (x * point.x + point.y * y);
    }

    Point operator-(const Point &point) const {
        return {x - point.x, y - point.y};
    }

    Point operator+(const Point &point) const {
        return {x + point.x, y + point.y};
    }

    Point operator-=(const Point &point) {
        x -= point.x, y -= point.y;
        return *this;
    }

    Point operator+=(const Point &point) {
        x += point.x, y += point.y;
        return *this;
    }

    int operator<(const Point &point) const {
        if (x == point.x) return y < point.y;
        return x < point.x;
    }

    int operator<=(const Point &point) const {
        if (x == point.x) return y <= point.y;
        return x < point.x;
    }

    int operator==(const Point &point) const {
        return *this == point;
    }

    int operator>(const Point &point) const {
        if (x == point.x) return y > point.y;
        return x > point.x;
    }

    int operator>=(const Point &point) const {
        if (x == point.x) return y >= point.y;
        return x > point.x;
    }
};
updatedupdated2025-09-302025-09-30