diff --git a/dl/base/dl_vector2.h b/dl/base/dl_vector2.h index 004e6639..cbc22f37 100644 --- a/dl/base/dl_vector2.h +++ b/dl/base/dl_vector2.h @@ -113,6 +113,10 @@ public: assert(i < _w); return _ptrLine[j][i]; } + const T& Get(const PointU& xy) const + { + return Get(xy[1], xy[0]); + } T& GetRef(size_t j, size_t i) { assert(j < _ptrLine.size()); diff --git a/dl/math/dl_math.h b/dl/math/dl_math.h index d0fbdca9..ea0703f2 100644 --- a/dl/math/dl_math.h +++ b/dl/math/dl_math.h @@ -375,10 +375,8 @@ std::array Normalize(const std::array& v) /** * @brief 返回圆形范围的节点,考虑越界 * @param[in] rad 传入0返回1个节点、传入1返回4个节点、传入2返回13个节点,依次类推 - * @todo 暂未测试 */ std::vector GetCircle(const Size& size, const PointU& xy, unsigned rad); - /** * @brief 返回圆形范围的节点,不考虑越界 * @param[in] rad 传入0返回1个节点、传入1返回4个节点、传入2返回13个节点,依次类推 diff --git a/dl/math/dl_random.h b/dl/math/dl_random.h index 75461bd0..ff327abe 100644 --- a/dl/math/dl_random.h +++ b/dl/math/dl_random.h @@ -158,10 +158,19 @@ public: return ret; } + static Point ExPoint(const Point& p0, const Point& p1) + { + return { Int(p0[0], p1[0]), Int(p0[1], p1[1]) }; + } static PointU ExPointU(const PointU& p0, const PointU& p1) { return { Uint(p0[0], p1[0]), Uint(p0[1], p1[1]) }; } + static Position ExDirection() + { + float r = Random::Angle(); + return { std::cos(r), std::sin(r)}; + } /** * @brief 返回百分比命中 */ @@ -169,6 +178,13 @@ public: { return Int(0, 99) < 50; } + /** + * @brief 返回角度(弧度制) + */ + static float Angle(float min = 0, float max = 3.1415926f * 2.0f) + { + return Float(min, max); + } //! 一般不使用,传给标准库接口才使用 static std::default_random_engine& GetEngine() diff --git a/project/hs b/project/hs index aa0f8109..5a690d4c 160000 --- a/project/hs +++ b/project/hs @@ -1 +1 @@ -Subproject commit aa0f81092f43d9b36fb9f2cdae67a043995e2395 +Subproject commit 5a690d4c432aaa4ee1f6a57cd0bae312d56d99e8