Files
hwr2024_b/cpp/misc/structs_enums_unions.h

64 lines
1.7 KiB
C++

//
// Created by David Hackbarth on 27.02.26.
//
#ifndef MISC_STRUCTS_ENUMS_UNIONS_H
#define MISC_STRUCTS_ENUMS_UNIONS_H
#include <iostream>
struct Vector3 {
// public
float x, y, z;
bool operator==(const Vector3 &other) const {
return x == other.x && y == other.y && z == other.z;
}
bool operator!=(const Vector3 &other) const { return !(*this == other); }
bool operator<(const Vector3 &other) const { return x < other.x && y < other.y && z < other.z; }
bool operator>(const Vector3 &other) const { return other < *this; }
bool operator<=(const Vector3 &other) const { return !(*this > other); }
bool operator>=(const Vector3 &other) const { return !(*this < other); }
Vector3 operator*(float scalar) const { return {x * scalar, y * scalar, z * scalar}; }
void operator*=(float scalar) {
x *= scalar;
y *= scalar;
z *= scalar;
}
private:
// private
};
inline Vector3 operator*(float scalar, const Vector3 &v) { return v * scalar; }
inline std::ostream &operator<<(std::ostream &os, const Vector3 &v) {
os << "(" << v.x << "/" << v.y << "/" << v.z << ")";
return os;
}
enum Weekdays {
Monday = 1, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday,
FORCE_DWORD = 0x7fffffff // DWORD -> double word -> unsigned 32bit int, word -> unsigned 16bit int
};
union ScreenSize {
// struct {
// unsigned short width; // first 16bit
// unsigned short height; // second 16bit
// };
struct {
unsigned short width; // first 16bit
unsigned short height; // second 16bit
} u;
unsigned int value;
};
#endif //MISC_STRUCTS_ENUMS_UNIONS_H