📝 测试文档部署

This commit is contained in:
远野千束 2024-08-28 21:27:52 +08:00
parent 0320f13ae9
commit de42d34e38
16 changed files with 493 additions and 426 deletions

View File

@ -5,19 +5,19 @@ title: mbcp.mp_math.angle
### ***class*** `AnyAngle` ### ***class*** `AnyAngle`
- #### *def* `__init__(self, value: float, is_radian: bool = False)` ### *def* `__init__(self, value: float, is_radian: bool = False)`
任意角度。 任意角度。
参数: 参数:
value: 角度或弧度值 - value: 角度或弧度值
- is_radian: 是否为弧度,默认为否
is_radian: 是否为弧度,默认为否
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -36,18 +36,18 @@ def __init__(self, value: float, is_radian: bool=False):
``` ```
</details> </details>
- #### `@property` ### `@property`
- #### *def* `complementary(self)` ### *def* `complementary(self) -> 'AnyAngle'`
余角两角的和为90°。 余角两角的和为90°。
返回: 返回:
余角 - 余角
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -63,18 +63,18 @@ def complementary(self) -> 'AnyAngle':
``` ```
</details> </details>
- #### `@property` ### `@property`
- #### *def* `supplementary(self)` ### *def* `supplementary(self) -> 'AnyAngle'`
补角两角的和为180°。 补角两角的和为180°。
返回: 返回:
补角 - 补角
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -90,18 +90,18 @@ def supplementary(self) -> 'AnyAngle':
``` ```
</details> </details>
- #### `@property` ### `@property`
- #### *def* `degree(self)` ### *def* `degree(self) -> float`
角度。 角度。
返回: 返回:
弧度 - 弧度
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -117,18 +117,18 @@ def degree(self) -> float:
``` ```
</details> </details>
- #### `@property` ### `@property`
- #### *def* `minimum_positive(self)` ### *def* `minimum_positive(self) -> 'AnyAngle'`
最小正角。 最小正角。
返回: 返回:
最小正角度 - 最小正角度
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -144,18 +144,18 @@ def minimum_positive(self) -> 'AnyAngle':
``` ```
</details> </details>
- #### `@property` ### `@property`
- #### *def* `maximum_negative(self)` ### *def* `maximum_negative(self) -> 'AnyAngle'`
最大负角。 最大负角。
返回: 返回:
最大负角度 - 最大负角度
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -171,18 +171,18 @@ def maximum_negative(self) -> 'AnyAngle':
``` ```
</details> </details>
- #### `@property` ### `@property`
- #### *def* `sin(self)` ### *def* `sin(self) -> float`
正弦值。 正弦值。
返回: 返回:
正弦值 - 正弦值
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -198,18 +198,18 @@ def sin(self) -> float:
``` ```
</details> </details>
- #### `@property` ### `@property`
- #### *def* `cos(self)` ### *def* `cos(self) -> float`
余弦值。 余弦值。
返回: 返回:
余弦值 - 余弦值
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -225,18 +225,18 @@ def cos(self) -> float:
``` ```
</details> </details>
- #### `@property` ### `@property`
- #### *def* `tan(self)` ### *def* `tan(self) -> float`
正切值。 正切值。
返回: 返回:
正切值 - 正切值
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -252,18 +252,18 @@ def tan(self) -> float:
``` ```
</details> </details>
- #### `@property` ### `@property`
- #### *def* `cot(self)` ### *def* `cot(self) -> float`
余切值。 余切值。
返回: 返回:
余切值 - 余切值
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -279,18 +279,18 @@ def cot(self) -> float:
``` ```
</details> </details>
- #### `@property` ### `@property`
- #### *def* `sec(self)` ### *def* `sec(self) -> float`
正割值。 正割值。
返回: 返回:
正割值 - 正割值
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -306,18 +306,18 @@ def sec(self) -> float:
``` ```
</details> </details>
- #### `@property` ### `@property`
- #### *def* `csc(self)` ### *def* `csc(self) -> float`
余割值。 余割值。
返回: 返回:
余割值 - 余割值
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -333,9 +333,9 @@ def csc(self) -> float:
``` ```
</details> </details>
- #### *def* `__add__(self, other: 'AnyAngle')` ### *def* `__add__(self, other: 'AnyAngle') -> 'AnyAngle'`
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -345,9 +345,9 @@ def __add__(self, other: 'AnyAngle') -> 'AnyAngle':
``` ```
</details> </details>
- #### *def* `__eq__(self, other)` ### *def* `__eq__(self, other)`
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -357,9 +357,9 @@ def __eq__(self, other):
``` ```
</details> </details>
- #### *def* `__sub__(self, other: 'AnyAngle')` ### *def* `__sub__(self, other: 'AnyAngle') -> 'AnyAngle'`
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -369,9 +369,9 @@ def __sub__(self, other: 'AnyAngle') -> 'AnyAngle':
``` ```
</details> </details>
- #### *def* `__mul__(self, other: float)` ### *def* `__mul__(self, other: float) -> 'AnyAngle'`
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -381,9 +381,9 @@ def __mul__(self, other: float) -> 'AnyAngle':
``` ```
</details> </details>
- #### *def* `__repr__(self)` ### *def* `__repr__(self)`
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -393,9 +393,9 @@ def __repr__(self):
``` ```
</details> </details>
- #### *def* `__str__(self)` ### *def* `__str__(self)`
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -405,10 +405,10 @@ def __str__(self):
``` ```
</details> </details>
- #### `@overload` ### `@overload`
- #### *def* `__truediv__(self, other: float)` ### *def* `__truediv__(self, other: float) -> 'AnyAngle'`
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -419,10 +419,10 @@ def __truediv__(self, other: float) -> 'AnyAngle':
``` ```
</details> </details>
- #### `@overload` ### `@overload`
- #### *def* `__truediv__(self, other: 'AnyAngle')` ### *def* `__truediv__(self, other: 'AnyAngle') -> float`
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -433,9 +433,9 @@ def __truediv__(self, other: 'AnyAngle') -> float:
``` ```
</details> </details>
- #### *def* `__truediv__(self, other)` ### *def* `__truediv__(self, other)`
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>

View File

@ -1,20 +1,18 @@
--- ---
title: mbcp.mp_math.equation title: mbcp.mp_math.equation
--- ---
### ***var*** `result_func = get_partial_derivative_func(result_func, v, epsilon)` ### *def* `get_partial_derivative_func(func: MultiVarsFunc = EPSILON) -> MultiVarsFunc`
### *def* `get_partial_derivative_func(func: MultiVarsFunc = EPSILON)`
求N元函数一阶偏导函数。这玩意不太稳定慎用。 求N元函数一阶偏导函数。这玩意不太稳定慎用。
参数: 参数:
func: 函数 - func: 函数
var: 变量位置,可为整数(一阶偏导)或整数元组(高阶偏导) - var: 变量位置,可为整数(一阶偏导)或整数元组(高阶偏导)
epsilon: 偏移量 - epsilon: 偏移量
@ -56,7 +54,7 @@ def get_partial_derivative_func(func: MultiVarsFunc, var: int | tuple[int, ...],
``` ```
</details> </details>
### *def* `partial_derivative_func()` ### *def* `partial_derivative_func() -> Var`
<details> <details>
@ -72,7 +70,7 @@ def partial_derivative_func(*args: Var) -> Var:
``` ```
</details> </details>
### *def* `high_order_partial_derivative_func()` ### *def* `high_order_partial_derivative_func() -> Var`
<details> <details>
@ -89,21 +87,21 @@ def high_order_partial_derivative_func(*args: Var) -> Var:
### ***class*** `CurveEquation` ### ***class*** `CurveEquation`
- #### *def* `__init__(self, x_func: OneVarFunc, y_func: OneVarFunc, z_func: OneVarFunc)` ### *def* `__init__(self, x_func: OneVarFunc, y_func: OneVarFunc, z_func: OneVarFunc)`
曲线方程。 曲线方程。
参数: 参数:
x_func: x函数 - x_func: x函数
y_func: y函数 - y_func: y函数
- z_func: z函数
z_func: z函数
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -122,19 +120,19 @@ def __init__(self, x_func: OneVarFunc, y_func: OneVarFunc, z_func: OneVarFunc):
``` ```
</details> </details>
- #### *def* `__call__(self)` ### *def* `__call__(self) -> Point3 | tuple[Point3, ...]`
计算曲线上的点。 计算曲线上的点。
参数: 参数:
*t: - *t:
- 参数:
参数:
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -155,9 +153,9 @@ def __call__(self, *t: Var) -> Point3 | tuple[Point3, ...]:
``` ```
</details> </details>
- #### *def* `__str__(self)` ### *def* `__str__(self)`
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -167,3 +165,5 @@ def __str__(self):
``` ```
</details> </details>
### ***var*** `result_func = get_partial_derivative_func(result_func, v, epsilon)`

View File

@ -3,19 +3,19 @@ title: mbcp.mp_math.line
--- ---
### ***class*** `Line3` ### ***class*** `Line3`
- #### *def* `__init__(self, point: 'Point3', direction: 'Vector3')` ### *def* `__init__(self, point: 'Point3', direction: 'Vector3')`
三维空间中的直线。由一个点和一个方向向量确定。 三维空间中的直线。由一个点和一个方向向量确定。
参数: 参数:
point: 直线上的一点 - point: 直线上的一点
- direction: 直线的方向向量
direction: 直线的方向向量
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -32,19 +32,19 @@ def __init__(self, point: 'Point3', direction: 'Vector3'):
``` ```
</details> </details>
- #### *def* `approx(self, other: 'Line3', epsilon: float = APPROX)` ### *def* `approx(self, other: 'Line3', epsilon: float = APPROX) -> bool`
判断两条直线是否近似相等。 判断两条直线是否近似相等。
参数: 参数:
other: 另一条直线 - other: 另一条直线
- epsilon: 误差
epsilon: 误差
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -62,17 +62,17 @@ def approx(self, other: 'Line3', epsilon: float=APPROX) -> bool:
``` ```
</details> </details>
- #### *def* `cal_angle(self, other: 'Line3')` ### *def* `cal_angle(self, other: 'Line3') -> 'AnyAngle'`
计算直线和直线之间的夹角。 计算直线和直线之间的夹角。
参数: 参数:
other: 另一条直线 - other: 另一条直线
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -91,17 +91,17 @@ def cal_angle(self, other: 'Line3') -> 'AnyAngle':
``` ```
</details> </details>
- #### *def* `cal_distance(self, other: 'Line3 | Point3')` ### *def* `cal_distance(self, other: 'Line3 | Point3') -> float`
计算直线和直线或点之间的距离。 计算直线和直线或点之间的距离。
参数: 参数:
other: 平行直线或点 - other: 平行直线或点
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -133,17 +133,17 @@ def cal_distance(self, other: 'Line3 | Point3') -> float:
``` ```
</details> </details>
- #### *def* `cal_intersection(self, other: 'Line3')` ### *def* `cal_intersection(self, other: 'Line3') -> 'Point3'`
计算两条直线的交点。 计算两条直线的交点。
参数: 参数:
other: 另一条直线 - other: 另一条直线
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -167,17 +167,17 @@ def cal_intersection(self, other: 'Line3') -> 'Point3':
``` ```
</details> </details>
- #### *def* `cal_perpendicular(self, point: 'Point3')` ### *def* `cal_perpendicular(self, point: 'Point3') -> 'Line3'`
计算直线经过指定点p的垂线。 计算直线经过指定点p的垂线。
参数: 参数:
point: 指定点 - point: 指定点
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -194,17 +194,17 @@ def cal_perpendicular(self, point: 'Point3') -> 'Line3':
``` ```
</details> </details>
- #### *def* `get_point(self, t: RealNumber)` ### *def* `get_point(self, t: RealNumber) -> 'Point3'`
获取直线上的点。同一条直线但起始点和方向向量不同则同一个t对应的点不同。 获取直线上的点。同一条直线但起始点和方向向量不同则同一个t对应的点不同。
参数: 参数:
t: 参数t - t: 参数t
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -221,17 +221,17 @@ def get_point(self, t: RealNumber) -> 'Point3':
``` ```
</details> </details>
- #### *def* `get_parametric_equations(self)` ### *def* `get_parametric_equations(self) -> tuple[OneSingleVarFunc, OneSingleVarFunc, OneSingleVarFunc]`
获取直线的参数方程。 获取直线的参数方程。
返回: 返回:
x(t), y(t), z(t) - x(t), y(t), z(t)
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -246,19 +246,19 @@ def get_parametric_equations(self) -> tuple[OneSingleVarFunc, OneSingleVarFunc,
``` ```
</details> </details>
- #### *def* `is_approx_parallel(self, other: 'Line3', epsilon: float = 1e-06)` ### *def* `is_approx_parallel(self, other: 'Line3', epsilon: float = 1e-06) -> bool`
判断两条直线是否近似平行。 判断两条直线是否近似平行。
参数: 参数:
other: 另一条直线 - other: 另一条直线
- epsilon: 误差
epsilon: 误差
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -276,17 +276,17 @@ def is_approx_parallel(self, other: 'Line3', epsilon: float=1e-06) -> bool:
``` ```
</details> </details>
- #### *def* `is_parallel(self, other: 'Line3')` ### *def* `is_parallel(self, other: 'Line3') -> bool`
判断两条直线是否平行。 判断两条直线是否平行。
参数: 参数:
other: 另一条直线 - other: 另一条直线
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -303,17 +303,17 @@ def is_parallel(self, other: 'Line3') -> bool:
``` ```
</details> </details>
- #### *def* `is_collinear(self, other: 'Line3')` ### *def* `is_collinear(self, other: 'Line3') -> bool`
判断两条直线是否共线。 判断两条直线是否共线。
参数: 参数:
other: 另一条直线 - other: 另一条直线
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -330,17 +330,17 @@ def is_collinear(self, other: 'Line3') -> bool:
``` ```
</details> </details>
- #### *def* `is_point_on(self, point: 'Point3')` ### *def* `is_point_on(self, point: 'Point3') -> bool`
判断点是否在直线上。 判断点是否在直线上。
参数: 参数:
point: 点 - point: 点
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -357,7 +357,7 @@ def is_point_on(self, point: 'Point3') -> bool:
``` ```
</details> </details>
- #### *def* `is_coplanar(self, other: 'Line3')` ### *def* `is_coplanar(self, other: 'Line3') -> bool`
判断两条直线是否共面。 判断两条直线是否共面。
@ -365,10 +365,10 @@ def is_point_on(self, point: 'Point3') -> bool:
参数: 参数:
other: 另一条直线 - other: 另一条直线
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -386,7 +386,7 @@ def is_coplanar(self, other: 'Line3') -> bool:
``` ```
</details> </details>
- #### *def* `simplify(self)` ### *def* `simplify(self)`
简化直线方程,等价相等。 简化直线方程,等价相等。
@ -395,7 +395,7 @@ def is_coplanar(self, other: 'Line3') -> bool:
按照可行性一次对x y z 化 0 处理,并对向量单位化 按照可行性一次对x y z 化 0 处理,并对向量单位化
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -417,20 +417,20 @@ def simplify(self):
``` ```
</details> </details>
- #### `@classmethod` ### `@classmethod`
- #### *def* `from_two_points(cls, p1: 'Point3', p2: 'Point3')` ### *def* `from_two_points(cls, p1: 'Point3', p2: 'Point3') -> 'Line3'`
工厂函数 由两点构造直线。 工厂函数 由两点构造直线。
参数: 参数:
p1: 点1 - p1: 点1
- p2: 点2
p2: 点2
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -450,17 +450,17 @@ def from_two_points(cls, p1: 'Point3', p2: 'Point3') -> 'Line3':
``` ```
</details> </details>
- #### *def* `__and__(self, other: 'Line3')` ### *def* `__and__(self, other: 'Line3') -> 'Line3 | Point3 | None'`
计算两条直线点集合的交集。重合线返回自身平行线返回None交线返回交点。 计算两条直线点集合的交集。重合线返回自身平行线返回None交线返回交点。
参数: 参数:
other: 另一条直线 - other: 另一条直线
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -482,7 +482,7 @@ def __and__(self, other: 'Line3') -> 'Line3 | Point3 | None':
``` ```
</details> </details>
- #### *def* `__eq__(self, other)` ### *def* `__eq__(self, other) -> bool`
判断两条直线是否等价。 判断两条直线是否等价。
@ -491,10 +491,10 @@ v1 // v2 ∧ (p1 - p2) // v1
参数: 参数:
other: - other:
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -514,13 +514,13 @@ def __eq__(self, other) -> bool:
``` ```
</details> </details>
- #### *def* `__str__(self)` ### *def* `__str__(self)`
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -542,9 +542,9 @@ def __str__(self):
``` ```
</details> </details>
- #### *def* `__repr__(self)` ### *def* `__repr__(self)`
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>

View File

@ -1,45 +1,25 @@
--- ---
title: mbcp.mp_math.plane title: mbcp.mp_math.plane
--- ---
### ***var*** `k = other.a / self.a`
### ***var*** `A = np.array([[self.b, self.c], [other.b, other.c]])`
### ***var*** `B = np.array([-self.d, -other.d])`
### ***var*** `v2 = l2.get_point(1) - l1.point`
### ***var*** `k = other.b / self.b`
### ***var*** `A = np.array([[self.a, self.c], [other.a, other.c]])`
### ***var*** `B = np.array([-self.d, -other.d])`
### ***var*** `k = other.c / self.c`
### ***var*** `A = np.array([[self.a, self.b], [other.a, other.b]])`
### ***var*** `B = np.array([-self.d, -other.d])`
### ***class*** `Plane3` ### ***class*** `Plane3`
- #### *def* `__init__(self, a: float, b: float, c: float, d: float)` ### *def* `__init__(self, a: float, b: float, c: float, d: float)`
平面方程ax + by + cz + d = 0 平面方程ax + by + cz + d = 0
参数: 参数:
a: - a:
b: - b:
c: - c:
- d:
d:
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -60,17 +40,17 @@ def __init__(self, a: float, b: float, c: float, d: float):
``` ```
</details> </details>
- #### *def* `approx(self, other: 'Plane3')` ### *def* `approx(self, other: 'Plane3') -> bool`
判断两个平面是否近似相等。 判断两个平面是否近似相等。
参数: 参数:
other: - other:
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -84,6 +64,7 @@ def approx(self, other: 'Plane3') -> bool:
Returns: Returns:
是否近似相等 是否近似相等
""" """
a = 3
if self.a != 0: if self.a != 0:
k = other.a / self.a k = other.a / self.a
return approx(other.b, self.b * k) and approx(other.c, self.c * k) and approx(other.d, self.d * k) return approx(other.b, self.b * k) and approx(other.c, self.c * k) and approx(other.d, self.d * k)
@ -98,17 +79,17 @@ def approx(self, other: 'Plane3') -> bool:
``` ```
</details> </details>
- #### *def* `cal_angle(self, other: 'Line3 | Plane3')` ### *def* `cal_angle(self, other: 'Line3 | Plane3') -> 'AnyAngle'`
计算平面与平面之间的夹角。 计算平面与平面之间的夹角。
参数: 参数:
other: 另一个平面 - other: 另一个平面
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -132,17 +113,17 @@ def cal_angle(self, other: 'Line3 | Plane3') -> 'AnyAngle':
``` ```
</details> </details>
- #### *def* `cal_distance(self, other: 'Plane3 | Point3')` ### *def* `cal_distance(self, other: 'Plane3 | Point3') -> float`
计算平面与平面或点之间的距离。 计算平面与平面或点之间的距离。
参数: 参数:
other: 另一个平面或点 - other: 另一个平面或点
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -166,17 +147,17 @@ def cal_distance(self, other: 'Plane3 | Point3') -> float:
``` ```
</details> </details>
- #### *def* `cal_intersection_line3(self, other: 'Plane3')` ### *def* `cal_intersection_line3(self, other: 'Plane3') -> 'Line3'`
计算两平面的交线。该方法有问题,待修复。 计算两平面的交线。该方法有问题,待修复。
参数: 参数:
other: 另一个平面 - other: 另一个平面
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -210,17 +191,17 @@ def cal_intersection_line3(self, other: 'Plane3') -> 'Line3':
``` ```
</details> </details>
- #### *def* `cal_intersection_point3(self, other: 'Line3')` ### *def* `cal_intersection_point3(self, other: 'Line3') -> 'Point3'`
计算平面与直线的交点。 计算平面与直线的交点。
参数: 参数:
other: 不与平面平行或在平面上的直线 - other: 不与平面平行或在平面上的直线
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -243,17 +224,17 @@ def cal_intersection_point3(self, other: 'Line3') -> 'Point3':
``` ```
</details> </details>
- #### *def* `cal_parallel_plane3(self, point: 'Point3')` ### *def* `cal_parallel_plane3(self, point: 'Point3') -> 'Plane3'`
计算平行于该平面且过指定点的平面。 计算平行于该平面且过指定点的平面。
参数: 参数:
point: 指定点 - point: 指定点
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -270,17 +251,17 @@ def cal_parallel_plane3(self, point: 'Point3') -> 'Plane3':
``` ```
</details> </details>
- #### *def* `is_parallel(self, other: 'Plane3')` ### *def* `is_parallel(self, other: 'Plane3') -> bool`
判断两个平面是否平行。 判断两个平面是否平行。
参数: 参数:
other: 另一个平面 - other: 另一个平面
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -297,18 +278,18 @@ def is_parallel(self, other: 'Plane3') -> bool:
``` ```
</details> </details>
- #### `@property` ### `@property`
- #### *def* `normal(self)` ### *def* `normal(self) -> 'Vector3'`
平面的法向量。 平面的法向量。
返回: 返回:
法向量 - 法向量
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -324,20 +305,20 @@ def normal(self) -> 'Vector3':
``` ```
</details> </details>
- #### `@classmethod` ### `@classmethod`
- #### *def* `from_point_and_normal(cls, point: 'Point3', normal: 'Vector3')` ### *def* `from_point_and_normal(cls, point: 'Point3', normal: 'Vector3') -> 'Plane3'`
工厂函数 由点和法向量构造平面(点法式构造)。 工厂函数 由点和法向量构造平面(点法式构造)。
参数: 参数:
point: 平面上的一点 - point: 平面上的一点
- normal: 法向量
normal: 法向量
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -358,22 +339,22 @@ def from_point_and_normal(cls, point: 'Point3', normal: 'Vector3') -> 'Plane3':
``` ```
</details> </details>
- #### `@classmethod` ### `@classmethod`
- #### *def* `from_three_points(cls, p1: 'Point3', p2: 'Point3', p3: 'Point3')` ### *def* `from_three_points(cls, p1: 'Point3', p2: 'Point3', p3: 'Point3') -> 'Plane3'`
工厂函数 由三点构造平面。 工厂函数 由三点构造平面。
参数: 参数:
p1: 点1 - p1: 点1
p2: 点2 - p2: 点2
- p3: 点3
p3: 点3
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -396,20 +377,20 @@ def from_three_points(cls, p1: 'Point3', p2: 'Point3', p3: 'Point3') -> 'Plane3'
``` ```
</details> </details>
- #### `@classmethod` ### `@classmethod`
- #### *def* `from_two_lines(cls, l1: 'Line3', l2: 'Line3')` ### *def* `from_two_lines(cls, l1: 'Line3', l2: 'Line3') -> 'Plane3'`
工厂函数 由两直线构造平面。 工厂函数 由两直线构造平面。
参数: 参数:
l1: 直线1 - l1: 直线1
- l2: 直线2
l2: 直线2
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -432,20 +413,20 @@ def from_two_lines(cls, l1: 'Line3', l2: 'Line3') -> 'Plane3':
``` ```
</details> </details>
- #### `@classmethod` ### `@classmethod`
- #### *def* `from_point_and_line(cls, point: 'Point3', line: 'Line3')` ### *def* `from_point_and_line(cls, point: 'Point3', line: 'Line3') -> 'Plane3'`
工厂函数 由点和直线构造平面。 工厂函数 由点和直线构造平面。
参数: 参数:
point: 面上一点 - point: 面上一点
- line: 面上直线,不包含点
line: 面上直线,不包含点
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -464,9 +445,9 @@ def from_point_and_line(cls, point: 'Point3', line: 'Line3') -> 'Plane3':
``` ```
</details> </details>
- #### *def* `__repr__(self)` ### *def* `__repr__(self)`
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -476,9 +457,9 @@ def __repr__(self):
``` ```
</details> </details>
- #### *def* `__str__(self)` ### *def* `__str__(self)`
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -497,10 +478,10 @@ def __str__(self):
``` ```
</details> </details>
- #### `@overload` ### `@overload`
- #### *def* `__and__(self, other: 'Line3')` ### *def* `__and__(self, other: 'Line3') -> 'Point3 | None'`
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -511,10 +492,10 @@ def __and__(self, other: 'Line3') -> 'Point3 | None':
``` ```
</details> </details>
- #### `@overload` ### `@overload`
- #### *def* `__and__(self, other: 'Plane3')` ### *def* `__and__(self, other: 'Plane3') -> 'Line3 | None'`
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -525,17 +506,17 @@ def __and__(self, other: 'Plane3') -> 'Line3 | None':
``` ```
</details> </details>
- #### *def* `__and__(self, other)` ### *def* `__and__(self, other)`
取两平面的交集(人话:交线) 取两平面的交集(人话:交线)
参数: 参数:
other: - other:
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -561,9 +542,9 @@ def __and__(self, other):
``` ```
</details> </details>
- #### *def* `__eq__(self, other)` ### *def* `__eq__(self, other) -> bool`
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -573,9 +554,9 @@ def __eq__(self, other) -> bool:
``` ```
</details> </details>
- #### *def* `__rand__(self, other: 'Line3')` ### *def* `__rand__(self, other: 'Line3') -> 'Point3'`
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -585,3 +566,23 @@ def __rand__(self, other: 'Line3') -> 'Point3':
``` ```
</details> </details>
### ***var*** `k = other.a / self.a`
### ***var*** `A = np.array([[self.b, self.c], [other.b, other.c]])`
### ***var*** `B = np.array([-self.d, -other.d])`
### ***var*** `v2 = l2.get_point(1) - l1.point`
### ***var*** `k = other.b / self.b`
### ***var*** `A = np.array([[self.a, self.c], [other.a, other.c]])`
### ***var*** `B = np.array([-self.d, -other.d])`
### ***var*** `k = other.c / self.c`
### ***var*** `A = np.array([[self.a, self.b], [other.a, other.b]])`
### ***var*** `B = np.array([-self.d, -other.d])`

View File

@ -3,21 +3,21 @@ title: mbcp.mp_math.point
--- ---
### ***class*** `Point3` ### ***class*** `Point3`
- #### *def* `__init__(self, x: float, y: float, z: float)` ### *def* `__init__(self, x: float, y: float, z: float)`
笛卡尔坐标系中的点。 笛卡尔坐标系中的点。
参数: 参数:
x: x 坐标 - x: x 坐标
y: y 坐标 - y: y 坐标
- z: z 坐标
z: z 坐标
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -36,19 +36,19 @@ def __init__(self, x: float, y: float, z: float):
``` ```
</details> </details>
- #### *def* `approx(self, other: 'Point3', epsilon: float = APPROX)` ### *def* `approx(self, other: 'Point3', epsilon: float = APPROX) -> bool`
判断两个点是否近似相等。 判断两个点是否近似相等。
参数: 参数:
other: - other:
- epsilon:
epsilon:
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -67,9 +67,9 @@ def approx(self, other: 'Point3', epsilon: float=APPROX) -> bool:
``` ```
</details> </details>
- #### *def* `__str__(self)` ### *def* `__str__(self)`
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -79,10 +79,10 @@ def __str__(self):
``` ```
</details> </details>
- #### `@overload` ### `@overload`
- #### *def* `__add__(self, other: 'Vector3')` ### *def* `__add__(self, other: 'Vector3') -> 'Point3'`
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -93,10 +93,10 @@ def __add__(self, other: 'Vector3') -> 'Point3':
``` ```
</details> </details>
- #### `@overload` ### `@overload`
- #### *def* `__add__(self, other: 'Point3')` ### *def* `__add__(self, other: 'Point3') -> 'Point3'`
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -107,7 +107,7 @@ def __add__(self, other: 'Point3') -> 'Point3':
``` ```
</details> </details>
- #### *def* `__add__(self, other)` ### *def* `__add__(self, other)`
P + V -> P P + V -> P
@ -115,10 +115,10 @@ P + P -> P
参数: 参数:
other: - other:
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -135,17 +135,17 @@ def __add__(self, other):
``` ```
</details> </details>
- #### *def* `__eq__(self, other)` ### *def* `__eq__(self, other)`
判断两个点是否相等。 判断两个点是否相等。
参数: 参数:
other: - other:
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -161,3 +161,35 @@ def __eq__(self, other):
``` ```
</details> </details>
### *def* `__sub__(self, other: 'Point3') -> 'Vector3'`
P - P -> V
P - V -> P 已在 :class:`Vector3` 中实现
参数:
- other:
<details>
<summary>源码</summary>
```python
def __sub__(self, other: 'Point3') -> 'Vector3':
"""
P - P -> V
P - V -> P 已在 :class:`Vector3` 中实现
Args:
other:
Returns:
"""
from .vector import Vector3
return Vector3(self.x - other.x, self.y - other.y, self.z - other.z)
```
</details>

View File

@ -3,7 +3,7 @@ title: mbcp.mp_math.segment
--- ---
### ***class*** `Segment3` ### ***class*** `Segment3`
- #### *def* `__init__(self, p1: 'Point3', p2: 'Point3')` ### *def* `__init__(self, p1: 'Point3', p2: 'Point3')`
三维空间中的线段。 三维空间中的线段。
@ -11,7 +11,7 @@ title: mbcp.mp_math.segment
:param p2: :param p2:
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -33,9 +33,9 @@ def __init__(self, p1: 'Point3', p2: 'Point3'):
``` ```
</details> </details>
- #### *def* `__repr__(self)` ### *def* `__repr__(self)`
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -45,9 +45,9 @@ def __repr__(self):
``` ```
</details> </details>
- #### *def* `__str__(self)` ### *def* `__str__(self)`
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>

View File

@ -1,18 +1,18 @@
--- ---
title: mbcp.mp_math.utils title: mbcp.mp_math.utils
--- ---
### *def* `clamp()` ### *def* `clamp() -> float`
区间截断函数。 区间截断函数。
参数: 参数:
x: - x:
min_: - min_:
max_: - max_:
@ -35,18 +35,18 @@ def clamp(x: float, min_: float, max_: float) -> float:
``` ```
</details> </details>
### *def* `approx(x: float = 0.0, y: float = APPROX)` ### *def* `approx(x: float = 0.0, y: float = APPROX) -> bool`
判断两个数是否近似相等。或包装一个实数用于判断是否近似于0。 判断两个数是否近似相等。或包装一个实数用于判断是否近似于0。
参数: 参数:
x: - x:
y: - y:
epsilon: - epsilon:
@ -69,16 +69,16 @@ def approx(x: float, y: float=0.0, epsilon: float=APPROX) -> bool:
``` ```
</details> </details>
### *def* `sign(x: float = False)` ### *def* `sign(x: float = False) -> str`
获取数的符号。 获取数的符号。
参数: 参数:
x: 数 - x: 数
only_neg: 是否只返回负数的符号 - only_neg: 是否只返回负数的符号
@ -103,7 +103,7 @@ def sign(x: float, only_neg: bool=False) -> str:
``` ```
</details> </details>
### *def* `sign_format(x: float = False)` ### *def* `sign_format(x: float = False) -> str`
格式化符号数 格式化符号数
@ -113,9 +113,9 @@ def sign(x: float, only_neg: bool=False) -> str:
参数: 参数:
x: 数 - x: 数
only_neg: 是否只返回负数的符号 - only_neg: 是否只返回负数的符号
@ -145,9 +145,9 @@ def sign_format(x: float, only_neg: bool=False) -> str:
### ***class*** `Approx` ### ***class*** `Approx`
- #### *def* `__init__(self, value: RealNumber)` ### *def* `__init__(self, value: RealNumber)`
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -157,9 +157,9 @@ def __init__(self, value: RealNumber):
``` ```
</details> </details>
- #### *def* `__eq__(self, other)` ### *def* `__eq__(self, other)`
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -178,9 +178,9 @@ def __eq__(self, other):
``` ```
</details> </details>
- #### *def* `raise_type_error(self, other)` ### *def* `raise_type_error(self, other)`
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -190,9 +190,9 @@ def raise_type_error(self, other):
``` ```
</details> </details>
- #### *def* `__ne__(self, other)` ### *def* `__ne__(self, other)`
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>

View File

@ -1,31 +1,23 @@
--- ---
title: mbcp.mp_math.vector title: mbcp.mp_math.vector
--- ---
### ***var*** `zero_vector3 = Vector3(0, 0, 0)`
### ***var*** `x_axis = Vector3(1, 0, 0)`
### ***var*** `y_axis = Vector3(0, 1, 0)`
### ***var*** `z_axis = Vector3(0, 0, 1)`
### ***class*** `Vector3` ### ***class*** `Vector3`
- #### *def* `__init__(self, x: float, y: float, z: float)` ### *def* `__init__(self, x: float, y: float, z: float)`
3维向量 3维向量
参数: 参数:
x: x轴分量 - x: x轴分量
y: y轴分量 - y: y轴分量
- z: z轴分量
z: z轴分量
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -44,19 +36,19 @@ def __init__(self, x: float, y: float, z: float):
``` ```
</details> </details>
- #### *def* `approx(self, other: 'Vector3', epsilon: float = APPROX)` ### *def* `approx(self, other: 'Vector3', epsilon: float = APPROX) -> bool`
判断两个向量是否近似相等。 判断两个向量是否近似相等。
参数: 参数:
other: - other:
- epsilon:
epsilon:
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -75,17 +67,17 @@ def approx(self, other: 'Vector3', epsilon: float=APPROX) -> bool:
``` ```
</details> </details>
- #### *def* `cal_angle(self, other: 'Vector3')` ### *def* `cal_angle(self, other: 'Vector3') -> 'AnyAngle'`
计算两个向量之间的夹角。 计算两个向量之间的夹角。
参数: 参数:
other: 另一个向量 - other: 另一个向量
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -102,7 +94,7 @@ def cal_angle(self, other: 'Vector3') -> 'AnyAngle':
``` ```
</details> </details>
- #### *def* `cross(self, other: 'Vector3')` ### *def* `cross(self, other: 'Vector3') -> 'Vector3'`
向量积 叉乘v1 cross v2 -> v3 向量积 叉乘v1 cross v2 -> v3
@ -112,7 +104,7 @@ def cal_angle(self, other: 'Vector3') -> 'AnyAngle':
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -141,19 +133,19 @@ def cross(self, other: 'Vector3') -> 'Vector3':
``` ```
</details> </details>
- #### *def* `is_approx_parallel(self, other: 'Vector3', epsilon: float = APPROX)` ### *def* `is_approx_parallel(self, other: 'Vector3', epsilon: float = APPROX) -> bool`
判断两个向量是否近似平行。 判断两个向量是否近似平行。
参数: 参数:
other: 另一个向量 - other: 另一个向量
- epsilon: 允许的误差
epsilon: 允许的误差
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -171,17 +163,17 @@ def is_approx_parallel(self, other: 'Vector3', epsilon: float=APPROX) -> bool:
``` ```
</details> </details>
- #### *def* `is_parallel(self, other: 'Vector3')` ### *def* `is_parallel(self, other: 'Vector3') -> bool`
判断两个向量是否平行。 判断两个向量是否平行。
参数: 参数:
other: 另一个向量 - other: 另一个向量
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -198,7 +190,7 @@ def is_parallel(self, other: 'Vector3') -> bool:
``` ```
</details> </details>
- #### *def* `normalize(self)` ### *def* `normalize(self)`
将向量归一化。 将向量归一化。
@ -206,7 +198,7 @@ def is_parallel(self, other: 'Vector3') -> bool:
自体归一化,不返回值。 自体归一化,不返回值。
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -224,14 +216,14 @@ def normalize(self):
``` ```
</details> </details>
- #### `@property` ### `@property`
- #### *def* `np_array(self)` ### *def* `np_array(self) -> 'np.ndarray'`
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -246,18 +238,18 @@ def np_array(self) -> 'np.ndarray':
``` ```
</details> </details>
- #### `@property` ### `@property`
- #### *def* `length(self)` ### *def* `length(self) -> float`
向量的模。 向量的模。
返回: 返回:
- 模
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -273,18 +265,18 @@ def length(self) -> float:
``` ```
</details> </details>
- #### `@property` ### `@property`
- #### *def* `unit(self)` ### *def* `unit(self) -> 'Vector3'`
获取该向量的单位向量。 获取该向量的单位向量。
返回: 返回:
单位向量 - 单位向量
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -300,9 +292,9 @@ def unit(self) -> 'Vector3':
``` ```
</details> </details>
- #### *def* `__abs__(self)` ### *def* `__abs__(self)`
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -312,10 +304,10 @@ def __abs__(self):
``` ```
</details> </details>
- #### `@overload` ### `@overload`
- #### *def* `__add__(self, other: 'Vector3')` ### *def* `__add__(self, other: 'Vector3') -> 'Vector3'`
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -326,10 +318,10 @@ def __add__(self, other: 'Vector3') -> 'Vector3':
``` ```
</details> </details>
- #### `@overload` ### `@overload`
- #### *def* `__add__(self, other: 'Point3')` ### *def* `__add__(self, other: 'Point3') -> 'Point3'`
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -340,7 +332,7 @@ def __add__(self, other: 'Point3') -> 'Point3':
``` ```
</details> </details>
- #### *def* `__add__(self, other)` ### *def* `__add__(self, other)`
V + P -> P V + P -> P
@ -349,10 +341,10 @@ V + V -> V
参数: 参数:
other: - other:
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -376,17 +368,17 @@ def __add__(self, other):
``` ```
</details> </details>
- #### *def* `__eq__(self, other)` ### *def* `__eq__(self, other)`
判断两个向量是否相等。 判断两个向量是否相等。
参数: 参数:
other: - other:
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -403,7 +395,7 @@ def __eq__(self, other):
``` ```
</details> </details>
- #### *def* `__radd__(self, other: 'Point3')` ### *def* `__radd__(self, other: 'Point3') -> 'Point3'`
P + V -> P P + V -> P
@ -413,7 +405,7 @@ P + V -> P
:return: :return:
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -430,10 +422,10 @@ def __radd__(self, other: 'Point3') -> 'Point3':
``` ```
</details> </details>
- #### `@overload` ### `@overload`
- #### *def* `__sub__(self, other: 'Vector3')` ### *def* `__sub__(self, other: 'Vector3') -> 'Vector3'`
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -444,10 +436,10 @@ def __sub__(self, other: 'Vector3') -> 'Vector3':
``` ```
</details> </details>
- #### `@overload` ### `@overload`
- #### *def* `__sub__(self, other: 'Point3')` ### *def* `__sub__(self, other: 'Point3') -> 'Point3'`
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -458,7 +450,7 @@ def __sub__(self, other: 'Point3') -> 'Point3':
``` ```
</details> </details>
- #### *def* `__sub__(self, other)` ### *def* `__sub__(self, other)`
V - P -> P V - P -> P
@ -467,10 +459,10 @@ V - V -> V
参数: 参数:
other: - other:
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -493,17 +485,17 @@ def __sub__(self, other):
``` ```
</details> </details>
- #### *def* `__rsub__(self, other: 'Point3')` ### *def* `__rsub__(self, other: 'Point3')`
P - V -> P P - V -> P
参数: 参数:
other: - other:
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -523,10 +515,10 @@ def __rsub__(self, other: 'Point3'):
``` ```
</details> </details>
- #### `@overload` ### `@overload`
- #### *def* `__mul__(self, other: 'Vector3')` ### *def* `__mul__(self, other: 'Vector3') -> 'Vector3'`
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -537,10 +529,10 @@ def __mul__(self, other: 'Vector3') -> 'Vector3':
``` ```
</details> </details>
- #### `@overload` ### `@overload`
- #### *def* `__mul__(self, other: RealNumber)` ### *def* `__mul__(self, other: RealNumber) -> 'Vector3'`
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -551,17 +543,17 @@ def __mul__(self, other: RealNumber) -> 'Vector3':
``` ```
</details> </details>
- #### *def* `__mul__(self, other: 'int | float | Vector3')` ### *def* `__mul__(self, other: 'int | float | Vector3') -> 'Vector3'`
数组运算 非点乘。点乘使用@叉乘使用cross。 数组运算 非点乘。点乘使用@叉乘使用cross。
参数: 参数:
other: - other:
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -583,9 +575,9 @@ def __mul__(self, other: 'int | float | Vector3') -> 'Vector3':
``` ```
</details> </details>
- #### *def* `__rmul__(self, other: 'RealNumber')` ### *def* `__rmul__(self, other: 'RealNumber') -> 'Vector3'`
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -595,17 +587,17 @@ def __rmul__(self, other: 'RealNumber') -> 'Vector3':
``` ```
</details> </details>
- #### *def* `__matmul__(self, other: 'Vector3')` ### *def* `__matmul__(self, other: 'Vector3') -> 'RealNumber'`
点乘。 点乘。
参数: 参数:
other: - other:
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -621,9 +613,9 @@ def __matmul__(self, other: 'Vector3') -> 'RealNumber':
``` ```
</details> </details>
- #### *def* `__truediv__(self, other: RealNumber)` ### *def* `__truediv__(self, other: RealNumber) -> 'Vector3'`
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -633,9 +625,9 @@ def __truediv__(self, other: RealNumber) -> 'Vector3':
``` ```
</details> </details>
- #### *def* `__neg__(self)` ### *def* `__neg__(self)`
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -645,9 +637,9 @@ def __neg__(self):
``` ```
</details> </details>
- #### *def* `__repr__(self)` ### *def* `__repr__(self)`
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -657,9 +649,9 @@ def __repr__(self):
``` ```
</details> </details>
- #### *def* `__str__(self)` ### *def* `__str__(self)`
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>
@ -669,3 +661,11 @@ def __str__(self):
``` ```
</details> </details>
### ***var*** `zero_vector3 = Vector3(0, 0, 0)`
### ***var*** `x_axis = Vector3(1, 0, 0)`
### ***var*** `y_axis = Vector3(0, 1, 0)`
### ***var*** `z_axis = Vector3(0, 0, 1)`

View File

@ -3,20 +3,20 @@ title: mbcp.presets.model
--- ---
### ***class*** `GeometricModels` ### ***class*** `GeometricModels`
- #### `@staticmethod` ### `@staticmethod`
- #### *def* `sphere(radius: float, density: float)` ### *def* `sphere(radius: float, density: float)`
生成球体上的点集。 生成球体上的点集。
参数: 参数:
radius: - radius:
- density:
density:
- #
<details> <details>
<summary>源码</summary> <summary>源码</summary>

View File

@ -121,29 +121,29 @@ class Docstring(BaseModel):
""" """
PREFIX = "" * indent PREFIX = "" * indent
if is_classmethod:
PREFIX = " -"
ret = "" ret = ""
ret += self.desc + "\n\n" ret += self.desc + "\n\n"
# print(self.reduction())
# print(self.desc, self.return_)
if self.args: if self.args:
ret += PREFIX + f"{get_text(lang, 'docstring.args')}:\n\n" ret += PREFIX + f"{get_text(lang, 'docstring.args')}:\n\n"
for arg in self.args: for arg in self.args:
ret += PREFIX + f"{arg.name}: {arg.type} {arg.desc}\n\n" ret += PREFIX + f"- {arg.name}: {arg.type} {arg.desc}\n\n"
if self.attrs: if self.attrs:
ret += PREFIX + f"{get_text(lang, 'docstring.attrs')}:\n\n" ret += PREFIX + f"{get_text(lang, 'docstring.attrs')}:\n\n"
for attr in self.attrs: for attr in self.attrs:
ret += PREFIX + f"{attr.name}: {attr.type} {attr.desc}\n\n" ret += PREFIX + f"- {attr.name}: {attr.type} {attr.desc}\n\n"
if self.return_: if self.return_ is not None:
ret += PREFIX + f"{get_text(lang, 'docstring.return')}:\n\n" ret += PREFIX + f"{get_text(lang, 'docstring.return')}:\n\n"
ret += PREFIX + f"{self.return_.desc}\n\n" ret += PREFIX + f"- {self.return_.desc}\n\n"
if self.raise_: if self.raise_:
ret += PREFIX + f"{get_text(lang, 'docstring.raises')}:\n\n" ret += PREFIX + f"{get_text(lang, 'docstring.raises')}:\n\n"
for exception in self.raise_: for exception in self.raise_:
ret += PREFIX + f"{exception.name} {exception.desc}\n\n" ret += PREFIX + f"- {exception.name} {exception.desc}\n\n"
if self.example: if self.example:
ret += PREFIX + f"{get_text(lang, 'docstring.example')}:\n\n" ret += PREFIX + f"{get_text(lang, 'docstring.example')}:\n\n"
for example in self.example: for example in self.example:
ret += PREFIX + f"{example.desc}\n Input: {example.input}\n Output: {example.output}\n\n" ret += PREFIX + f"- {example.desc}\n Input: {example.input}\n Output: {example.output}\n\n"
return ret return ret
def __str__(self): def __str__(self):

View File

@ -115,17 +115,17 @@ class GoogleDocstringParser(Parser):
在一个子解析器中解析下一行直到缩进小于等于当前行的缩进 在一个子解析器中解析下一行直到缩进小于等于当前行的缩进
Returns: Returns:
""" """
while self.lineno + 1 < len(self.lines): while (self.lineno + 1) < len(self.lines):
line = self.lines[self.lineno + 1] line = self.lines[self.lineno + 1]
if line.startswith(" " * self.indent): if line.startswith(" " * self.indent):
line = line[self.indent:] line = line[self.indent:]
else:
return None
if not line:
return None
self.lineno += 1 self.lineno += 1
return line return line
else:
self.lineno += 1
return None
self.lineno += 1
return None
def parse(self) -> Docstring: def parse(self) -> Docstring:
""" """
@ -146,7 +146,6 @@ class GoogleDocstringParser(Parser):
add_desc = False add_desc = False
match token: match token:
case "args": case "args":
self.parse_args() self.parse_args()
case "return": case "return":

View File

@ -26,7 +26,6 @@ def generate(parser: AstParser, lang: str, frontmatter: Optional[dict] = None) -
Returns: Returns:
markdown style document markdown style document
""" """
print(parser.variables)
if frontmatter is not None: if frontmatter is not None:
md = "---\n" md = "---\n"
for k, v in frontmatter.items(): for k, v in frontmatter.items():
@ -36,20 +35,13 @@ def generate(parser: AstParser, lang: str, frontmatter: Optional[dict] = None) -
md = "" md = ""
# var > func > class # var > func > class
for var in parser.variables:
if var.type == TypeHint.NO_TYPEHINT:
md += f"### ***var*** `{var.name} = {var.value}`\n\n"
else:
md += f"### ***var*** `{var.name}: {var.type} = {var.value}`\n\n"
for func in parser.functions: for func in parser.functions:
md += func.markdown(lang) md += func.markdown(lang)
for cls in parser.classes: for cls in parser.classes:
md += f"### ***class*** `{cls.name}`\n\n" md += f"### ***class*** `{cls.name}`\n\n"
for mtd in cls.methods: for mtd in cls.methods:
md += mtd.markdown(lang, 2, True) md += mtd.markdown(lang, 2, True)
for attr in cls.attrs: for attr in cls.attrs:
@ -58,4 +50,10 @@ def generate(parser: AstParser, lang: str, frontmatter: Optional[dict] = None) -
else: else:
md += f"#### ***attr*** `{attr.name}: {attr.type} = {attr.value}`\n\n" md += f"#### ***attr*** `{attr.name}: {attr.type} = {attr.value}`\n\n"
for var in parser.variables:
if var.type == TypeHint.NO_TYPEHINT:
md += f"### ***var*** `{var.name} = {var.value}`\n\n"
else:
md += f"### ***var*** `{var.name}: {var.type} = {var.value}`\n\n"
return md return md

View File

@ -139,18 +139,18 @@ class AstParser:
) )
for default in node.args.defaults for default in node.args.defaults
], ],
return_=ast.unparse(node.returns).strip() if node.returns else TypeHint.NO_TYPEHINT, return_=ast.unparse(node.returns).strip() if node.returns else TypeHint.NO_RETURN,
decorators=[ast.unparse(decorator).strip() for decorator in node.decorator_list], decorators=[ast.unparse(decorator).strip() for decorator in node.decorator_list],
is_async=isinstance(node, ast.AsyncFunctionDef), is_async=isinstance(node, ast.AsyncFunctionDef),
src=ast.unparse(node).strip() src=ast.unparse(node).strip()
)) ))
elif isinstance(node, (ast.Assign, ast.AnnAssign)): elif isinstance(node, (ast.Assign, ast.AnnAssign)):
if not self._is_module_level_variable(node): if not self._is_module_level_variable2(node):
# print("变量不在模块级别", ast.unparse(node)) # print("变量不在模块级别", ast.unparse(node))
continue continue
else: else:
print("变量在模块级别", ast.unparse(node)) pass
if isinstance(node, ast.Assign): if isinstance(node, ast.Assign):
for target in node.targets: for target in node.targets:
if isinstance(target, ast.Name): if isinstance(target, ast.Name):
@ -180,7 +180,39 @@ class AstParser:
return False return False
return True return True
def _is_module_level_variable(self, node: ast.Assign): def _is_module_level_variable(self, node: ast.Assign | ast.AnnAssign):
"""在类方法或函数内部的变量不会被记录"""
# for parent in ast.walk(self.tree):
# if isinstance(parent, (ast.ClassDef, ast.FunctionDef, ast.AsyncFunctionDef)):
# if node in parent.body:
# return False
# else:
# for sub_node in parent.body:
# if isinstance(sub_node, (ast.FunctionDef, ast.AsyncFunctionDef)):
# if node in sub_node.body:
# return False
# return True
# 递归检查
def _check(_node, _parent):
if isinstance(_parent, (ast.ClassDef, ast.FunctionDef, ast.AsyncFunctionDef)):
if _node in _parent.body:
return False
else:
for sub_node in _parent.body:
if isinstance(sub_node, (ast.FunctionDef, ast.AsyncFunctionDef)):
return _check(_node, sub_node)
return True
for parent in ast.walk(self.tree):
if not _check(node, parent):
return False
return True
def _is_module_level_variable2(self, node: ast.Assign | ast.AnnAssign) -> bool:
"""
检查变量是否在模块级别定义
"""
for parent in ast.walk(self.tree): for parent in ast.walk(self.tree):
if isinstance(parent, (ast.ClassDef, ast.FunctionDef, ast.AsyncFunctionDef)): if isinstance(parent, (ast.ClassDef, ast.FunctionDef, ast.AsyncFunctionDef)):
if node in parent.body: if node in parent.body:

View File

@ -119,7 +119,7 @@ class FunctionNode(BaseModel):
kw_defaults: list[ConstantNode] = [] kw_defaults: list[ConstantNode] = []
defaults: list[ConstantNode] = [] defaults: list[ConstantNode] = []
return_: str = Field(TypeHint.NO_RETURN, alias="return") return_: str = TypeHint.NO_RETURN
decorators: list[str] = [] decorators: list[str] = []
src: str src: str
is_async: bool = False is_async: bool = False
@ -153,8 +153,8 @@ class FunctionNode(BaseModel):
""" """
self.complete_default_args() self.complete_default_args()
PREFIX = "" * indent PREFIX = "" * indent
if is_classmethod: # if is_classmethod:
PREFIX = "- #" # PREFIX = "- #"
md = "" md = ""
@ -211,11 +211,14 @@ class FunctionNode(BaseModel):
md += ", ".join(args) + ")" md += ", ".join(args) + ")"
if self.return_ != TypeHint.NO_RETURN:
md += f" -> {self.return_}"
md += "`\n\n" # code end md += "`\n\n" # code end
"""此处预留docstring""" """此处预留docstring"""
if self.docs is not None: if self.docs is not None:
md += f"\n{self.docs.markdown(lang, indent)}\n" md += f"\n{self.docs.markdown(lang, indent, is_classmethod)}\n"
else: else:
pass pass
# 源码展示 # 源码展示

View File

@ -41,6 +41,8 @@ class Plane3:
Returns: Returns:
是否近似相等 是否近似相等
""" """
a = 3 # 测试变量
if self.a != 0: if self.a != 0:
k = other.a / self.a k = other.a / self.a
return approx(other.b, self.b * k) and approx(other.c, self.c * k) and approx(other.d, self.d * k) return approx(other.b, self.b * k) and approx(other.c, self.c * k) and approx(other.d, self.d * k)

View File

@ -62,15 +62,15 @@ class Point3:
""" """
return approx(self.x, other.x) and approx(self.y, other.y) and approx(self.z, other.z) return approx(self.x, other.x) and approx(self.y, other.y) and approx(self.z, other.z)
# def __sub__(self, other: "Point3") -> "Vector3": def __sub__(self, other: "Point3") -> "Vector3":
# """ """
# P - P -> V P - P -> V
#
# P - V -> P 已在 :class:`Vector3` 中实现 P - V -> P 已在 :class:`Vector3` 中实现
# Args: Args:
# other: other:
# Returns: Returns:
#
# """ """
# from .vector import Vector3 from .vector import Vector3
# return Vector3(self.x - other.x, self.y - other.y, self.z - other.z) return Vector3(self.x - other.x, self.y - other.y, self.z - other.z)