# Geometry
# Description
The Geometry namespace provides a series of geometric calculations and graphics processing functions and classes, used for spatial positioning, shape calculations, and collision detection operations in the game.
# How to Use
// Angle and radian conversion
float degrees = Geometry::RadianToDegree(M_PI / 4); // 45 degrees
float radians = Geometry::ToRadians(45.0f); // π/4
// Geometric calculations
std::vector<Vector> path = unit->Path();
float pathLength = Geometry::PathLength(path);
// Using geometric shapes
Geometry::Circle circle(Vector(500, 500), 150.0f);
Geometry::Polygon polygon;
circle.ToPolygon(polygon);
polygon.Draw(MAKE_COLOR(255, 0, 0, 255), 2.0f);
# Constants
# CIRCLE_LINE_SEGMENTS
#define CIRCLE_LINE_SEGMENTS 18
The number of line segments used when converting a circle to a polygon, determining the accuracy of the polygon approximation of the circle.
// Used internally, no need to call directly
// When Circle::ToPolygon() is called, this constant is used to determine the number of vertices in the polygon
# Vector Static Members
# Vector.Zero
static Vector Zero
Represents a zero vector with coordinates (0,0,0). Used for scenarios requiring a default vector or zero vector.
// Using zero vector as a default value
bool isValidTarget = hero->IsValidTarget(900.0f, true, Vector::Zero);
// As a reference point
Vector direction = (targetPos - Vector::Zero).Normalized();
# RadianToDegree
double RadianToDegree(double angle)
Converts radians to degrees.
Parameter Name | Parameter Type | Description |
---|---|---|
angle | double | The radian value to convert |
double radians = M_PI / 4; // 45 degrees in radians
float degrees = Geometry::RadianToDegree(radians);
// degrees ≈ 45.0
# ToRadians
float ToRadians(float val)
Converts degrees to radians.
Parameter Name | Parameter Type | Description |
---|---|---|
val | float | The degree value to convert |
float degrees = 45.0f;
float radians = Geometry::ToRadians(degrees);
// radians ≈ 0.785398... (π/4)
# CircleCircleIntersection
void CircleCircleIntersection(const Vector& center1, const Vector& center2, float radius1, float radius2, std::vector<Vector>& Out)
Calculates the intersection points of two circles.
Parameter Name | Parameter Type | Description |
---|---|---|
center1 | const Vector& | Center point of the first circle |
center2 | const Vector& | Center point of the second circle |
radius1 | float | Radius of the first circle |
radius2 | float | Radius of the second circle |
Out | std::vector<Vector>& | Output parameter for storing intersection points |
Vector center1(100, 100);
Vector center2(150, 100);
float radius1 = 60;
float radius2 = 60;
std::vector<Vector> intersectionPoints;
Geometry::CircleCircleIntersection(center1, center2, radius1, radius2, intersectionPoints);
// intersectionPoints contains the intersection points of the two circles
# ClipPolygons
std::vector<std::vector<ClipperLib::IntPoint>> ClipPolygons(std::vector<Polygon>& polygons)
Clips a collection of polygons.
Parameter Name | Parameter Type | Description |
---|---|---|
polygons | std::vector<Polygon>& | The collection of polygons to clip |
std::vector<Geometry::Polygon> polygons;
// Add polygons to the collection
auto clippedPolygons = Geometry::ClipPolygons(polygons);
# PositionAfter
Vector PositionAfter(const std::vector<Vector>& self, int t, int speed, int delay = 0)
Calculates the position of an object after a given time, speed, and delay.
Parameter Name | Parameter Type | Description |
---|---|---|
self | const std::vector<Vector>& | Collection of path points |
t | int | Time |
speed | int | Movement speed |
delay | int | Delay time, default is 0 |
std::vector<Vector> path = unit->Path();
Vector futurePosition = Geometry::PositionAfter(path, 500, unit->MoveSpeed());
# ToPolygon (ClipperLib::IntPoint version)
void ToPolygon(const std::vector<ClipperLib::IntPoint>& v, Polygon& out)
Converts a ClipperLib::IntPoint vector to a polygon.
Parameter Name | Parameter Type | Description |
---|---|---|
v | const std::vector<ClipperLib::IntPoint>& | Collection of points |
out | Polygon& | Output parameter, the converted polygon |
std::vector<ClipperLib::IntPoint> points;
// Add points to the collection
Geometry::Polygon polygon;
Geometry::ToPolygon(points, polygon);
# ToPolygon (Nested ClipperLib::IntPoint version)
void ToPolygon(const std::vector<std::vector<ClipperLib::IntPoint>>& v, std::vector<Polygon>& out)
Converts a nested ClipperLib::IntPoint vector to a collection of polygons.
Parameter Name | Parameter Type | Description |
---|---|---|
v | const std::vector<std::vector<ClipperLib::IntPoint>>& | Nested collection of points |
out | std::vector<Polygon>& | Output parameter, the converted collection of polygons |
std::vector<std::vector<ClipperLib::IntPoint>> nestedPoints;
// Add point collections to the nested collection
std::vector<Geometry::Polygon> polygons;
Geometry::ToPolygon(nestedPoints, polygons);
# VectorMovementCollision
void VectorMovementCollision(const Vector& startPoint1, const Vector& endPoint1, float v1, const Vector& startPoint2, float v2, float delay, float& Outt, Vector& Outpos)
Calculates vector movement collision.
Parameter Name | Parameter Type | Description |
---|---|---|
startPoint1 | const Vector& | Starting position of the first object |
endPoint1 | const Vector& | Ending position of the first object |
v1 | float | Speed of the first object |
startPoint2 | const Vector& | Starting position of the second object |
v2 | float | Speed of the second object |
delay | float | Delay time |
Outt | float& | Output parameter, collision time |
Outpos | Vector& | Output parameter, collision position |
Vector startPoint1 = hero->Position();
Vector endPoint1 = hero->Position().Extend(hero->Direction(), 1000);
float v1 = hero->MoveSpeed();
Vector startPoint2 = missile->StartPosition();
float v2 = missile->SData()->MissileSpeed();
float delay = 0.25f;
float collisionTime;
Vector collisionPosition;
Geometry::VectorMovementCollision(startPoint1, endPoint1, v1, startPoint2, v2, delay, collisionTime, collisionPosition);
// If collisionTime is not NaN, there will be a collision, and collisionPosition is the collision position
# PathLength
float PathLength(const std::vector<Vector>& path)
Calculates the length of a path.
Parameter Name | Parameter Type | Description |
---|---|---|
path | const std::vector<Vector>& | Collection of path points |
std::vector<Vector> path = unit->Path();
float length = Geometry::PathLength(path);
# CutPath
void CutPath(const std::vector<Vector>& path, float distance, std::vector<Vector>& out)
Cuts a path at a specified distance.
Parameter Name | Parameter Type | Description |
---|---|---|
path | const std::vector<Vector>& | The path to cut |
distance | float | Cutting distance |
out | std::vector<Vector>& | Output parameter, the cut path segment |
std::vector<Vector> path = unit->Path();
std::vector<Vector> cutResult;
Geometry::CutPath(path, 500, cutResult);
// cutResult contains the path segment from the start point to the specified distance
# Class:Polygon
Represents a polygon.
Geometry::Polygon polygon;
polygon.Add(Vector(100, 100));
polygon.Add(Vector(200, 100));
polygon.Add(Vector(200, 200));
polygon.Add(Vector(100, 200));
# Polygon.Polygon
Polygon()
Creates an empty polygon.
Geometry::Polygon polygon;
# Polygon.Add
void Add(const Vector& point)
Adds a point to the polygon.
Parameter Name | Parameter Type | Description |
---|---|---|
point | const Vector& | The point to add |
Geometry::Polygon polygon;
polygon.Add(Vector(100, 100));
polygon.Add(Vector(200, 100));
polygon.Add(Vector(200, 200));
polygon.Add(Vector(100, 200));
# Polygon.IsInside
bool IsInside(const Vector& point) const
Checks if a point is inside the polygon.
Parameter Name | Parameter Type | Description |
---|---|---|
point | const Vector& | The point to check |
Geometry::Polygon polygon;
// Add points to form a polygon
Vector point(150, 150);
bool isInside = polygon.IsInside(point);
# Polygon.Draw
void Draw(unsigned int color, int width = 1, float z = -1.0f) const
Draws the polygon.
Parameter Name | Parameter Type | Description |
---|---|---|
color | unsigned int | Drawing color |
width | int | Line width, default is 1 |
z | float | Z coordinate, default is -1.0f |
Geometry::Polygon polygon;
// Add points to form a polygon
polygon.Draw(MAKE_COLOR(255, 0, 0, 255), 2.0f);
# Polygon.ToClipperPath
void ToClipperPath(std::vector<ClipperLib::IntPoint>& out) const
Converts the polygon to a ClipperLib path.
Parameter Name | Parameter Type | Description |
---|---|---|
out | std::vector<ClipperLib::IntPoint>& | Output parameter, the converted path point collection |
Geometry::Polygon polygon;
// Add points to form a polygon
std::vector<ClipperLib::IntPoint> clipperPath;
polygon.ToClipperPath(clipperPath);
# Class:Circle
Represents a circle.
Vector center(500, 500);
float radius = 150.0f;
Geometry::Circle circle(center, radius);
# Circle.Circle
Circle()
Creates a default circle with center at (0,0) and radius 0.
Geometry::Circle defaultCircle;
# Circle.Circle
Circle(const Vector& center, float radius)
Creates a circle with the specified center and radius.
Parameter Name | Parameter Type | Description |
---|---|---|
center | const Vector& | Center position |
radius | float | Circle radius |
Vector center(500, 500);
float radius = 150.0f;
Geometry::Circle circle(center, radius);
# Circle.ToPolygon
void ToPolygon(Polygon& out, int extraRadius = 0, float overrideRadius = -1) const
Converts the circle to an approximate polygon representation.
Parameter Name | Parameter Type | Description |
---|---|---|
out | Polygon& | Output parameter, the converted polygon |
extraRadius | int | Extra radius to add, default is 0 |
overrideRadius | float | Value to override the existing radius, default is -1 (don't override) |
Geometry::Circle circle(Vector(500, 500), 150.0f);
Geometry::Polygon polygon;
circle.ToPolygon(polygon);
// Now polygon contains a polygon approximating the circle
# Class:Arc
Represents an arc.
Vector start(100, 100);
Vector end(300, 100);
int radius = 100;
Geometry::Arc arc(start, end, radius);
# Arc.Arc
Arc()
Creates a default arc.
Geometry::Arc defaultArc;
# Arc.Arc
Arc(const Vector& start, const Vector& end, int radius)
Creates an arc with the specified start point, end point, and radius.
Parameter Name | Parameter Type | Description |
---|---|---|
start | const Vector& | Arc start position |
end | const Vector& | Arc end position |
radius | int | Arc radius |
Vector start(100, 100);
Vector end(300, 100);
int radius = 100;
Geometry::Arc arc(start, end, radius);
# Arc.ToPolygon
void ToPolygon(Polygon& out, int offset = 0) const
Converts the arc to an approximate polygon representation.
Parameter Name | Parameter Type | Description |
---|---|---|
out | Polygon& | Output parameter, the converted polygon |
offset | int | Offset, default is 0 |
Geometry::Arc arc(Vector(100, 100), Vector(300, 100), 100);
Geometry::Polygon polygon;
arc.ToPolygon(polygon);
// Now polygon contains a polygon approximating the arc
# Class:Rectangle
Represents a rectangle.
Vector start(100, 100);
Vector end(400, 100);
float width = 50.0f;
Geometry::Rectangle rectangle(start, end, width);
# Rectangle.Rectangle
Rectangle()
Creates a default rectangle.
Geometry::Rectangle defaultRectangle;
# Rectangle.Rectangle
Rectangle(const Vector& start, const Vector& end, float width)
Creates a rectangle with the specified start point, end point, and width.
Parameter Name | Parameter Type | Description |
---|---|---|
start | const Vector& | Rectangle start position |
end | const Vector& | Rectangle end position |
width | float | Rectangle width |
Vector start(100, 100);
Vector end(400, 100);
float width = 50.0f;
Geometry::Rectangle rectangle(start, end, width);
# Rectangle.ToPolygon
void ToPolygon(Polygon& out, int offset = 0) const
Converts the rectangle to a polygon representation.
Parameter Name | Parameter Type | Description |
---|---|---|
out | Polygon& | Output parameter, the converted polygon |
offset | int | Offset, default is 0 |
Geometry::Rectangle rectangle(Vector(100, 100), Vector(400, 100), 50.0f);
Geometry::Polygon polygon;
rectangle.ToPolygon(polygon);
// Now polygon represents the rectangle
# Class:Ring
Represents a ring (the area between two concentric circles).
Vector center(300, 300);
float innerRadius = 100.0f;
float outerRadius = 200.0f;
Geometry::Ring ring(center, innerRadius, outerRadius);
# Ring.Ring
Ring()
Creates a default ring.
Geometry::Ring defaultRing;
# Ring.Ring
Ring(const Vector& center, float innerRadius, float outerRadius)
Creates a ring with the specified center, inner radius, and outer radius.
Parameter Name | Parameter Type | Description |
---|---|---|
center | const Vector& | Ring center position |
innerRadius | float | Inner circle radius |
outerRadius | float | Outer circle radius |
Vector center(300, 300);
float innerRadius = 100.0f;
float outerRadius = 200.0f;
Geometry::Ring ring(center, innerRadius, outerRadius);
# Ring.ToPolygon
void ToPolygon(Polygon& out, int offset = 0) const
Converts the ring to a polygon representation.
Parameter Name | Parameter Type | Description |
---|---|---|
out | Polygon& | Output parameter, the converted polygon |
offset | int | Offset, default is 0 |
Geometry::Ring ring(Vector(300, 300), 100.0f, 200.0f);
Geometry::Polygon polygon;
ring.ToPolygon(polygon);
// Now polygon represents the ring
# Class:Cone
Represents a cone area.
Vector center = hero->Position();
Vector direction = (enemy->Position() - center).Normalized();
float radius = 45.0f; // 45 degree cone
float range = 600.0f; // 600 unit range
Geometry::Cone cone(center, direction, radius, range);
# Cone.Cone
Cone()
Creates a default cone.
Geometry::Cone defaultCone;
# Cone.Cone
Cone(const Vector& center, const Vector& direction, float radius, float range)
Creates a cone with the specified center, direction, radius, and range.
Parameter Name | Parameter Type | Description |
---|---|---|
center | const Vector& | Cone center position |
direction | const Vector& | Cone direction vector |
radius | float | Cone angle radius (degrees) |
range | float | Cone range |
Vector center = hero->Position();
Vector direction = (enemy->Position() - center).Normalized();
float radius = 45.0f; // 45 degree cone
float range = 600.0f; // 600 unit range
Geometry::Cone cone(center, direction, radius, range);
# Cone.ToPolygon
void ToPolygon(Polygon& out, int offset = 0) const
Converts the cone to a polygon representation.
Parameter Name | Parameter Type | Description |
---|---|---|
out | Polygon& | Output parameter, the converted polygon |
offset | int | Offset, default is 0 |
Geometry::Cone cone(center, direction, 45.0f, 600.0f);
Geometry::Polygon polygon;
cone.ToPolygon(polygon);
// Now polygon represents the cone
← Game HealthPrediction →