first commit

This commit is contained in:
陈赣
2026-06-03 12:43:14 +08:00
commit ba76cfae28
608 changed files with 120791 additions and 0 deletions

17
objects/shapes/vp_line.cpp Executable file
View File

@@ -0,0 +1,17 @@
#include "vp_line.h"
namespace vp_objects {
vp_line::vp_line(vp_point start, vp_point end): start(start), end(end) {
}
vp_line::~vp_line() {
}
float vp_line::length() {
return start.distance_with(end);
}
}

24
objects/shapes/vp_line.h Executable file
View File

@@ -0,0 +1,24 @@
#pragma once
#include "vp_point.h"
namespace vp_objects {
// line in 2-dims coordinate system
class vp_line {
private:
/* data */
public:
vp_line() = default;
vp_line(vp_point start, vp_point end);
~vp_line();
vp_point start;
vp_point end;
// distance between start and end point
float length();
};
}

18
objects/shapes/vp_point.cpp Executable file
View File

@@ -0,0 +1,18 @@
#include "vp_point.h"
namespace vp_objects {
vp_point::vp_point(int x, int y): x(x), y(y) {
}
vp_point::~vp_point() {
}
float vp_point::distance_with(const vp_point & p) {
return std::sqrt(std::pow(x-p.x, 2) + std::pow(y-p.y, 2));
}
}

23
objects/shapes/vp_point.h Executable file
View File

@@ -0,0 +1,23 @@
#pragma once
#include <utility>
#include <cmath>
namespace vp_objects {
// point in 2-dims coordinate system
class vp_point
{
private:
/* data */
public:
vp_point(int x = 0, int y = 0);
~vp_point();
int x;
int y;
// distance between 2 points
float distance_with(const vp_point & p);
};
}

18
objects/shapes/vp_polygon.cpp Executable file
View File

@@ -0,0 +1,18 @@
#include <assert.h>
#include "vp_polygon.h"
namespace vp_objects {
vp_polygon::vp_polygon(std::vector<vp_point> vertexs): vertexs(vertexs) {
assert(vertexs.size() > 2);
}
vp_polygon::~vp_polygon() {
}
bool vp_polygon::contains(const vp_point & p) {
return true;
}
}

25
objects/shapes/vp_polygon.h Executable file
View File

@@ -0,0 +1,25 @@
#pragma once
#include <vector>
#include "vp_point.h"
namespace vp_objects {
class vp_polygon
{
private:
/* data */
public:
vp_polygon() = default;
vp_polygon(std::vector<vp_point> vertexs);
~vp_polygon();
// vertexs of the polygon
std::vector<vp_point> vertexs;
// check if the polygon contains a point
bool contains(const vp_point & p);
};
}

41
objects/shapes/vp_rect.cpp Executable file
View File

@@ -0,0 +1,41 @@
#include "vp_rect.h"
namespace vp_objects {
vp_rect::vp_rect(int x, int y, int width, int height):
x(x),
y(y),
width(width),
height(height) {
}
vp_rect::vp_rect(vp_point left_top, vp_size wh):
x(left_top.x), y(left_top.y), width(wh.width), height(wh.height) {
}
vp_rect::~vp_rect() {
}
vp_point vp_rect::center() {
return vp_point(x + width / 2, y + height / 2);
}
float vp_rect::iou_with(const vp_rect & rect) {
return 1.0;
}
bool vp_rect::contains(const vp_point & p) {
return true;
}
vp_point vp_rect::track_point() {
// by default the center point of bottom is tracking point.
return {x + width / 2, y + height};
}
}

38
objects/shapes/vp_rect.h Executable file
View File

@@ -0,0 +1,38 @@
#pragma once
#include <tuple>
#include "vp_point.h"
#include "vp_size.h"
namespace vp_objects {
// rect in 2-dims coordinate system
class vp_rect {
private:
/* data */
public:
vp_rect() = default;
vp_rect(int x, int y, int width, int height);
vp_rect(vp_point left_top, vp_size wh);
~vp_rect();
int x;
int y;
int width;
int height;
// get center point of the rect
vp_point center();
// get track point of the rect
// track point is used to locate the target(represented by the rect)
vp_point track_point();
// calculate the iou with another rect
float iou_with(const vp_rect & rect);
// check if the rect contains a point
bool contains(const vp_point & p);
};
}

13
objects/shapes/vp_size.cpp Executable file
View File

@@ -0,0 +1,13 @@
#include "vp_size.h"
namespace vp_objects {
vp_size::vp_size(int width, int height): width(width), height(height) {
}
vp_size::~vp_size() {
}
}

20
objects/shapes/vp_size.h Executable file
View File

@@ -0,0 +1,20 @@
#pragma once
#include <utility>
namespace vp_objects {
// size(width and height) in 2-dims coordinate system
class vp_size {
private:
/* data */
public:
vp_size(int width = 0, int height = 0);
~vp_size();
int width;
int height;
};
}