docs: 优化项目文档
This commit is contained in:
691
utils/geometry/README.md
Normal file
691
utils/geometry/README.md
Normal file
@@ -0,0 +1,691 @@
|
||||
# Geometry
|
||||
|
||||
geometry 旨在提供一组用于处理几何形状和计算几何属性的函数和数据结构。该包旨在简化几何计算的过程,并提供一致的接口和易于使用的功能。
|
||||
主要特性:
|
||||
- 几何形状:"geometry"包支持处理各种几何形状,如点、线、多边形和圆等。您可以使用这些形状来表示和操作实际世界中的几何对象。
|
||||
- 几何计算:该包提供了一系列函数,用于执行常见的几何计算,如计算两点之间的距离、计算线段的长度、计算多边形的面积等。这些函数旨在提供高效和准确的计算结果。
|
||||
- 坐标转换:"geometry"包还提供了一些函数,用于在不同坐标系之间进行转换。您可以将点从笛卡尔坐标系转换为极坐标系,或者从二维坐标系转换为三维坐标系等。
|
||||
- 简化接口:该包的设计目标之一是提供简化的接口,使几何计算变得更加直观和易于使用。您可以轻松地创建和操作几何对象,而无需处理繁琐的底层细节。
|
||||
|
||||
[](https://pkg.go.dev/github.com/kercylan98/minotaur/geometry)
|
||||

|
||||
|
||||
## 目录
|
||||
列出了该 `package` 下所有的函数,可通过目录进行快捷跳转 ❤️
|
||||
<details>
|
||||
<summary>展开 / 折叠目录</summary
|
||||
|
||||
|
||||
> 包级函数定义
|
||||
|
||||
|函数|描述
|
||||
|:--|:--
|
||||
|[NewCircle](#NewCircle)|通过传入圆的半径和需要的点数量,生成一个圆
|
||||
|[CalcCircleCentroidDistance](#CalcCircleCentroidDistance)|计算两个圆质心距离
|
||||
|[GetOppositionDirection](#GetOppositionDirection)|获取特定方向的对立方向
|
||||
|[GetDirectionNextWithCoordinate](#GetDirectionNextWithCoordinate)|获取特定方向上的下一个坐标
|
||||
|[GetDirectionNextWithPoint](#GetDirectionNextWithPoint)|获取特定方向上的下一个坐标
|
||||
|[GetDirectionNextWithPos](#GetDirectionNextWithPos)|获取位置在特定宽度和特定方向上的下一个位置
|
||||
|[CalcDirection](#CalcDirection)|计算点2位于点1的方向
|
||||
|[CalcDistanceWithCoordinate](#CalcDistanceWithCoordinate)|计算两点之间的距离
|
||||
|[CalcDistanceWithPoint](#CalcDistanceWithPoint)|计算两点之间的距离
|
||||
|[CalcDistanceSquared](#CalcDistanceSquared)|计算两点之间的平方距离
|
||||
|[CalcAngle](#CalcAngle)|计算点2位于点1之间的角度
|
||||
|[CalcNewCoordinate](#CalcNewCoordinate)|根据给定的x、y坐标、角度和距离计算新的坐标
|
||||
|[CalcRadianWithAngle](#CalcRadianWithAngle)|根据角度 angle 计算弧度
|
||||
|[CalcAngleDifference](#CalcAngleDifference)|计算两个角度之间的最小角度差
|
||||
|[CalcRayIsIntersect](#CalcRayIsIntersect)|根据给定的位置和角度生成射线,检测射线是否与多边形发生碰撞
|
||||
|[NewLineSegment](#NewLineSegment)|创建一根线段
|
||||
|[NewLineSegmentCap](#NewLineSegmentCap)|创建一根包含数据的线段
|
||||
|[NewLineSegmentCapWithLine](#NewLineSegmentCapWithLine)|通过已有线段创建一根包含数据的线段
|
||||
|[ConvertLineSegmentGeneric](#ConvertLineSegmentGeneric)|转换线段的泛型类型为特定类型
|
||||
|[PointOnLineSegmentWithCoordinate](#PointOnLineSegmentWithCoordinate)|通过一个线段两个点的位置和一个点的坐标,判断这个点是否在一条线段上
|
||||
|[PointOnLineSegmentWithPos](#PointOnLineSegmentWithPos)|通过一个线段两个点的位置和一个点的坐标,判断这个点是否在一条线段上
|
||||
|[PointOnLineSegmentWithPoint](#PointOnLineSegmentWithPoint)|通过一个线段两个点的位置和一个点的坐标,判断这个点是否在一条线段上
|
||||
|[PointOnLineSegmentWithCoordinateInBounds](#PointOnLineSegmentWithCoordinateInBounds)|通过一个线段两个点的位置和一个点的坐标,判断这个点是否在一条线段上
|
||||
|[PointOnLineSegmentWithPosInBounds](#PointOnLineSegmentWithPosInBounds)|通过一个线段两个点的位置和一个点的坐标,判断这个点是否在一条线段上
|
||||
|[PointOnLineSegmentWithPointInBounds](#PointOnLineSegmentWithPointInBounds)|通过一个线段两个点的位置和一个点的坐标,判断这个点是否在一条线段上
|
||||
|[CalcLineSegmentIsCollinear](#CalcLineSegmentIsCollinear)|检查两条线段在一个误差内是否共线
|
||||
|[CalcLineSegmentIsOverlap](#CalcLineSegmentIsOverlap)|通过对点进行排序来检查两条共线线段是否重叠,返回重叠线段
|
||||
|[CalcLineSegmentIsIntersect](#CalcLineSegmentIsIntersect)|计算两条线段是否相交
|
||||
|[CalcLineSegmentSlope](#CalcLineSegmentSlope)|计算线段的斜率
|
||||
|[CalcLineSegmentIntercept](#CalcLineSegmentIntercept)|计算线段的截距
|
||||
|[NewPoint](#NewPoint)|创建一个由 x、y 坐标组成的点
|
||||
|[NewPointCap](#NewPointCap)|创建一个由 x、y 坐标组成的点,这个点具有一个数据容量
|
||||
|[NewPointCapWithData](#NewPointCapWithData)|通过设置数据的方式创建一个由 x、y 坐标组成的点,这个点具有一个数据容量
|
||||
|[NewPointCapWithPoint](#NewPointCapWithPoint)|通过设置数据的方式创建一个由已有坐标组成的点,这个点具有一个数据容量
|
||||
|[CoordinateToPoint](#CoordinateToPoint)|将坐标转换为x、y的坐标数组
|
||||
|[CoordinateToPos](#CoordinateToPos)|将坐标转换为二维数组的顺序位置坐标
|
||||
|[PointToCoordinate](#PointToCoordinate)|将坐标数组转换为x和y坐标
|
||||
|[PointToPos](#PointToPos)|将坐标转换为二维数组的顺序位置
|
||||
|[PosToCoordinate](#PosToCoordinate)|通过宽度将一个二维数组的顺序位置转换为xy坐标
|
||||
|[PosToPoint](#PosToPoint)|通过宽度将一个二维数组的顺序位置转换为x、y的坐标数组
|
||||
|[PosToCoordinateX](#PosToCoordinateX)|通过宽度将一个二维数组的顺序位置转换为X坐标
|
||||
|[PosToCoordinateY](#PosToCoordinateY)|通过宽度将一个二维数组的顺序位置转换为Y坐标
|
||||
|[PointCopy](#PointCopy)|复制一个坐标数组
|
||||
|[PointToPosWithMulti](#PointToPosWithMulti)|将一组坐标转换为二维数组的顺序位置
|
||||
|[PosToPointWithMulti](#PosToPointWithMulti)|将一组二维数组的顺序位置转换为一组数组坐标
|
||||
|[PosSameRow](#PosSameRow)|返回两个顺序位置在同一宽度是否位于同一行
|
||||
|[DoublePointToCoordinate](#DoublePointToCoordinate)|将两个位置转换为 x1, y1, x2, y2 的坐标进行返回
|
||||
|[CalcProjectionPoint](#CalcProjectionPoint)|计算一个点到一条线段的最近点(即投影点)的。这个函数接收一个点和一条线段作为输入,线段由两个端点组成。
|
||||
|[GetAdjacentTranslatePos](#GetAdjacentTranslatePos)|获取一个连续位置的矩阵中,特定位置相邻的最多四个平移方向(上下左右)的位置
|
||||
|[GetAdjacentTranslateCoordinateXY](#GetAdjacentTranslateCoordinateXY)|获取一个基于 x、y 的二维矩阵中,特定位置相邻的最多四个平移方向(上下左右)的位置
|
||||
|[GetAdjacentTranslateCoordinateYX](#GetAdjacentTranslateCoordinateYX)|获取一个基于 y、x 的二维矩阵中,特定位置相邻的最多四个平移方向(上下左右)的位置
|
||||
|[GetAdjacentDiagonalsPos](#GetAdjacentDiagonalsPos)|获取一个连续位置的矩阵中,特定位置相邻的对角线最多四个方向的位置
|
||||
|[GetAdjacentDiagonalsCoordinateXY](#GetAdjacentDiagonalsCoordinateXY)|获取一个基于 x、y 的二维矩阵中,特定位置相邻的对角线最多四个方向的位置
|
||||
|[GetAdjacentDiagonalsCoordinateYX](#GetAdjacentDiagonalsCoordinateYX)|获取一个基于 tx 的二维矩阵中,特定位置相邻的对角线最多四个方向的位置
|
||||
|[GetAdjacentPos](#GetAdjacentPos)|获取一个连续位置的矩阵中,特定位置相邻的最多八个方向的位置
|
||||
|[GetAdjacentCoordinateXY](#GetAdjacentCoordinateXY)|获取一个基于 x、y 的二维矩阵中,特定位置相邻的最多八个方向的位置
|
||||
|[GetAdjacentCoordinateYX](#GetAdjacentCoordinateYX)|获取一个基于 yx 的二维矩阵中,特定位置相邻的最多八个方向的位置
|
||||
|[CoordinateMatrixToPosMatrix](#CoordinateMatrixToPosMatrix)|将二维矩阵转换为顺序的二维矩阵
|
||||
|[GetShapeCoverageAreaWithPoint](#GetShapeCoverageAreaWithPoint)|通过传入的一组坐标 points 计算一个图形覆盖的矩形范围
|
||||
|[GetShapeCoverageAreaWithPos](#GetShapeCoverageAreaWithPos)|通过传入的一组坐标 positions 计算一个图形覆盖的矩形范围
|
||||
|[CoverageAreaBoundless](#CoverageAreaBoundless)|将一个图形覆盖矩形范围设置为无边的
|
||||
|[GenerateShapeOnRectangle](#GenerateShapeOnRectangle)|生成一组二维坐标的形状
|
||||
|[GenerateShapeOnRectangleWithCoordinate](#GenerateShapeOnRectangleWithCoordinate)|生成一组二维坐标的形状
|
||||
|[GetExpressibleRectangleBySize](#GetExpressibleRectangleBySize)|获取一个宽高可表达的所有特定尺寸以上的矩形形状
|
||||
|[GetExpressibleRectangle](#GetExpressibleRectangle)|获取一个宽高可表达的所有矩形形状
|
||||
|[GetRectangleFullPointsByXY](#GetRectangleFullPointsByXY)|通过开始结束坐标获取一个矩形包含的所有点
|
||||
|[GetRectangleFullPoints](#GetRectangleFullPoints)|获取一个矩形填充满后包含的所有点
|
||||
|[GetRectangleFullPos](#GetRectangleFullPos)|获取一个矩形填充满后包含的所有位置
|
||||
|[CalcRectangleCentroid](#CalcRectangleCentroid)|计算矩形质心
|
||||
|[SetShapeStringHasBorder](#SetShapeStringHasBorder)|设置 Shape.String 是拥有边界的
|
||||
|[SetShapeStringNotHasBorder](#SetShapeStringNotHasBorder)|设置 Shape.String 是没有边界的
|
||||
|[NewShape](#NewShape)|通过多个点生成一个形状进行返回
|
||||
|[NewShapeWithString](#NewShapeWithString)|通过字符串将指定 rune 转换为点位置生成形状进行返回
|
||||
|[CalcBoundingRadius](#CalcBoundingRadius)|计算多边形转换为圆的半径
|
||||
|[CalcBoundingRadiusWithCentroid](#CalcBoundingRadiusWithCentroid)|计算多边形在特定质心下圆的半径
|
||||
|[CalcTriangleTwiceArea](#CalcTriangleTwiceArea)|计算由 a、b、c 三个点组成的三角形的面积的两倍
|
||||
|[IsPointOnEdge](#IsPointOnEdge)|检查点是否在 edges 的任意一条边上
|
||||
|[ProjectionPointToShape](#ProjectionPointToShape)|将一个点投影到一个多边形上,找到离该点最近的投影点,并返回投影点和距离
|
||||
|[WithShapeSearchRectangleLowerLimit](#WithShapeSearchRectangleLowerLimit)|通过矩形宽高下限的方式搜索
|
||||
|[WithShapeSearchRectangleUpperLimit](#WithShapeSearchRectangleUpperLimit)|通过矩形宽高上限的方式搜索
|
||||
|[WithShapeSearchRightAngle](#WithShapeSearchRightAngle)|通过直角的方式进行搜索
|
||||
|[WithShapeSearchOppositionDirection](#WithShapeSearchOppositionDirection)|通过限制对立方向的方式搜索
|
||||
|[WithShapeSearchDirectionCount](#WithShapeSearchDirectionCount)|通过限制方向数量的方式搜索
|
||||
|[WithShapeSearchDirectionCountLowerLimit](#WithShapeSearchDirectionCountLowerLimit)|通过限制特定方向数量下限的方式搜索
|
||||
|[WithShapeSearchDirectionCountUpperLimit](#WithShapeSearchDirectionCountUpperLimit)|通过限制特定方向数量上限的方式搜索
|
||||
|[WithShapeSearchDeduplication](#WithShapeSearchDeduplication)|通过去重的方式进行搜索
|
||||
|[WithShapeSearchPointCountLowerLimit](#WithShapeSearchPointCountLowerLimit)|通过限制图形构成的最小点数进行搜索
|
||||
|[WithShapeSearchPointCountUpperLimit](#WithShapeSearchPointCountUpperLimit)|通过限制图形构成的最大点数进行搜索
|
||||
|[WithShapeSearchAsc](#WithShapeSearchAsc)|通过升序的方式进行搜索
|
||||
|[WithShapeSearchDesc](#WithShapeSearchDesc)|通过降序的方式进行搜索
|
||||
|
||||
|
||||
> 结构体定义
|
||||
|
||||
|结构体|描述
|
||||
|:--|:--
|
||||
|[Circle](#circle)|圆形
|
||||
|[FloorPlan](#floorplan)|平面图
|
||||
|[Direction](#direction)|方向
|
||||
|[LineSegment](#linesegment)|通过两个点表示一根线段
|
||||
|[LineSegmentCap](#linesegmentcap)|可以包含一份额外数据的线段
|
||||
|[Point](#point)|表示了一个由 x、y 坐标组成的点
|
||||
|[PointCap](#pointcap)|表示了一个由 x、y 坐标组成的点,这个点具有一个数据容量
|
||||
|[Shape](#shape)|通过多个点表示了一个形状
|
||||
|[ShapeSearchOption](#shapesearchoption)|图形搜索可选项,用于 Shape.ShapeSearch 搜索支持
|
||||
|
||||
</details>
|
||||
|
||||
|
||||
#### func NewCircle(radius V, points int) Circle[V]
|
||||
<span id="NewCircle"></span>
|
||||
> 通过传入圆的半径和需要的点数量,生成一个圆
|
||||
***
|
||||
#### func CalcCircleCentroidDistance(circle1 Circle[V], circle2 Circle[V]) V
|
||||
<span id="CalcCircleCentroidDistance"></span>
|
||||
> 计算两个圆质心距离
|
||||
***
|
||||
#### func GetOppositionDirection(direction Direction) Direction
|
||||
<span id="GetOppositionDirection"></span>
|
||||
> 获取特定方向的对立方向
|
||||
***
|
||||
#### func GetDirectionNextWithCoordinate(direction Direction, x V, y V) (nx V, ny V)
|
||||
<span id="GetDirectionNextWithCoordinate"></span>
|
||||
> 获取特定方向上的下一个坐标
|
||||
***
|
||||
#### func GetDirectionNextWithPoint(direction Direction, point Point[V]) Point[V]
|
||||
<span id="GetDirectionNextWithPoint"></span>
|
||||
> 获取特定方向上的下一个坐标
|
||||
***
|
||||
#### func GetDirectionNextWithPos(direction Direction, width V, pos V) V
|
||||
<span id="GetDirectionNextWithPos"></span>
|
||||
> 获取位置在特定宽度和特定方向上的下一个位置
|
||||
> - 需要注意的是,在左右方向时,当下一个位置不在矩形区域内时,将会返回上一行的末位置或下一行的首位置
|
||||
***
|
||||
#### func CalcDirection(x1 V, y1 V, x2 V, y2 V) Direction
|
||||
<span id="CalcDirection"></span>
|
||||
> 计算点2位于点1的方向
|
||||
***
|
||||
#### func CalcDistanceWithCoordinate(x1 V, y1 V, x2 V, y2 V) V
|
||||
<span id="CalcDistanceWithCoordinate"></span>
|
||||
> 计算两点之间的距离
|
||||
***
|
||||
#### func CalcDistanceWithPoint(point1 Point[V], point2 Point[V]) V
|
||||
<span id="CalcDistanceWithPoint"></span>
|
||||
> 计算两点之间的距离
|
||||
***
|
||||
#### func CalcDistanceSquared(x1 V, y1 V, x2 V, y2 V) V
|
||||
<span id="CalcDistanceSquared"></span>
|
||||
> 计算两点之间的平方距离
|
||||
> - 这个函数的主要用途是在需要计算两点之间距离的情况下,但不需要得到实际的距离值,而只需要比较距离大小。因为平方根运算相对较为耗时,所以在只需要比较大小的情况下,通常会使用平方距离。
|
||||
***
|
||||
#### func CalcAngle(x1 V, y1 V, x2 V, y2 V) V
|
||||
<span id="CalcAngle"></span>
|
||||
> 计算点2位于点1之间的角度
|
||||
***
|
||||
#### func CalcNewCoordinate(x V, y V, angle V, distance V) (newX V, newY V)
|
||||
<span id="CalcNewCoordinate"></span>
|
||||
> 根据给定的x、y坐标、角度和距离计算新的坐标
|
||||
***
|
||||
#### func CalcRadianWithAngle(angle V) V
|
||||
<span id="CalcRadianWithAngle"></span>
|
||||
> 根据角度 angle 计算弧度
|
||||
***
|
||||
#### func CalcAngleDifference(angleA V, angleB V) V
|
||||
<span id="CalcAngleDifference"></span>
|
||||
> 计算两个角度之间的最小角度差
|
||||
***
|
||||
#### func CalcRayIsIntersect(x V, y V, angle V, shape Shape[V]) bool
|
||||
<span id="CalcRayIsIntersect"></span>
|
||||
> 根据给定的位置和角度生成射线,检测射线是否与多边形发生碰撞
|
||||
***
|
||||
#### func NewLineSegment(start Point[V], end Point[V]) LineSegment[V]
|
||||
<span id="NewLineSegment"></span>
|
||||
> 创建一根线段
|
||||
***
|
||||
#### func NewLineSegmentCap(start Point[V], end Point[V], data Data) LineSegmentCap[V, Data]
|
||||
<span id="NewLineSegmentCap"></span>
|
||||
> 创建一根包含数据的线段
|
||||
***
|
||||
#### func NewLineSegmentCapWithLine(line LineSegment[V], data Data) LineSegmentCap[V, Data]
|
||||
<span id="NewLineSegmentCapWithLine"></span>
|
||||
> 通过已有线段创建一根包含数据的线段
|
||||
***
|
||||
#### func ConvertLineSegmentGeneric(line LineSegment[V]) LineSegment[TO]
|
||||
<span id="ConvertLineSegmentGeneric"></span>
|
||||
> 转换线段的泛型类型为特定类型
|
||||
***
|
||||
#### func PointOnLineSegmentWithCoordinate(x1 V, y1 V, x2 V, y2 V, x V, y V) bool
|
||||
<span id="PointOnLineSegmentWithCoordinate"></span>
|
||||
> 通过一个线段两个点的位置和一个点的坐标,判断这个点是否在一条线段上
|
||||
***
|
||||
#### func PointOnLineSegmentWithPos(width V, pos1 V, pos2 V, pos V) bool
|
||||
<span id="PointOnLineSegmentWithPos"></span>
|
||||
> 通过一个线段两个点的位置和一个点的坐标,判断这个点是否在一条线段上
|
||||
***
|
||||
#### func PointOnLineSegmentWithPoint(point1 Point[V], point2 Point[V], point Point[V]) bool
|
||||
<span id="PointOnLineSegmentWithPoint"></span>
|
||||
> 通过一个线段两个点的位置和一个点的坐标,判断这个点是否在一条线段上
|
||||
***
|
||||
#### func PointOnLineSegmentWithCoordinateInBounds(x1 V, y1 V, x2 V, y2 V, x V, y V) bool
|
||||
<span id="PointOnLineSegmentWithCoordinateInBounds"></span>
|
||||
> 通过一个线段两个点的位置和一个点的坐标,判断这个点是否在一条线段上
|
||||
> - 与 PointOnLineSegmentWithCoordinate 不同的是, PointOnLineSegmentWithCoordinateInBounds 中会判断线段及点的位置是否正确
|
||||
***
|
||||
#### func PointOnLineSegmentWithPosInBounds(width V, pos1 V, pos2 V, pos V) bool
|
||||
<span id="PointOnLineSegmentWithPosInBounds"></span>
|
||||
> 通过一个线段两个点的位置和一个点的坐标,判断这个点是否在一条线段上
|
||||
> - 与 PointOnLineSegmentWithPos 不同的是, PointOnLineSegmentWithPosInBounds 中会判断线段及点的位置是否正确
|
||||
***
|
||||
#### func PointOnLineSegmentWithPointInBounds(point1 Point[V], point2 Point[V], point Point[V]) bool
|
||||
<span id="PointOnLineSegmentWithPointInBounds"></span>
|
||||
> 通过一个线段两个点的位置和一个点的坐标,判断这个点是否在一条线段上
|
||||
> - 与 PointOnLineSegmentWithPoint 不同的是, PointOnLineSegmentWithPointInBounds 中会判断线段及点的位置是否正确
|
||||
***
|
||||
#### func CalcLineSegmentIsCollinear(line1 LineSegment[V], line2 LineSegment[V], tolerance V) bool
|
||||
<span id="CalcLineSegmentIsCollinear"></span>
|
||||
> 检查两条线段在一个误差内是否共线
|
||||
> - 共线是指两条线段在同一直线上,即它们的延长线可以重合
|
||||
***
|
||||
#### func CalcLineSegmentIsOverlap(line1 LineSegment[V], line2 LineSegment[V]) (line LineSegment[V], overlap bool)
|
||||
<span id="CalcLineSegmentIsOverlap"></span>
|
||||
> 通过对点进行排序来检查两条共线线段是否重叠,返回重叠线段
|
||||
***
|
||||
#### func CalcLineSegmentIsIntersect(line1 LineSegment[V], line2 LineSegment[V]) bool
|
||||
<span id="CalcLineSegmentIsIntersect"></span>
|
||||
> 计算两条线段是否相交
|
||||
***
|
||||
#### func CalcLineSegmentSlope(line LineSegment[V]) V
|
||||
<span id="CalcLineSegmentSlope"></span>
|
||||
> 计算线段的斜率
|
||||
***
|
||||
#### func CalcLineSegmentIntercept(line LineSegment[V]) V
|
||||
<span id="CalcLineSegmentIntercept"></span>
|
||||
> 计算线段的截距
|
||||
***
|
||||
#### func NewPoint(x V, y V) Point[V]
|
||||
<span id="NewPoint"></span>
|
||||
> 创建一个由 x、y 坐标组成的点
|
||||
***
|
||||
#### func NewPointCap(x V, y V) PointCap[V, D]
|
||||
<span id="NewPointCap"></span>
|
||||
> 创建一个由 x、y 坐标组成的点,这个点具有一个数据容量
|
||||
***
|
||||
#### func NewPointCapWithData(x V, y V, data D) PointCap[V, D]
|
||||
<span id="NewPointCapWithData"></span>
|
||||
> 通过设置数据的方式创建一个由 x、y 坐标组成的点,这个点具有一个数据容量
|
||||
***
|
||||
#### func NewPointCapWithPoint(point Point[V], data D) PointCap[V, D]
|
||||
<span id="NewPointCapWithPoint"></span>
|
||||
> 通过设置数据的方式创建一个由已有坐标组成的点,这个点具有一个数据容量
|
||||
***
|
||||
#### func CoordinateToPoint(x V, y V) Point[V]
|
||||
<span id="CoordinateToPoint"></span>
|
||||
> 将坐标转换为x、y的坐标数组
|
||||
***
|
||||
#### func CoordinateToPos(width V, x V, y V) V
|
||||
<span id="CoordinateToPos"></span>
|
||||
> 将坐标转换为二维数组的顺序位置坐标
|
||||
> - 需要确保x的取值范围必须小于width,或者将会得到不正确的值
|
||||
***
|
||||
#### func PointToCoordinate(position Point[V]) (x V, y V)
|
||||
<span id="PointToCoordinate"></span>
|
||||
> 将坐标数组转换为x和y坐标
|
||||
***
|
||||
#### func PointToPos(width V, xy Point[V]) V
|
||||
<span id="PointToPos"></span>
|
||||
> 将坐标转换为二维数组的顺序位置
|
||||
> - 需要确保x的取值范围必须小于width,或者将会得到不正确的值
|
||||
***
|
||||
#### func PosToCoordinate(width V, pos V) (x V, y V)
|
||||
<span id="PosToCoordinate"></span>
|
||||
> 通过宽度将一个二维数组的顺序位置转换为xy坐标
|
||||
***
|
||||
#### func PosToPoint(width V, pos V) Point[V]
|
||||
<span id="PosToPoint"></span>
|
||||
> 通过宽度将一个二维数组的顺序位置转换为x、y的坐标数组
|
||||
***
|
||||
#### func PosToCoordinateX(width V, pos V) V
|
||||
<span id="PosToCoordinateX"></span>
|
||||
> 通过宽度将一个二维数组的顺序位置转换为X坐标
|
||||
***
|
||||
#### func PosToCoordinateY(width V, pos V) V
|
||||
<span id="PosToCoordinateY"></span>
|
||||
> 通过宽度将一个二维数组的顺序位置转换为Y坐标
|
||||
***
|
||||
#### func PointCopy(point Point[V]) Point[V]
|
||||
<span id="PointCopy"></span>
|
||||
> 复制一个坐标数组
|
||||
***
|
||||
#### func PointToPosWithMulti(width V, points ...Point[V]) []V
|
||||
<span id="PointToPosWithMulti"></span>
|
||||
> 将一组坐标转换为二维数组的顺序位置
|
||||
> - 需要确保x的取值范围必须小于width,或者将会得到不正确的值
|
||||
***
|
||||
#### func PosToPointWithMulti(width V, positions ...V) []Point[V]
|
||||
<span id="PosToPointWithMulti"></span>
|
||||
> 将一组二维数组的顺序位置转换为一组数组坐标
|
||||
***
|
||||
#### func PosSameRow(width V, pos1 V, pos2 V) bool
|
||||
<span id="PosSameRow"></span>
|
||||
> 返回两个顺序位置在同一宽度是否位于同一行
|
||||
***
|
||||
#### func DoublePointToCoordinate(point1 Point[V], point2 Point[V]) (x1 V, y1 V, x2 V, y2 V)
|
||||
<span id="DoublePointToCoordinate"></span>
|
||||
> 将两个位置转换为 x1, y1, x2, y2 的坐标进行返回
|
||||
***
|
||||
#### func CalcProjectionPoint(line LineSegment[V], point Point[V]) Point[V]
|
||||
<span id="CalcProjectionPoint"></span>
|
||||
> 计算一个点到一条线段的最近点(即投影点)的。这个函数接收一个点和一条线段作为输入,线段由两个端点组成。
|
||||
> - 该函数的主要用于需要计算一个点到一条线段的最近点的情况下
|
||||
***
|
||||
#### func GetAdjacentTranslatePos(matrix []T, width P, pos P) (result []P)
|
||||
<span id="GetAdjacentTranslatePos"></span>
|
||||
> 获取一个连续位置的矩阵中,特定位置相邻的最多四个平移方向(上下左右)的位置
|
||||
***
|
||||
#### func GetAdjacentTranslateCoordinateXY(matrix [][]T, x P, y P) (result []Point[P])
|
||||
<span id="GetAdjacentTranslateCoordinateXY"></span>
|
||||
> 获取一个基于 x、y 的二维矩阵中,特定位置相邻的最多四个平移方向(上下左右)的位置
|
||||
***
|
||||
#### func GetAdjacentTranslateCoordinateYX(matrix [][]T, x P, y P) (result []Point[P])
|
||||
<span id="GetAdjacentTranslateCoordinateYX"></span>
|
||||
> 获取一个基于 y、x 的二维矩阵中,特定位置相邻的最多四个平移方向(上下左右)的位置
|
||||
***
|
||||
#### func GetAdjacentDiagonalsPos(matrix []T, width P, pos P) (result []P)
|
||||
<span id="GetAdjacentDiagonalsPos"></span>
|
||||
> 获取一个连续位置的矩阵中,特定位置相邻的对角线最多四个方向的位置
|
||||
***
|
||||
#### func GetAdjacentDiagonalsCoordinateXY(matrix [][]T, x P, y P) (result []Point[P])
|
||||
<span id="GetAdjacentDiagonalsCoordinateXY"></span>
|
||||
> 获取一个基于 x、y 的二维矩阵中,特定位置相邻的对角线最多四个方向的位置
|
||||
***
|
||||
#### func GetAdjacentDiagonalsCoordinateYX(matrix [][]T, x P, y P) (result []Point[P])
|
||||
<span id="GetAdjacentDiagonalsCoordinateYX"></span>
|
||||
> 获取一个基于 tx 的二维矩阵中,特定位置相邻的对角线最多四个方向的位置
|
||||
***
|
||||
#### func GetAdjacentPos(matrix []T, width P, pos P) (result []P)
|
||||
<span id="GetAdjacentPos"></span>
|
||||
> 获取一个连续位置的矩阵中,特定位置相邻的最多八个方向的位置
|
||||
***
|
||||
#### func GetAdjacentCoordinateXY(matrix [][]T, x P, y P) (result []Point[P])
|
||||
<span id="GetAdjacentCoordinateXY"></span>
|
||||
> 获取一个基于 x、y 的二维矩阵中,特定位置相邻的最多八个方向的位置
|
||||
***
|
||||
#### func GetAdjacentCoordinateYX(matrix [][]T, x P, y P) (result []Point[P])
|
||||
<span id="GetAdjacentCoordinateYX"></span>
|
||||
> 获取一个基于 yx 的二维矩阵中,特定位置相邻的最多八个方向的位置
|
||||
***
|
||||
#### func CoordinateMatrixToPosMatrix(matrix [][]V) (width int, posMatrix []V)
|
||||
<span id="CoordinateMatrixToPosMatrix"></span>
|
||||
> 将二维矩阵转换为顺序的二维矩阵
|
||||
***
|
||||
#### func GetShapeCoverageAreaWithPoint(points ...Point[V]) (left V, right V, top V, bottom V)
|
||||
<span id="GetShapeCoverageAreaWithPoint"></span>
|
||||
> 通过传入的一组坐标 points 计算一个图形覆盖的矩形范围
|
||||
***
|
||||
#### func GetShapeCoverageAreaWithPos(width V, positions ...V) (left V, right V, top V, bottom V)
|
||||
<span id="GetShapeCoverageAreaWithPos"></span>
|
||||
> 通过传入的一组坐标 positions 计算一个图形覆盖的矩形范围
|
||||
***
|
||||
#### func CoverageAreaBoundless(l V, r V, t V, b V) (left V, right V, top V, bottom V)
|
||||
<span id="CoverageAreaBoundless"></span>
|
||||
> 将一个图形覆盖矩形范围设置为无边的
|
||||
> - 无边化表示会将多余的部分进行裁剪,例如图形左边从 2 开始的时候,那么左边将会被裁剪到从 0 开始
|
||||
***
|
||||
#### func GenerateShapeOnRectangle(points ...Point[V]) (result []PointCap[V, bool])
|
||||
<span id="GenerateShapeOnRectangle"></span>
|
||||
> 生成一组二维坐标的形状
|
||||
> - 这个形状将被在一个刚好能容纳形状的矩形中表示
|
||||
> - 为 true 的位置表示了形状的每一个点
|
||||
***
|
||||
#### func GenerateShapeOnRectangleWithCoordinate(points ...Point[V]) (result [][]bool)
|
||||
<span id="GenerateShapeOnRectangleWithCoordinate"></span>
|
||||
> 生成一组二维坐标的形状
|
||||
> - 这个形状将被在一个刚好能容纳形状的矩形中表示
|
||||
> - 为 true 的位置表示了形状的每一个点
|
||||
***
|
||||
#### func GetExpressibleRectangleBySize(width V, height V, minWidth V, minHeight V) (result []Point[V])
|
||||
<span id="GetExpressibleRectangleBySize"></span>
|
||||
> 获取一个宽高可表达的所有特定尺寸以上的矩形形状
|
||||
> - 返回值表示了每一个矩形右下角的x,y位置(左上角始终为0, 0)
|
||||
> - 矩形尺寸由大到小
|
||||
***
|
||||
#### func GetExpressibleRectangle(width V, height V) (result []Point[V])
|
||||
<span id="GetExpressibleRectangle"></span>
|
||||
> 获取一个宽高可表达的所有矩形形状
|
||||
> - 返回值表示了每一个矩形右下角的x,y位置(左上角始终为0, 0)
|
||||
> - 矩形尺寸由大到小
|
||||
***
|
||||
#### func GetRectangleFullPointsByXY(startX V, startY V, endX V, endY V) (result []Point[V])
|
||||
<span id="GetRectangleFullPointsByXY"></span>
|
||||
> 通过开始结束坐标获取一个矩形包含的所有点
|
||||
> - 例如 1,1 到 2,2 的矩形结果为 1,1 2,1 1,2 2,2
|
||||
***
|
||||
#### func GetRectangleFullPoints(width V, height V) (result []Point[V])
|
||||
<span id="GetRectangleFullPoints"></span>
|
||||
> 获取一个矩形填充满后包含的所有点
|
||||
***
|
||||
#### func GetRectangleFullPos(width V, height V) (result []V)
|
||||
<span id="GetRectangleFullPos"></span>
|
||||
> 获取一个矩形填充满后包含的所有位置
|
||||
***
|
||||
#### func CalcRectangleCentroid(shape Shape[V]) Point[V]
|
||||
<span id="CalcRectangleCentroid"></span>
|
||||
> 计算矩形质心
|
||||
> - 非多边形质心计算,仅为顶点的平均值 - 该区域中多边形因子的适当质心
|
||||
***
|
||||
#### func SetShapeStringHasBorder()
|
||||
<span id="SetShapeStringHasBorder"></span>
|
||||
> 设置 Shape.String 是拥有边界的
|
||||
***
|
||||
#### func SetShapeStringNotHasBorder()
|
||||
<span id="SetShapeStringNotHasBorder"></span>
|
||||
> 设置 Shape.String 是没有边界的
|
||||
***
|
||||
#### func NewShape(points ...Point[V]) Shape[V]
|
||||
<span id="NewShape"></span>
|
||||
> 通过多个点生成一个形状进行返回
|
||||
***
|
||||
#### func NewShapeWithString(rows []string, point rune) (shape Shape[V])
|
||||
<span id="NewShapeWithString"></span>
|
||||
> 通过字符串将指定 rune 转换为点位置生成形状进行返回
|
||||
> - 每个点的顺序从上到下,从左到右
|
||||
***
|
||||
#### func CalcBoundingRadius(shape Shape[V]) V
|
||||
<span id="CalcBoundingRadius"></span>
|
||||
> 计算多边形转换为圆的半径
|
||||
***
|
||||
#### func CalcBoundingRadiusWithCentroid(shape Shape[V], centroid Point[V]) V
|
||||
<span id="CalcBoundingRadiusWithCentroid"></span>
|
||||
> 计算多边形在特定质心下圆的半径
|
||||
***
|
||||
#### func CalcTriangleTwiceArea(a Point[V], b Point[V], c Point[V]) V
|
||||
<span id="CalcTriangleTwiceArea"></span>
|
||||
> 计算由 a、b、c 三个点组成的三角形的面积的两倍
|
||||
***
|
||||
#### func IsPointOnEdge(edges []LineSegment[V], point Point[V]) bool
|
||||
<span id="IsPointOnEdge"></span>
|
||||
> 检查点是否在 edges 的任意一条边上
|
||||
***
|
||||
#### func ProjectionPointToShape(point Point[V], shape Shape[V]) Point[V], V
|
||||
<span id="ProjectionPointToShape"></span>
|
||||
> 将一个点投影到一个多边形上,找到离该点最近的投影点,并返回投影点和距离
|
||||
***
|
||||
#### func WithShapeSearchRectangleLowerLimit(minWidth int, minHeight int) ShapeSearchOption
|
||||
<span id="WithShapeSearchRectangleLowerLimit"></span>
|
||||
> 通过矩形宽高下限的方式搜索
|
||||
***
|
||||
#### func WithShapeSearchRectangleUpperLimit(maxWidth int, maxHeight int) ShapeSearchOption
|
||||
<span id="WithShapeSearchRectangleUpperLimit"></span>
|
||||
> 通过矩形宽高上限的方式搜索
|
||||
***
|
||||
#### func WithShapeSearchRightAngle() ShapeSearchOption
|
||||
<span id="WithShapeSearchRightAngle"></span>
|
||||
> 通过直角的方式进行搜索
|
||||
***
|
||||
#### func WithShapeSearchOppositionDirection(direction Direction) ShapeSearchOption
|
||||
<span id="WithShapeSearchOppositionDirection"></span>
|
||||
> 通过限制对立方向的方式搜索
|
||||
> - 对立方向例如上不能与下共存
|
||||
***
|
||||
#### func WithShapeSearchDirectionCount(count int) ShapeSearchOption
|
||||
<span id="WithShapeSearchDirectionCount"></span>
|
||||
> 通过限制方向数量的方式搜索
|
||||
***
|
||||
#### func WithShapeSearchDirectionCountLowerLimit(direction Direction, count int) ShapeSearchOption
|
||||
<span id="WithShapeSearchDirectionCountLowerLimit"></span>
|
||||
> 通过限制特定方向数量下限的方式搜索
|
||||
***
|
||||
#### func WithShapeSearchDirectionCountUpperLimit(direction Direction, count int) ShapeSearchOption
|
||||
<span id="WithShapeSearchDirectionCountUpperLimit"></span>
|
||||
> 通过限制特定方向数量上限的方式搜索
|
||||
***
|
||||
#### func WithShapeSearchDeduplication() ShapeSearchOption
|
||||
<span id="WithShapeSearchDeduplication"></span>
|
||||
> 通过去重的方式进行搜索
|
||||
> - 去重方式中每个点仅会被使用一次
|
||||
***
|
||||
#### func WithShapeSearchPointCountLowerLimit(lowerLimit int) ShapeSearchOption
|
||||
<span id="WithShapeSearchPointCountLowerLimit"></span>
|
||||
> 通过限制图形构成的最小点数进行搜索
|
||||
> - 当搜索到的图形的点数量低于 lowerLimit 时,将被忽略
|
||||
***
|
||||
#### func WithShapeSearchPointCountUpperLimit(upperLimit int) ShapeSearchOption
|
||||
<span id="WithShapeSearchPointCountUpperLimit"></span>
|
||||
> 通过限制图形构成的最大点数进行搜索
|
||||
> - 当搜索到的图形的点数量大于 upperLimit 时,将被忽略
|
||||
***
|
||||
#### func WithShapeSearchAsc() ShapeSearchOption
|
||||
<span id="WithShapeSearchAsc"></span>
|
||||
> 通过升序的方式进行搜索
|
||||
***
|
||||
#### func WithShapeSearchDesc() ShapeSearchOption
|
||||
<span id="WithShapeSearchDesc"></span>
|
||||
> 通过降序的方式进行搜索
|
||||
***
|
||||
### Circle
|
||||
圆形
|
||||
```go
|
||||
type Circle[V generic.SignedNumber] struct {
|
||||
Shape[V]
|
||||
}
|
||||
```
|
||||
#### func (Circle) Radius() V
|
||||
> 获取圆形半径
|
||||
***
|
||||
#### func (Circle) Centroid() Point[V]
|
||||
> 获取圆形质心位置
|
||||
***
|
||||
#### func (Circle) Overlap(circle Circle[V]) bool
|
||||
> 与另一个圆是否发生重叠
|
||||
***
|
||||
#### func (Circle) Area() V
|
||||
> 获取圆形面积
|
||||
***
|
||||
#### func (Circle) Length() V
|
||||
> 获取圆的周长
|
||||
***
|
||||
#### func (Circle) CentroidDistance(circle Circle[V]) V
|
||||
> 计算与另一个圆的质心距离
|
||||
***
|
||||
### FloorPlan
|
||||
平面图
|
||||
```go
|
||||
type FloorPlan struct{}
|
||||
```
|
||||
#### func (FloorPlan) IsFree(point Point[int]) bool
|
||||
> 检查位置是否为空格
|
||||
***
|
||||
#### func (FloorPlan) IsInBounds(point Point[int]) bool
|
||||
> 检查位置是否在边界内
|
||||
***
|
||||
#### func (FloorPlan) Put(point Point[int], c rune)
|
||||
> 设置平面图特定位置的字符
|
||||
***
|
||||
#### func (FloorPlan) String() string
|
||||
> 获取平面图结果
|
||||
***
|
||||
### Direction
|
||||
方向
|
||||
```go
|
||||
type Direction struct{}
|
||||
```
|
||||
### LineSegment
|
||||
通过两个点表示一根线段
|
||||
```go
|
||||
type LineSegment[V generic.SignedNumber] struct{}
|
||||
```
|
||||
#### func (LineSegment) GetPoints() [2]Point[V]
|
||||
> 获取该线段的两个点
|
||||
***
|
||||
#### func (LineSegment) GetStart() Point[V]
|
||||
> 获取该线段的开始位置
|
||||
***
|
||||
#### func (LineSegment) GetEnd() Point[V]
|
||||
> 获取该线段的结束位置
|
||||
***
|
||||
#### func (LineSegment) GetLength() V
|
||||
> 获取该线段的长度
|
||||
***
|
||||
### LineSegmentCap
|
||||
可以包含一份额外数据的线段
|
||||
```go
|
||||
type LineSegmentCap[V generic.SignedNumber, Data any] struct {
|
||||
LineSegment[V]
|
||||
Data Data
|
||||
}
|
||||
```
|
||||
### Point
|
||||
表示了一个由 x、y 坐标组成的点
|
||||
```go
|
||||
type Point[V generic.SignedNumber] struct{}
|
||||
```
|
||||
#### func (Point) GetX() V
|
||||
> 返回该点的 x 坐标
|
||||
***
|
||||
#### func (Point) GetY() V
|
||||
> 返回该点的 y 坐标
|
||||
***
|
||||
#### func (Point) GetXY() (x V, y V)
|
||||
> 返回该点的 x、y 坐标
|
||||
***
|
||||
#### func (Point) GetPos(width V) V
|
||||
> 返回该点位于特定宽度的二维数组的顺序位置
|
||||
***
|
||||
#### func (Point) GetOffset(x V, y V) Point[V]
|
||||
> 获取偏移后的新坐标
|
||||
***
|
||||
#### func (Point) Negative() bool
|
||||
> 返回该点是否是一个负数坐标
|
||||
***
|
||||
#### func (Point) OutOf(minWidth V, minHeight V, maxWidth V, maxHeight V) bool
|
||||
> 返回该点在特定宽高下是否越界f
|
||||
***
|
||||
#### func (Point) Equal(point Point[V]) bool
|
||||
> 返回两个点是否相等
|
||||
***
|
||||
#### func (Point) Copy() Point[V]
|
||||
> 复制一个点位置
|
||||
***
|
||||
#### func (Point) Add(point Point[V]) Point[V]
|
||||
> 得到加上 point 后的点
|
||||
***
|
||||
#### func (Point) Sub(point Point[V]) Point[V]
|
||||
> 得到减去 point 后的点
|
||||
***
|
||||
#### func (Point) Mul(point Point[V]) Point[V]
|
||||
> 得到乘以 point 后的点
|
||||
***
|
||||
#### func (Point) Div(point Point[V]) Point[V]
|
||||
> 得到除以 point 后的点
|
||||
***
|
||||
#### func (Point) Abs() Point[V]
|
||||
> 返回位置的绝对值
|
||||
***
|
||||
#### func (Point) Max(point Point[V]) Point[V]
|
||||
> 返回两个位置中每个维度的最大值组成的新的位置
|
||||
***
|
||||
#### func (Point) Min(point Point[V]) Point[V]
|
||||
> 返回两个位置中每个维度的最小值组成的新的位置
|
||||
***
|
||||
### PointCap
|
||||
表示了一个由 x、y 坐标组成的点,这个点具有一个数据容量
|
||||
```go
|
||||
type PointCap[V generic.SignedNumber, D any] struct {
|
||||
Point[V]
|
||||
Data D
|
||||
}
|
||||
```
|
||||
### Shape
|
||||
通过多个点表示了一个形状
|
||||
```go
|
||||
type Shape[V generic.SignedNumber] struct{}
|
||||
```
|
||||
#### func (Shape) Points() []Point[V]
|
||||
> 获取这个形状的所有点
|
||||
***
|
||||
#### func (Shape) PointCount() int
|
||||
> 获取这个形状的点数量
|
||||
***
|
||||
#### func (Shape) Contains(point Point[V]) bool
|
||||
> 返回该形状中是否包含点
|
||||
***
|
||||
#### func (Shape) ToCircle() Circle[V]
|
||||
> 将形状转换为圆形进行处理
|
||||
> - 当形状非圆形时将会产生意外情况
|
||||
***
|
||||
#### func (Shape) String() string
|
||||
> 将该形状转换为可视化的字符串进行返回
|
||||
***
|
||||
#### func (Shape) ShapeSearch(options ...ShapeSearchOption) (result []Shape[V])
|
||||
> 获取该形状中包含的所有图形组合及其位置
|
||||
> - 需要注意的是,即便图形最终表示为相同的,但是只要位置组合顺序不同,那么也将被认定为一种图形组合
|
||||
> - [[1 0] [1 1] [1 2]] 和 [[1 1] [1 0] [1 2]] 可以被视为两个图形组合
|
||||
> - 返回的坐标为原始形状的坐标
|
||||
>
|
||||
> 可通过可选项对搜索结果进行过滤
|
||||
***
|
||||
#### func (Shape) Edges() (edges []LineSegment[V])
|
||||
> 获取该形状每一条边
|
||||
> - 该形状需要最少由3个点组成,否则将不会返回任意一边
|
||||
***
|
||||
#### func (Shape) IsPointOnEdge(point Point[V]) bool
|
||||
> 检查点是否在该形状的一条边上
|
||||
***
|
||||
### ShapeSearchOption
|
||||
图形搜索可选项,用于 Shape.ShapeSearch 搜索支持
|
||||
```go
|
||||
type ShapeSearchOption struct{}
|
||||
```
|
||||
64
utils/geometry/astar/README.md
Normal file
64
utils/geometry/astar/README.md
Normal file
@@ -0,0 +1,64 @@
|
||||
# Astar
|
||||
|
||||
astar 提供用于实现 A* 算法的函数和数据结构。A* 算法是一种常用的路径搜索算法,用于在图形或网络中找到最短路径。该包旨在简化 A* 算法的实现过程,并提供一致的接口和易于使用的功能。
|
||||
主要特性:
|
||||
- 图形表示:astar 包支持使用图形或网络来表示路径搜索的环境。您可以定义节点和边,以构建图形,并在其中执行路径搜索。
|
||||
- A* 算法:该包提供了 A* 算法的实现,用于在图形中找到最短路径。A* 算法使用启发式函数来评估节点的优先级,并选择最有希望的节点进行扩展,以达到最短路径的目标。
|
||||
- 自定义启发式函数:您可以根据具体问题定义自己的启发式函数,以指导 A* 算法的搜索过程。启发式函数用于估计从当前节点到目标节点的代价,以帮助算法选择最佳路径。
|
||||
- 可定制性:astar 包提供了一些可定制的选项,以满足不同场景下的需求。您可以设置节点的代价、边的权重等参数,以调整算法的行为。
|
||||
|
||||
[](https://pkg.go.dev/github.com/kercylan98/minotaur/astar)
|
||||

|
||||
|
||||
## 目录
|
||||
列出了该 `package` 下所有的函数,可通过目录进行快捷跳转 ❤️
|
||||
<details>
|
||||
<summary>展开 / 折叠目录</summary
|
||||
|
||||
|
||||
> 包级函数定义
|
||||
|
||||
|函数|描述
|
||||
|:--|:--
|
||||
|[Find](#Find)|使用 A* 算法在导航网格上查找从起点到终点的最短路径,并返回路径上的节点序列。
|
||||
|
||||
|
||||
> 结构体定义
|
||||
|
||||
|结构体|描述
|
||||
|:--|:--
|
||||
|[Graph](#graph)|适用于 A* 算法的图数据结构接口定义,表示导航网格,其中包含了节点和连接节点的边。
|
||||
|
||||
</details>
|
||||
|
||||
|
||||
#### func Find(graph Graph[Node], start Node, end Node, cost func (a Node) V, heuristic func (a Node) V) []Node
|
||||
<span id="Find"></span>
|
||||
> 使用 A* 算法在导航网格上查找从起点到终点的最短路径,并返回路径上的节点序列。
|
||||
>
|
||||
> 参数:
|
||||
> - graph: 图对象,类型为 Graph[Node],表示导航网格。
|
||||
> - start: 起点节点,类型为 Node,表示路径的起点。
|
||||
> - end: 终点节点,类型为 Node,表示路径的终点。
|
||||
> - cost: 路径代价函数,类型为 func(a, b Node) V,用于计算两个节点之间的代价。
|
||||
> - heuristic: 启发函数,类型为 func(a, b Node) V,用于估计从当前节点到目标节点的启发式代价。
|
||||
>
|
||||
> 返回值:
|
||||
> - []Node: 节点序列,表示从起点到终点的最短路径。如果找不到路径,则返回空序列。
|
||||
>
|
||||
> 注意事项:
|
||||
> - graph 对象表示导航网格,其中包含了节点和连接节点的边。
|
||||
> - start 和 end 分别表示路径的起点和终点。
|
||||
> - cost 函数用于计算两个节点之间的代价,可以根据实际情况自定义实现。
|
||||
> - heuristic 函数用于估计从当前节点到目标节点的启发式代价,可以根据实际情况自定义实现。
|
||||
> - 函数使用了 A* 算法来搜索最短路径。
|
||||
> - 函数内部使用了堆数据结构来管理待处理的节点。
|
||||
> - 函数返回一个节点序列,表示从起点到终点的最短路径。如果找不到路径,则返回空序列。
|
||||
***
|
||||
### Graph
|
||||
适用于 A* 算法的图数据结构接口定义,表示导航网格,其中包含了节点和连接节点的边。
|
||||
```go
|
||||
type Graph[Node comparable] struct{}
|
||||
```
|
||||
#### func (Graph) Neighbours(point geometry.Point[int]) []geometry.Point[int]
|
||||
***
|
||||
81
utils/geometry/dp/README.md
Normal file
81
utils/geometry/dp/README.md
Normal file
@@ -0,0 +1,81 @@
|
||||
# Dp
|
||||
|
||||
dp (DistributionPattern) 提供用于在二维数组中根据不同的特征标记为数组成员建立分布链接的函数和数据结构。该包的目标是实现快速查找与给定位置成员具有相同特征且位置紧邻的其他成员。
|
||||
主要特性:
|
||||
- 分布链接机制:dp 包提供了一种分布链接的机制,可以根据成员的特征将它们链接在一起。这样,可以快速查找与给定成员具有相同特征且位置紧邻的其他成员。
|
||||
- 二维数组支持:该包支持在二维数组中建立分布链接。可以将二维数组中的成员视为节点,并根据其特征进行链接。
|
||||
- 快速查找功能:使用 dp 包提供的函数,可以快速查找与给定位置成员具有相同特征且位置紧邻的其他成员。这有助于在二维数组中进行相关性分析或查找相邻成员。
|
||||
|
||||
[](https://pkg.go.dev/github.com/kercylan98/minotaur/dp)
|
||||

|
||||
|
||||
## 目录
|
||||
列出了该 `package` 下所有的函数,可通过目录进行快捷跳转 ❤️
|
||||
<details>
|
||||
<summary>展开 / 折叠目录</summary
|
||||
|
||||
|
||||
> 包级函数定义
|
||||
|
||||
|函数|描述
|
||||
|:--|:--
|
||||
|[NewDistributionPattern](#NewDistributionPattern)|构建一个分布图实例
|
||||
|
||||
|
||||
> 结构体定义
|
||||
|
||||
|结构体|描述
|
||||
|:--|:--
|
||||
|[DistributionPattern](#distributionpattern)|分布图
|
||||
|[Link](#link)|暂无描述...
|
||||
|
||||
</details>
|
||||
|
||||
|
||||
#### func NewDistributionPattern(sameKindVerifyHandle func (itemA Item) bool) *DistributionPattern[Item]
|
||||
<span id="NewDistributionPattern"></span>
|
||||
> 构建一个分布图实例
|
||||
***
|
||||
### DistributionPattern
|
||||
分布图
|
||||
```go
|
||||
type DistributionPattern[Item any] struct {
|
||||
matrix []Item
|
||||
links map[int]map[int]Item
|
||||
sameKindVerifyHandle func(itemA Item) bool
|
||||
width int
|
||||
usePos bool
|
||||
}
|
||||
```
|
||||
#### func (*DistributionPattern) GetLinks(pos int) (result []Link[Item])
|
||||
> 获取关联的成员
|
||||
> - 其中包含传入的 pos 成员
|
||||
***
|
||||
#### func (*DistributionPattern) HasLink(pos int) bool
|
||||
> 检查一个位置是否包含除它本身外的其他关联成员
|
||||
***
|
||||
#### func (*DistributionPattern) LoadMatrix(matrix [][]Item)
|
||||
> 通过二维矩阵加载分布图
|
||||
> - 通过该函数加载的分布图使用的矩阵是复制后的矩阵,因此无法直接通过刷新(Refresh)来更新分布关系
|
||||
> - 需要通过直接刷新的方式请使用 LoadMatrixWithPos
|
||||
***
|
||||
#### func (*DistributionPattern) LoadMatrixWithPos(width int, matrix []Item)
|
||||
> 通过二维矩阵加载分布图
|
||||
***
|
||||
#### func (*DistributionPattern) Refresh(pos int)
|
||||
> 刷新特定位置的分布关系
|
||||
> - 由于 LoadMatrix 的矩阵是复制后的矩阵,所以任何外部的改动都不会影响到分布图的变化,在这种情况下,刷新将没有任何意义
|
||||
> - 需要通过直接刷新的方式请使用 LoadMatrixWithPos 加载矩阵,或者通过 RefreshWithItem 函数进行刷新
|
||||
***
|
||||
#### func (*DistributionPattern) RefreshWithItem(pos int, item Item)
|
||||
> 通过特定的成员刷新特定位置的分布关系
|
||||
> - 如果矩阵通过 LoadMatrixWithPos 加载,将会重定向至 Refresh
|
||||
***
|
||||
### Link
|
||||
|
||||
```go
|
||||
type Link[V any] struct {
|
||||
Pos int
|
||||
Item V
|
||||
}
|
||||
```
|
||||
93
utils/geometry/matrix/README.md
Normal file
93
utils/geometry/matrix/README.md
Normal file
@@ -0,0 +1,93 @@
|
||||
# Matrix
|
||||
|
||||
matrix 提供了一个简单的二维数组的实现
|
||||
|
||||
[](https://pkg.go.dev/github.com/kercylan98/minotaur/matrix)
|
||||

|
||||
|
||||
## 目录
|
||||
列出了该 `package` 下所有的函数,可通过目录进行快捷跳转 ❤️
|
||||
<details>
|
||||
<summary>展开 / 折叠目录</summary
|
||||
|
||||
|
||||
> 包级函数定义
|
||||
|
||||
|函数|描述
|
||||
|:--|:--
|
||||
|[NewMatrix](#NewMatrix)|生成特定宽高的二维矩阵
|
||||
|
||||
|
||||
> 结构体定义
|
||||
|
||||
|结构体|描述
|
||||
|:--|:--
|
||||
|[Matrix](#matrix)|二维矩阵
|
||||
|
||||
</details>
|
||||
|
||||
|
||||
#### func NewMatrix(width int, height int) *Matrix[T]
|
||||
<span id="NewMatrix"></span>
|
||||
> 生成特定宽高的二维矩阵
|
||||
> - 虽然提供了通过x、y坐标的操作函数,但是建议无论如何使用pos进行处理
|
||||
> - 该矩阵为XY,而非YX
|
||||
***
|
||||
### Matrix
|
||||
二维矩阵
|
||||
```go
|
||||
type Matrix[T any] struct {
|
||||
w int
|
||||
h int
|
||||
m []T
|
||||
}
|
||||
```
|
||||
#### func (*Matrix) GetWidth() int
|
||||
> 获取二维矩阵宽度
|
||||
***
|
||||
#### func (*Matrix) GetHeight() int
|
||||
> 获取二维矩阵高度
|
||||
***
|
||||
#### func (*Matrix) GetWidth2Height() (width int, height int)
|
||||
> 获取二维矩阵的宽度和高度
|
||||
***
|
||||
#### func (*Matrix) GetMatrix() [][]T
|
||||
> 获取二维矩阵
|
||||
> - 通常建议使用 GetMatrixWithPos 进行处理这样将拥有更高的效率
|
||||
***
|
||||
#### func (*Matrix) GetMatrixWithPos() []T
|
||||
> 获取顺序的矩阵
|
||||
***
|
||||
#### func (*Matrix) Get(x int, y int) (value T)
|
||||
> 获取特定坐标的内容
|
||||
***
|
||||
#### func (*Matrix) GetExist(x int, y int) (value T, exist bool)
|
||||
> 获取特定坐标的内容,如果不存在则返回 false
|
||||
***
|
||||
#### func (*Matrix) GetWithPos(pos int) (value T)
|
||||
> 获取特定坐标的内容
|
||||
***
|
||||
#### func (*Matrix) Set(x int, y int, data T)
|
||||
> 设置特定坐标的内容
|
||||
***
|
||||
#### func (*Matrix) SetWithPos(pos int, data T)
|
||||
> 设置特定坐标的内容
|
||||
***
|
||||
#### func (*Matrix) Swap(x1 int, y1 int, x2 int, y2 int)
|
||||
> 交换两个位置的内容
|
||||
***
|
||||
#### func (*Matrix) SwapWithPos(pos1 int, pos2 int)
|
||||
> 交换两个位置的内容
|
||||
***
|
||||
#### func (*Matrix) TrySwap(x1 int, y1 int, x2 int, y2 int, expressionHandle func (matrix *Matrix[T]) bool)
|
||||
> 尝试交换两个位置的内容,交换后不满足表达式时进行撤销
|
||||
***
|
||||
#### func (*Matrix) TrySwapWithPos(pos1 int, pos2 int, expressionHandle func (matrix *Matrix[T]) bool)
|
||||
> 尝试交换两个位置的内容,交换后不满足表达式时进行撤销
|
||||
***
|
||||
#### func (*Matrix) FillFull(generateHandle func (x int) T)
|
||||
> 根据提供的生成器填充整个矩阵
|
||||
***
|
||||
#### func (*Matrix) FillFullWithPos(generateHandle func (pos int) T)
|
||||
> 根据提供的生成器填充整个矩阵
|
||||
***
|
||||
97
utils/geometry/navmesh/README.md
Normal file
97
utils/geometry/navmesh/README.md
Normal file
@@ -0,0 +1,97 @@
|
||||
# Navmesh
|
||||
|
||||
navmesh 提供了用于导航网格处理的函数和数据结构。导航网格是一种常用的数据结构,用于在游戏开发和虚拟环境中进行路径规划和导航。该包旨在简化导航网格的创建、查询和操作过程,并提供高效的导航功能。
|
||||
主要特性:
|
||||
- 导航网格表示:navmesh 包支持使用导航网格来表示虚拟环境中的可行走区域和障碍物。您可以定义多边形区域和连接关系,以构建导航网格,并在其中执行路径规划和导航。
|
||||
- 导航算法:采用了 A* 算法作为导航算法,用于在导航网格中找到最短路径或最优路径。这些算法使用启发式函数和代价评估来指导路径搜索,并提供高效的路径规划能力。
|
||||
|
||||
[](https://pkg.go.dev/github.com/kercylan98/minotaur/navmesh)
|
||||

|
||||
|
||||
## 目录
|
||||
列出了该 `package` 下所有的函数,可通过目录进行快捷跳转 ❤️
|
||||
<details>
|
||||
<summary>展开 / 折叠目录</summary
|
||||
|
||||
|
||||
> 包级函数定义
|
||||
|
||||
|函数|描述
|
||||
|:--|:--
|
||||
|[NewNavMesh](#NewNavMesh)|创建一个新的导航网格,并返回一个指向该导航网格的指针。
|
||||
|
||||
|
||||
> 结构体定义
|
||||
|
||||
|结构体|描述
|
||||
|:--|:--
|
||||
|[NavMesh](#navmesh)|暂无描述...
|
||||
|
||||
</details>
|
||||
|
||||
|
||||
#### func NewNavMesh(shapes []geometry.Shape[V], meshShrinkAmount V) *NavMesh[V]
|
||||
<span id="NewNavMesh"></span>
|
||||
> 创建一个新的导航网格,并返回一个指向该导航网格的指针。
|
||||
>
|
||||
> 参数:
|
||||
> - shapes: 形状切片,类型为 []geometry.Shape[V],表示导航网格中的形状。
|
||||
> - meshShrinkAmount: 网格缩小量,类型为 V,表示导航网格的缩小量。
|
||||
>
|
||||
> 返回值:
|
||||
> - *NavMesh[V]: 指向创建的导航网格的指针。
|
||||
>
|
||||
> 注意事项:
|
||||
> - 导航网格的形状可以是任何几何形状。
|
||||
> - meshShrinkAmount 表示导航网格的缩小量,用于在形状之间创建链接时考虑形状的缩小效果。
|
||||
> - 函数内部使用了泛型类型参数 V,可以根据需要指定形状的坐标类型。
|
||||
> - 函数返回一个指向创建的导航网格的指针。
|
||||
>
|
||||
> 使用建议:
|
||||
> - 确保 NavMesh 计算精度的情况下,V 建议使用 float64 类型
|
||||
***
|
||||
### NavMesh
|
||||
|
||||
```go
|
||||
type NavMesh[V generic.SignedNumber] struct {
|
||||
meshShapes []*shape[V]
|
||||
meshShrinkAmount V
|
||||
}
|
||||
```
|
||||
#### func (*NavMesh) Neighbours(node *shape[V]) []*shape[V]
|
||||
> 实现 astar.Graph 的接口,用于向 A* 算法提供相邻图形
|
||||
***
|
||||
#### func (*NavMesh) Find(point geometry.Point[V], maxDistance V) (distance V, findPoint geometry.Point[V], findShape geometry.Shape[V])
|
||||
> 用于在 NavMesh 中查找离给定点最近的形状,并返回距离、找到的点和找到的形状。
|
||||
>
|
||||
> 参数:
|
||||
> - point: 给定的点,类型为 geometry.Point[V],表示一个 V 维度的点坐标。
|
||||
> - maxDistance: 最大距离,类型为 V,表示查找的最大距离限制。
|
||||
>
|
||||
> 返回值:
|
||||
> - distance: 距离,类型为 V,表示离给定点最近的形状的距离。
|
||||
> - findPoint: 找到的点,类型为 geometry.Point[V],表示离给定点最近的点坐标。
|
||||
> - findShape: 找到的形状,类型为 geometry.Shape[V],表示离给定点最近的形状。
|
||||
>
|
||||
> 注意事项:
|
||||
> - 如果给定点在 NavMesh 中的某个形状内部或者在形状的边上,距离为 0,找到的形状为该形状,找到的点为给定点。
|
||||
> - 如果给定点不在任何形状内部或者形状的边上,将计算给定点到每个形状的距离,并找到最近的形状和对应的点。
|
||||
> - 距离的计算采用几何学中的投影点到形状的距离。
|
||||
> - 函数返回离给定点最近的形状的距离、找到的点和找到的形状。
|
||||
***
|
||||
#### func (*NavMesh) FindPath(start geometry.Point[V], end geometry.Point[V]) (result []geometry.Point[V])
|
||||
> 函数用于在 NavMesh 中查找从起点到终点的路径,并返回路径上的点序列。
|
||||
>
|
||||
> 参数:
|
||||
> - start: 起点,类型为 geometry.Point[V],表示路径的起始点。
|
||||
> - end: 终点,类型为 geometry.Point[V],表示路径的终点。
|
||||
>
|
||||
> 返回值:
|
||||
> - result: 路径上的点序列,类型为 []geometry.Point[V]。
|
||||
>
|
||||
> 注意事项:
|
||||
> - 函数首先根据起点和终点的位置,找到离它们最近的形状作为起点形状和终点形状。
|
||||
> - 如果起点或终点不在任何形状内部,且 NavMesh 的 meshShrinkAmount 大于0,则会考虑缩小的形状。
|
||||
> - 使用 A* 算法在 NavMesh 上搜索从起点形状到终点形状的最短路径。
|
||||
> - 使用漏斗算法对路径进行优化,以得到最终的路径点序列。
|
||||
***
|
||||
Reference in New Issue
Block a user