Skip to content

point

DmDPoint

双精度点

Source code in dimine_python_sdk\lib\types\point.py
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
class DmDPoint:
    """双精度点"""

    def __init__(self, x: float = 0.0, y: float = 0.0, z: float = 0.0):
        """
        构造函数
        :param x: 向量x分量,默认0.0
        :param y: 向量y分量,默认0.0
        :param z: 向量z分量,默认0.0
        """
        self._obj = Dm.dmDPoint(x, y, z)

    @classmethod
    def _from_obj(cls, obj):
        """
        :param obj: 源dmDPoint对象
        :return: DmDPoint实例
        """
        instance = cls()
        instance._obj = obj
        return instance


    # ---------------------- 分量属性封装 ----------------------
    @property
    def x(self) -> float:
        return self._obj.x

    @x.setter
    def x(self, value: float):
        self._obj.x = float(value)

    @property
    def y(self) -> float:
        return self._obj.y

    @y.setter
    def y(self, value: float):
        self._obj.y = float(value)

    @property
    def z(self) -> float:
        return self._obj.z

    @z.setter
    def z(self, value: float):
        self._obj.z = float(value)

    # ---------------------- 基础运算符 ----------------------
    def __add__(self, other: "DmDPoint") -> "DmDPoint":
        """
        向量加法
        :param other: 待相加的DmDPoint实例
        :return: 相加后的新DmDPoint实例
        :raise TypeError: 非DmDPoint实例时抛出
        """
        if not isinstance(other, DmDPoint):
            raise TypeError(f"仅支持DmDPoint实例相加,当前为{type(other)}")
        res = DmDPoint()
        res._obj = self._obj + other._obj
        return res

    def __sub__(self, other: "DmDPoint") -> "DmDPoint":
        """
        向量减法
        :param other: 待相减的DmDPoint实例
        :return: 相减后的新DmDPoint实例
        :raise TypeError: 非DmDPoint实例时抛出
        """
        if not isinstance(other, DmDPoint):
            raise TypeError(f"仅支持DmDPoint实例相减,当前为{type(other)}")
        res = DmDPoint()
        res._obj = self._obj - other._obj
        return res

    def __mul__(self, scalar: (int, float)) -> "DmDPoint":
        """
        向量标量乘法
        :param scalar: 相乘的标量(int/float)
        :return: 相乘后的新DmDPoint实例
        :raise TypeError: 非标量类型时抛出
        """
        if not isinstance(scalar, (int, float)):
            raise TypeError(f"仅支持与标量(int/float)相乘,当前为{type(scalar)}")
        res = DmDPoint()
        res._obj = self._obj * scalar
        return res

    def __truediv__(self, scalar: (int, float)) -> "DmDPoint":
        """
        向量标量除法
        :param scalar: 相除的标量(int/float)
        :return: 相除后的新DmDPoint实例
        :raise TypeError: 非标量类型时抛出
        :raise ZeroDivisionError: 标量为0时抛出
        """
        if not isinstance(scalar, (int, float)):
            raise TypeError(f"仅支持与标量(int/float)相除,当前为{type(scalar)}")
        if scalar == 0:
            raise ZeroDivisionError("向量标量除法,标量不能为0")
        res = DmDPoint()
        res._obj = self._obj / scalar
        return res

    # ---------------------- 复合赋值运算符 ----------------------
    def __iadd__(self, other: "DmDPoint") -> "DmDPoint":
        """
        向量加法赋值(原地修改)
        :param other: 待相加的DmDPoint实例
        :return: 自身实例(支持链式调用)
        :raise TypeError: 非DmDPoint实例时抛出
        """
        if not isinstance(other, DmDPoint):
            raise TypeError(f"仅支持DmDPoint实例相加赋值,当前为{type(other)}")
        self._obj += other._obj
        return self

    def __isub__(self, other: "DmDPoint") -> "DmDPoint":
        """
        向量减法赋值(原地修改)
        :param other: 待相减的DmDPoint实例
        :return: 自身实例(支持链式调用)
        :raise TypeError: 非DmDPoint实例时抛出
        """
        if not isinstance(other, DmDPoint):
            raise TypeError(f"仅支持DmDPoint实例相减赋值,当前为{type(other)}")
        self._obj -= other._obj
        return self

    def __imul__(self, scalar: (int, float)) -> "DmDPoint":
        """
        向量标量乘法赋值(原地修改)
        :param scalar: 相乘的标量(int/float)
        :return: 自身实例(支持链式调用)
        :raise TypeError: 非标量类型时抛出
        """
        if not isinstance(scalar, (int, float)):
            raise TypeError(f"仅支持与标量(int/float)相乘赋值,当前为{type(scalar)}")
        self._obj *= scalar
        return self

    def __itruediv__(self, scalar: (int, float)) -> "DmDPoint":
        """
        向量标量除法赋值(原地修改)
        :param scalar: 相除的标量(int/float)
        :return: 自身实例(支持链式调用)
        :raise TypeError: 非标量类型时抛出
        :raise ZeroDivisionError: 标量为0时抛出
        """
        if not isinstance(scalar, (int, float)):
            raise TypeError(f"仅支持与标量(int/float)相除赋值,当前为{type(scalar)}")
        if scalar == 0:
            raise ZeroDivisionError("向量标量除法赋值,标量不能为0")
        self._obj /= scalar
        return self

    # ---------------------- 单目/比较运算符 ----------------------
    def __neg__(self) -> "DmDPoint":
        """
        负号运算符(取反向量)
        :return: 取反后的新DmDPoint实例
        """
        res = DmDPoint()
        res._obj = -self._obj
        return res

    def __eq__(self, other: "DmDPoint") -> bool:
        """
        等于比较运算符
        :param other: 待比较的DmDPoint实例
        :return: 相等返回True,否则返回False;非DmDPoint实例直接返回False
        """
        if not isinstance(other, DmDPoint):
            return False
        return self._obj == other._obj

    def __ne__(self, other: "DmDPoint") -> bool:
        """
        不等于比较运算符
        :param other: 待比较的DmDPoint实例
        :return: 不相等返回True,否则返回False;非DmDPoint实例直接返回True
        """
        if not isinstance(other, DmDPoint):
            return True
        return self._obj != other._obj

    # ---------------------- 核心工具方法 ----------------------
    def __getitem__(self, idx: int) -> float:
        """
        索引访问分量(0=x,1=y,2=z)
        :param idx: 索引值(仅支持0/1/2)
        :return: 对应索引的分量值(float)
        :raise IndexError: 索引非整数/超出0-2范围时抛出
        """
        if not isinstance(idx, int) or idx < 0 or idx >= 3:
            raise IndexError("向量索引仅支持0(x)、1(y)、2(z),超出范围")
        return self._obj[idx]

    def is_zero_length(self, tol: float = 1e-10) -> bool:
        """
        判断是否为零向量(考虑浮点精度误差)
        :param tol: 浮点容差阈值,默认1e-10(值越小精度要求越高)
        :return: 向量长度接近0返回True,否则返回False

        example:
        ```python
        pt = DmDPoint(0, 0, 0)
        print(pt.is_zero_length())
        ```
        """
        return self._obj.IsZeroLength(tol)

    def dot_product(self, other: "DmDPoint") -> float:
        """
        计算两个向量的点积(数量积)
        :param other: 待计算点积的DmDPoint实例
        :return: 点积结果(float)
        :raise TypeError: 非DmDPoint实例时抛出

        example:
        ```python
        pt1 = DmDPoint(1, 2, 3)
        pt2 = DmDPoint(4, 5, 6)
        dot = pt1.dot_product(pt2)
        print(dot)
        ```
        """
        if not isinstance(other, DmDPoint):
            raise TypeError(f"仅支持与DmDPoint实例计算点积,当前为{type(other)}")
        return self._obj.DotProduct(other._obj)

    def cross_product(self, other: "DmDPoint") -> "DmDPoint":
        """
        计算两个向量的叉积(向量积)
        :param other: 待计算叉积的DmDPoint实例
        :return: 叉积结果的新DmDPoint实例
        :raise TypeError: 非DmDPoint实例时抛出

        example:
        ```python
        pt1 = DmDPoint(1, 2, 3)
        pt2 = DmDPoint(4, 5, 6)
        cross = pt1.cross_product(pt2)
        print(cross)
        ```
        """
        if not isinstance(other, DmDPoint):
            raise TypeError(f"仅支持与DmDPoint实例计算叉积,当前为{type(other)}")
        res = DmDPoint()
        res._obj = self._obj.CrossProduct(other._obj)
        return res

    def norm(self) -> float:
        """
        计算向量的模长(长度)
        :return: 向量模长结果(float)

        example:
        ```python
        pt = DmDPoint(3, 4, 0)
        print(pt.norm())
        ```
        """
        return self._obj.Norm()

    def normalize(self) -> "DmDPoint":
        """
        向量归一化(原地修改,转为单位向量)
        :return: 自身实例

        example:
        ```python
        pt = DmDPoint(3, 4, 0)
        pt.normalize()
        print(pt)
        ```
        """
        self._obj.Normalize()
        return self

    def set(self, x: float, y: float, z: float) -> "DmDPoint":
        """
        一次性设置向量x/y/z分量(原地修改)
        :param x: 新的x分量值(float)
        :param y: 新的y分量值(float)
        :param z: 新的z分量值(float)
        :return: 自身实例(支持链式调用)

        example:
        ```python
        pt = DmDPoint()
        pt.set(1, 2, 3)
        print(pt)  # 输出: (1.0, 2.0, 3.0)
        ```
        """
        self._obj.Set(float(x), float(y), float(z))
        return self

    # ---------------------- 字符串表示 ----------------------
    def __repr__(self) -> str:
        """
        字符串表示
        :return: 向量的标准字符串表示
        """
        return self._obj.__repr__()

    def __str__(self) -> str:
        """
        打印字符串,与__repr__保持一致,确保输出格式统一
        :return: 向量的打印字符串表示
        """
        return self._obj.__repr__()

__add__(other)

向量加法 :param other: 待相加的DmDPoint实例 :return: 相加后的新DmDPoint实例 :raise TypeError: 非DmDPoint实例时抛出

Source code in dimine_python_sdk\lib\types\point.py
78
79
80
81
82
83
84
85
86
87
88
89
def __add__(self, other: "DmDPoint") -> "DmDPoint":
    """
    向量加法
    :param other: 待相加的DmDPoint实例
    :return: 相加后的新DmDPoint实例
    :raise TypeError: 非DmDPoint实例时抛出
    """
    if not isinstance(other, DmDPoint):
        raise TypeError(f"仅支持DmDPoint实例相加,当前为{type(other)}")
    res = DmDPoint()
    res._obj = self._obj + other._obj
    return res

__eq__(other)

等于比较运算符 :param other: 待比较的DmDPoint实例 :return: 相等返回True,否则返回False;非DmDPoint实例直接返回False

Source code in dimine_python_sdk\lib\types\point.py
195
196
197
198
199
200
201
202
203
def __eq__(self, other: "DmDPoint") -> bool:
    """
    等于比较运算符
    :param other: 待比较的DmDPoint实例
    :return: 相等返回True,否则返回False;非DmDPoint实例直接返回False
    """
    if not isinstance(other, DmDPoint):
        return False
    return self._obj == other._obj

__getitem__(idx)

索引访问分量(0=x,1=y,2=z) :param idx: 索引值(仅支持0/1/2) :return: 对应索引的分量值(float) :raise IndexError: 索引非整数/超出0-2范围时抛出

Source code in dimine_python_sdk\lib\types\point.py
216
217
218
219
220
221
222
223
224
225
def __getitem__(self, idx: int) -> float:
    """
    索引访问分量(0=x,1=y,2=z)
    :param idx: 索引值(仅支持0/1/2)
    :return: 对应索引的分量值(float)
    :raise IndexError: 索引非整数/超出0-2范围时抛出
    """
    if not isinstance(idx, int) or idx < 0 or idx >= 3:
        raise IndexError("向量索引仅支持0(x)、1(y)、2(z),超出范围")
    return self._obj[idx]

__iadd__(other)

向量加法赋值(原地修改) :param other: 待相加的DmDPoint实例 :return: 自身实例(支持链式调用) :raise TypeError: 非DmDPoint实例时抛出

Source code in dimine_python_sdk\lib\types\point.py
134
135
136
137
138
139
140
141
142
143
144
def __iadd__(self, other: "DmDPoint") -> "DmDPoint":
    """
    向量加法赋值(原地修改)
    :param other: 待相加的DmDPoint实例
    :return: 自身实例(支持链式调用)
    :raise TypeError: 非DmDPoint实例时抛出
    """
    if not isinstance(other, DmDPoint):
        raise TypeError(f"仅支持DmDPoint实例相加赋值,当前为{type(other)}")
    self._obj += other._obj
    return self

__imul__(scalar)

向量标量乘法赋值(原地修改) :param scalar: 相乘的标量(int/float) :return: 自身实例(支持链式调用) :raise TypeError: 非标量类型时抛出

Source code in dimine_python_sdk\lib\types\point.py
158
159
160
161
162
163
164
165
166
167
168
def __imul__(self, scalar: (int, float)) -> "DmDPoint":
    """
    向量标量乘法赋值(原地修改)
    :param scalar: 相乘的标量(int/float)
    :return: 自身实例(支持链式调用)
    :raise TypeError: 非标量类型时抛出
    """
    if not isinstance(scalar, (int, float)):
        raise TypeError(f"仅支持与标量(int/float)相乘赋值,当前为{type(scalar)}")
    self._obj *= scalar
    return self

__init__(x=0.0, y=0.0, z=0.0)

构造函数 :param x: 向量x分量,默认0.0 :param y: 向量y分量,默认0.0 :param z: 向量z分量,默认0.0

Source code in dimine_python_sdk\lib\types\point.py
32
33
34
35
36
37
38
39
def __init__(self, x: float = 0.0, y: float = 0.0, z: float = 0.0):
    """
    构造函数
    :param x: 向量x分量,默认0.0
    :param y: 向量y分量,默认0.0
    :param z: 向量z分量,默认0.0
    """
    self._obj = Dm.dmDPoint(x, y, z)

__isub__(other)

向量减法赋值(原地修改) :param other: 待相减的DmDPoint实例 :return: 自身实例(支持链式调用) :raise TypeError: 非DmDPoint实例时抛出

Source code in dimine_python_sdk\lib\types\point.py
146
147
148
149
150
151
152
153
154
155
156
def __isub__(self, other: "DmDPoint") -> "DmDPoint":
    """
    向量减法赋值(原地修改)
    :param other: 待相减的DmDPoint实例
    :return: 自身实例(支持链式调用)
    :raise TypeError: 非DmDPoint实例时抛出
    """
    if not isinstance(other, DmDPoint):
        raise TypeError(f"仅支持DmDPoint实例相减赋值,当前为{type(other)}")
    self._obj -= other._obj
    return self

__itruediv__(scalar)

向量标量除法赋值(原地修改) :param scalar: 相除的标量(int/float) :return: 自身实例(支持链式调用) :raise TypeError: 非标量类型时抛出 :raise ZeroDivisionError: 标量为0时抛出

Source code in dimine_python_sdk\lib\types\point.py
170
171
172
173
174
175
176
177
178
179
180
181
182
183
def __itruediv__(self, scalar: (int, float)) -> "DmDPoint":
    """
    向量标量除法赋值(原地修改)
    :param scalar: 相除的标量(int/float)
    :return: 自身实例(支持链式调用)
    :raise TypeError: 非标量类型时抛出
    :raise ZeroDivisionError: 标量为0时抛出
    """
    if not isinstance(scalar, (int, float)):
        raise TypeError(f"仅支持与标量(int/float)相除赋值,当前为{type(scalar)}")
    if scalar == 0:
        raise ZeroDivisionError("向量标量除法赋值,标量不能为0")
    self._obj /= scalar
    return self

__mul__(scalar)

向量标量乘法 :param scalar: 相乘的标量(int/float) :return: 相乘后的新DmDPoint实例 :raise TypeError: 非标量类型时抛出

Source code in dimine_python_sdk\lib\types\point.py
104
105
106
107
108
109
110
111
112
113
114
115
def __mul__(self, scalar: (int, float)) -> "DmDPoint":
    """
    向量标量乘法
    :param scalar: 相乘的标量(int/float)
    :return: 相乘后的新DmDPoint实例
    :raise TypeError: 非标量类型时抛出
    """
    if not isinstance(scalar, (int, float)):
        raise TypeError(f"仅支持与标量(int/float)相乘,当前为{type(scalar)}")
    res = DmDPoint()
    res._obj = self._obj * scalar
    return res

__ne__(other)

不等于比较运算符 :param other: 待比较的DmDPoint实例 :return: 不相等返回True,否则返回False;非DmDPoint实例直接返回True

Source code in dimine_python_sdk\lib\types\point.py
205
206
207
208
209
210
211
212
213
def __ne__(self, other: "DmDPoint") -> bool:
    """
    不等于比较运算符
    :param other: 待比较的DmDPoint实例
    :return: 不相等返回True,否则返回False;非DmDPoint实例直接返回True
    """
    if not isinstance(other, DmDPoint):
        return True
    return self._obj != other._obj

__neg__()

负号运算符(取反向量) :return: 取反后的新DmDPoint实例

Source code in dimine_python_sdk\lib\types\point.py
186
187
188
189
190
191
192
193
def __neg__(self) -> "DmDPoint":
    """
    负号运算符(取反向量)
    :return: 取反后的新DmDPoint实例
    """
    res = DmDPoint()
    res._obj = -self._obj
    return res

__repr__()

字符串表示 :return: 向量的标准字符串表示

Source code in dimine_python_sdk\lib\types\point.py
328
329
330
331
332
333
def __repr__(self) -> str:
    """
    字符串表示
    :return: 向量的标准字符串表示
    """
    return self._obj.__repr__()

__str__()

打印字符串,与__repr__保持一致,确保输出格式统一 :return: 向量的打印字符串表示

Source code in dimine_python_sdk\lib\types\point.py
335
336
337
338
339
340
def __str__(self) -> str:
    """
    打印字符串,与__repr__保持一致,确保输出格式统一
    :return: 向量的打印字符串表示
    """
    return self._obj.__repr__()

__sub__(other)

向量减法 :param other: 待相减的DmDPoint实例 :return: 相减后的新DmDPoint实例 :raise TypeError: 非DmDPoint实例时抛出

Source code in dimine_python_sdk\lib\types\point.py
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
def __sub__(self, other: "DmDPoint") -> "DmDPoint":
    """
    向量减法
    :param other: 待相减的DmDPoint实例
    :return: 相减后的新DmDPoint实例
    :raise TypeError: 非DmDPoint实例时抛出
    """
    if not isinstance(other, DmDPoint):
        raise TypeError(f"仅支持DmDPoint实例相减,当前为{type(other)}")
    res = DmDPoint()
    res._obj = self._obj - other._obj
    return res

__truediv__(scalar)

向量标量除法 :param scalar: 相除的标量(int/float) :return: 相除后的新DmDPoint实例 :raise TypeError: 非标量类型时抛出 :raise ZeroDivisionError: 标量为0时抛出

Source code in dimine_python_sdk\lib\types\point.py
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
def __truediv__(self, scalar: (int, float)) -> "DmDPoint":
    """
    向量标量除法
    :param scalar: 相除的标量(int/float)
    :return: 相除后的新DmDPoint实例
    :raise TypeError: 非标量类型时抛出
    :raise ZeroDivisionError: 标量为0时抛出
    """
    if not isinstance(scalar, (int, float)):
        raise TypeError(f"仅支持与标量(int/float)相除,当前为{type(scalar)}")
    if scalar == 0:
        raise ZeroDivisionError("向量标量除法,标量不能为0")
    res = DmDPoint()
    res._obj = self._obj / scalar
    return res

cross_product(other)

计算两个向量的叉积(向量积) :param other: 待计算叉积的DmDPoint实例 :return: 叉积结果的新DmDPoint实例 :raise TypeError: 非DmDPoint实例时抛出

example:

pt1 = DmDPoint(1, 2, 3)
pt2 = DmDPoint(4, 5, 6)
cross = pt1.cross_product(pt2)
print(cross)
Source code in dimine_python_sdk\lib\types\point.py
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
def cross_product(self, other: "DmDPoint") -> "DmDPoint":
    """
    计算两个向量的叉积(向量积)
    :param other: 待计算叉积的DmDPoint实例
    :return: 叉积结果的新DmDPoint实例
    :raise TypeError: 非DmDPoint实例时抛出

    example:
    ```python
    pt1 = DmDPoint(1, 2, 3)
    pt2 = DmDPoint(4, 5, 6)
    cross = pt1.cross_product(pt2)
    print(cross)
    ```
    """
    if not isinstance(other, DmDPoint):
        raise TypeError(f"仅支持与DmDPoint实例计算叉积,当前为{type(other)}")
    res = DmDPoint()
    res._obj = self._obj.CrossProduct(other._obj)
    return res

dot_product(other)

计算两个向量的点积(数量积) :param other: 待计算点积的DmDPoint实例 :return: 点积结果(float) :raise TypeError: 非DmDPoint实例时抛出

example:

pt1 = DmDPoint(1, 2, 3)
pt2 = DmDPoint(4, 5, 6)
dot = pt1.dot_product(pt2)
print(dot)
Source code in dimine_python_sdk\lib\types\point.py
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
def dot_product(self, other: "DmDPoint") -> float:
    """
    计算两个向量的点积(数量积)
    :param other: 待计算点积的DmDPoint实例
    :return: 点积结果(float)
    :raise TypeError: 非DmDPoint实例时抛出

    example:
    ```python
    pt1 = DmDPoint(1, 2, 3)
    pt2 = DmDPoint(4, 5, 6)
    dot = pt1.dot_product(pt2)
    print(dot)
    ```
    """
    if not isinstance(other, DmDPoint):
        raise TypeError(f"仅支持与DmDPoint实例计算点积,当前为{type(other)}")
    return self._obj.DotProduct(other._obj)

is_zero_length(tol=1e-10)

判断是否为零向量(考虑浮点精度误差) :param tol: 浮点容差阈值,默认1e-10(值越小精度要求越高) :return: 向量长度接近0返回True,否则返回False

example:

pt = DmDPoint(0, 0, 0)
print(pt.is_zero_length())
Source code in dimine_python_sdk\lib\types\point.py
227
228
229
230
231
232
233
234
235
236
237
238
239
def is_zero_length(self, tol: float = 1e-10) -> bool:
    """
    判断是否为零向量(考虑浮点精度误差)
    :param tol: 浮点容差阈值,默认1e-10(值越小精度要求越高)
    :return: 向量长度接近0返回True,否则返回False

    example:
    ```python
    pt = DmDPoint(0, 0, 0)
    print(pt.is_zero_length())
    ```
    """
    return self._obj.IsZeroLength(tol)

norm()

计算向量的模长(长度) :return: 向量模长结果(float)

example:

pt = DmDPoint(3, 4, 0)
print(pt.norm())
Source code in dimine_python_sdk\lib\types\point.py
281
282
283
284
285
286
287
288
289
290
291
292
def norm(self) -> float:
    """
    计算向量的模长(长度)
    :return: 向量模长结果(float)

    example:
    ```python
    pt = DmDPoint(3, 4, 0)
    print(pt.norm())
    ```
    """
    return self._obj.Norm()

normalize()

向量归一化(原地修改,转为单位向量) :return: 自身实例

example:

pt = DmDPoint(3, 4, 0)
pt.normalize()
print(pt)
Source code in dimine_python_sdk\lib\types\point.py
294
295
296
297
298
299
300
301
302
303
304
305
306
307
def normalize(self) -> "DmDPoint":
    """
    向量归一化(原地修改,转为单位向量)
    :return: 自身实例

    example:
    ```python
    pt = DmDPoint(3, 4, 0)
    pt.normalize()
    print(pt)
    ```
    """
    self._obj.Normalize()
    return self

set(x, y, z)

一次性设置向量x/y/z分量(原地修改) :param x: 新的x分量值(float) :param y: 新的y分量值(float) :param z: 新的z分量值(float) :return: 自身实例(支持链式调用)

example:

pt = DmDPoint()
pt.set(1, 2, 3)
print(pt)  # 输出: (1.0, 2.0, 3.0)
Source code in dimine_python_sdk\lib\types\point.py
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
def set(self, x: float, y: float, z: float) -> "DmDPoint":
    """
    一次性设置向量x/y/z分量(原地修改)
    :param x: 新的x分量值(float)
    :param y: 新的y分量值(float)
    :param z: 新的z分量值(float)
    :return: 自身实例(支持链式调用)

    example:
    ```python
    pt = DmDPoint()
    pt.set(1, 2, 3)
    print(pt)  # 输出: (1.0, 2.0, 3.0)
    ```
    """
    self._obj.Set(float(x), float(y), float(z))
    return self

DmDbPoint

点实体

Source code in dimine_python_sdk\lib\types\point.py
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
class DmDbPoint:
    """点实体"""
    def __init__(self):
        """构造函数,初始化数据库点对象"""
        self._obj = Dm.dmDbPoint()

    def get_graph_data(self) -> DmDPoint:
        """
        获取该点的图形数据(坐标信息)
        :return: 点的坐标(DmDPoint实例)

        example:
        ```python
        if entity.get_type() == ETT_POINT:
            graph_data = entity.get_graph_data()
            print(graph_data)
        ```
        """
        cpp_result = self._obj.GetGraphData()
        return DmDPoint._from_obj(cpp_result)

    @classmethod
    def _from_obj(cls, obj):
        """
        :param obj: 原生dmDbPoint对象
        :return: DmDbPoint实例
        """
        instance = cls.__new__(cls)
        instance._obj = obj
        return instance

__init__()

构造函数,初始化数据库点对象

Source code in dimine_python_sdk\lib\types\point.py
668
669
670
def __init__(self):
    """构造函数,初始化数据库点对象"""
    self._obj = Dm.dmDbPoint()

get_graph_data()

获取该点的图形数据(坐标信息) :return: 点的坐标(DmDPoint实例)

example:

if entity.get_type() == ETT_POINT:
    graph_data = entity.get_graph_data()
    print(graph_data)
Source code in dimine_python_sdk\lib\types\point.py
672
673
674
675
676
677
678
679
680
681
682
683
684
685
def get_graph_data(self) -> DmDPoint:
    """
    获取该点的图形数据(坐标信息)
    :return: 点的坐标(DmDPoint实例)

    example:
    ```python
    if entity.get_type() == ETT_POINT:
        graph_data = entity.get_graph_data()
        print(graph_data)
    ```
    """
    cpp_result = self._obj.GetGraphData()
    return DmDPoint._from_obj(cpp_result)

DmPoints

点集类

Source code in dimine_python_sdk\lib\types\point.py
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
class DmPoints:
    """点集类"""

    def __init__(self):
        """
        构造函数:初始化点集合对象
        :return: None
        """
        self._obj = Dm.dmPoints()

    def insert_point(self, point: DmDPoint, point_id: int) -> None:
        """
        插入一个点并指定ID,ID不连续则会在中间插入[0,0,0]
        :param point: 待插入的点(DmDPoint实例)
        :param point_id: 点的唯一ID(整数)

        example:
        ```python
        points = DmPoints()
        points.insert_point(DmDPoint(1, 2, 3), 0)
        ```
        """
        self._obj.InsertPoint(point._obj, point_id)

    def insert_next_point(self, point: DmDPoint) -> int:
        """
        插入下一个点,自动分配ID
        :param point: 待插入的点(DmDPoint实例)
        :return: 自动分配的点索引(整数)

        example:
        ```python
        points = DmPoints()
        point_id = points.insert_next_point(DmDPoint(1, 2, 3))
        ```
        """
        return self._obj.InsertNextPoint(point._obj)

    def get_point_data_list(self) -> list[DmDPoint]:
        """
        获取所有点的坐标数据
        :return: 点列表,每个元素为DmDPoint实例

        example:
        ```python
        points = DmPoints()
        points.insert_point(DmDPoint(1, 2, 3), 0)
        points.insert_point(DmDPoint(4, 5, 6), 1)
        point_list = points.get_point_data_list()
        for point in point_list:
            print(point)
        ```
        """
        cpp_list = self._obj.GetPointData()
        return [DmDPoint._from_obj(item) for item in cpp_list]

    def __repr__(self) -> str:
        """
        字符串表示(直接调用源端实现,包含点数量和坐标)
        :return: 点集合的标准字符串表示
        """
        return self._obj.__repr__()

    @classmethod
    def _from_obj(cls, obj):
        """
        :param obj: 原生dmPoints对象
        :return: DmPoints实例
        """
        instance = cls.__new__(cls)
        instance._obj = obj
        return instance

__init__()

构造函数:初始化点集合对象 :return: None

Source code in dimine_python_sdk\lib\types\point.py
595
596
597
598
599
600
def __init__(self):
    """
    构造函数:初始化点集合对象
    :return: None
    """
    self._obj = Dm.dmPoints()

__repr__()

字符串表示(直接调用源端实现,包含点数量和坐标) :return: 点集合的标准字符串表示

Source code in dimine_python_sdk\lib\types\point.py
648
649
650
651
652
653
def __repr__(self) -> str:
    """
    字符串表示(直接调用源端实现,包含点数量和坐标)
    :return: 点集合的标准字符串表示
    """
    return self._obj.__repr__()

get_point_data_list()

获取所有点的坐标数据 :return: 点列表,每个元素为DmDPoint实例

example:

points = DmPoints()
points.insert_point(DmDPoint(1, 2, 3), 0)
points.insert_point(DmDPoint(4, 5, 6), 1)
point_list = points.get_point_data_list()
for point in point_list:
    print(point)
Source code in dimine_python_sdk\lib\types\point.py
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
def get_point_data_list(self) -> list[DmDPoint]:
    """
    获取所有点的坐标数据
    :return: 点列表,每个元素为DmDPoint实例

    example:
    ```python
    points = DmPoints()
    points.insert_point(DmDPoint(1, 2, 3), 0)
    points.insert_point(DmDPoint(4, 5, 6), 1)
    point_list = points.get_point_data_list()
    for point in point_list:
        print(point)
    ```
    """
    cpp_list = self._obj.GetPointData()
    return [DmDPoint._from_obj(item) for item in cpp_list]

insert_next_point(point)

插入下一个点,自动分配ID :param point: 待插入的点(DmDPoint实例) :return: 自动分配的点索引(整数)

example:

points = DmPoints()
point_id = points.insert_next_point(DmDPoint(1, 2, 3))
Source code in dimine_python_sdk\lib\types\point.py
616
617
618
619
620
621
622
623
624
625
626
627
628
def insert_next_point(self, point: DmDPoint) -> int:
    """
    插入下一个点,自动分配ID
    :param point: 待插入的点(DmDPoint实例)
    :return: 自动分配的点索引(整数)

    example:
    ```python
    points = DmPoints()
    point_id = points.insert_next_point(DmDPoint(1, 2, 3))
    ```
    """
    return self._obj.InsertNextPoint(point._obj)

insert_point(point, point_id)

插入一个点并指定ID,ID不连续则会在中间插入[0,0,0] :param point: 待插入的点(DmDPoint实例) :param point_id: 点的唯一ID(整数)

example:

points = DmPoints()
points.insert_point(DmDPoint(1, 2, 3), 0)
Source code in dimine_python_sdk\lib\types\point.py
602
603
604
605
606
607
608
609
610
611
612
613
614
def insert_point(self, point: DmDPoint, point_id: int) -> None:
    """
    插入一个点并指定ID,ID不连续则会在中间插入[0,0,0]
    :param point: 待插入的点(DmDPoint实例)
    :param point_id: 点的唯一ID(整数)

    example:
    ```python
    points = DmPoints()
    points.insert_point(DmDPoint(1, 2, 3), 0)
    ```
    """
    self._obj.InsertPoint(point._obj, point_id)

Point

二次封装Point类

Source code in dimine_python_sdk\lib\types\point.py
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
class Point:
    """二次封装Point类"""
    def __init__(self, a: int = 0):
        """
        构造函数
        :param a: 初始化x分量的值,默认0
        """
        self._obj = Dm.Point(a)

    # ---------------------- 核心方法封装 ----------------------
    def get(self) -> int:
        """
        获取x分量的值
        :return: x分量的整数值
        """
        return self._obj.get()

    def set(self, a: int) -> None:
        """
        设置x分量的值
        :param a: 新的x分量整数值
        """
        self._obj.set(a)

__init__(a=0)

构造函数 :param a: 初始化x分量的值,默认0

Source code in dimine_python_sdk\lib\types\point.py
 6
 7
 8
 9
10
11
def __init__(self, a: int = 0):
    """
    构造函数
    :param a: 初始化x分量的值,默认0
    """
    self._obj = Dm.Point(a)

get()

获取x分量的值 :return: x分量的整数值

Source code in dimine_python_sdk\lib\types\point.py
14
15
16
17
18
19
def get(self) -> int:
    """
    获取x分量的值
    :return: x分量的整数值
    """
    return self._obj.get()

set(a)

设置x分量的值 :param a: 新的x分量整数值

Source code in dimine_python_sdk\lib\types\point.py
21
22
23
24
25
26
def set(self, a: int) -> None:
    """
    设置x分量的值
    :param a: 新的x分量整数值
    """
    self._obj.set(a)