1
1
"""Point data."""
2
+ from __future__ import annotations
3
+
4
+ from typing import TYPE_CHECKING
5
+
6
+ if TYPE_CHECKING :
7
+ from ansys .edb .core .typing import ValueLike , PointLike
8
+ from ansys .edb .core .utility .value import Value
9
+ from typing import Iterable
10
+
2
11
from functools import reduce
3
12
import math
4
13
import operator
@@ -18,12 +27,12 @@ class PointData:
18
27
session .StubType .point_data
19
28
)
20
29
21
- def __init__ (self , * data ):
30
+ def __init__ (self , * data : Iterable [ ValueLike ] ):
22
31
"""Initialize point data from a list of coordinates.
23
32
24
33
Parameters
25
34
----------
26
- data : Iterable[Iterable[ansys.edb.core.typing.ValueLike], ansys.edb.core.typing. ValueLike]
35
+ data : :obj:`list` of :term:` ValueLike`
27
36
"""
28
37
self ._x = self ._y = self ._arc_h = None
29
38
@@ -49,20 +58,20 @@ def __init__(self, *data):
49
58
f"two values representing x and y coordinates. - Received '{ data } '"
50
59
)
51
60
52
- def __eq__ (self , other ) :
61
+ def __eq__ (self , other : PointData ) -> bool :
53
62
"""Determine if two objects represent the same coordinates.
54
63
55
64
Parameters
56
65
----------
57
- other : PointData
66
+ other : . PointData
58
67
59
68
Returns
60
69
-------
61
70
bool
62
71
"""
63
72
return self .equals (other )
64
73
65
- def __len__ (self ):
74
+ def __len__ (self ) -> int :
66
75
"""Return the number of coordinates present.
67
76
68
77
Returns
@@ -71,33 +80,33 @@ def __len__(self):
71
80
"""
72
81
return len (self ._matrix_values )
73
82
74
- def __add__ (self , other ) :
83
+ def __add__ (self , other : PointLike ) -> PointData :
75
84
"""Perform matrix addition of two points.
76
85
77
86
Parameters
78
87
----------
79
- other : ansys.edb.core.typing.PointLike
88
+ other : :term:`Point2DLike`
80
89
81
90
Returns
82
91
-------
83
- PointData
92
+ . PointData
84
93
"""
85
94
return self .__class__ (self ._map_reduce (other , operator .__add__ ))
86
95
87
- def __sub__ (self , other ) :
96
+ def __sub__ (self , other : PointLike ) -> PointData :
88
97
"""Perform matrix subtraction of two points.
89
98
90
99
Parameters
91
100
----------
92
- other : ansys.edb.core.typing.PointLike
101
+ other : :term:`Point2DLike`
93
102
94
103
Returns
95
104
-------
96
- PointData
105
+ . PointData
97
106
"""
98
107
return self .__class__ (self ._map_reduce (other , operator .__sub__ ))
99
108
100
- def __str__ (self ):
109
+ def __str__ (self ) -> str :
101
110
"""Generate unique name for the point object.
102
111
103
112
Returns
@@ -107,13 +116,13 @@ def __str__(self):
107
116
coord = "," .join ([str (v ) for v in self ._matrix_values ])
108
117
return f"<{ coord } >" if self .is_arc else f"({ coord } )"
109
118
110
- def equals (self , other , tolerance = 0.0 ):
119
+ def equals (self , other , tolerance : float = 0.0 ) -> bool :
111
120
"""Determine if two points are located at the same coordinates.
112
121
113
122
Parameters
114
123
----------
115
- other : ansys.edb.core.typing.PointLike
116
- tolerance : float, optional
124
+ other : :term:`Point2DLike`
125
+ tolerance : float, default: 0.0
117
126
118
127
Returns
119
128
-------
@@ -131,7 +140,7 @@ def value_equals(a, b):
131
140
return False
132
141
133
142
@property
134
- def _matrix_values (self ):
143
+ def _matrix_values (self ) -> list [ Value ] :
135
144
""":obj:`list` of :class:`.Value`: Coordinates of the point as a list of values."""
136
145
return [self .arc_height ] if self .is_arc else [self .x , self .y ]
137
146
@@ -140,31 +149,31 @@ def _map_reduce(self, other, op):
140
149
return [reduce (op , values ) for values in zip (self ._matrix_values , other ._matrix_values )]
141
150
142
151
@property
143
- def is_arc (self ):
152
+ def is_arc (self ) -> bool :
144
153
""":obj:`bool`: Flag indicating if the point represents an arc."""
145
154
return self ._arc_h is not None
146
155
147
156
@property
148
- def arc_height (self ):
157
+ def arc_height (self ) -> Value :
149
158
""":class:`.Value`: Height of the arc."""
150
159
return self ._arc_h
151
160
152
161
@property
153
- def x (self ):
162
+ def x (self ) -> Value :
154
163
""":class:`.Value`: X coordinate."""
155
164
return self ._x
156
165
157
166
@property
158
- def y (self ):
167
+ def y (self ) -> Value :
159
168
""":class:`.Value`: Y coordinate."""
160
169
return self ._y
161
170
162
171
@property
163
- def is_parametric (self ):
172
+ def is_parametric (self ) -> bool :
164
173
""":obj:`bool`: Flag indicating if the point contains parametric values (variable expressions)."""
165
174
return any (val .is_parametric for val in self ._matrix_values )
166
175
167
- def magnitude (self ):
176
+ def magnitude (self ) -> float :
168
177
"""Get the magnitude of the point vector.
169
178
170
179
Returns
@@ -176,7 +185,7 @@ def magnitude(self):
176
185
return 0
177
186
return math .sqrt (sum ([v ** 2 for v in self ._matrix_values ], value .Value (0 )).value )
178
187
179
- def normalized (self ):
188
+ def normalized (self ) -> PointData :
180
189
"""Normalize the point vector.
181
190
182
191
Returns
@@ -188,32 +197,32 @@ def normalized(self):
188
197
return self .__class__ (n )
189
198
190
199
@parser .to_point_data
191
- def closest (self , start , end ) :
200
+ def closest (self , start : PointLike , end : PointLike ) -> PointData | None :
192
201
"""Get the closest point on a line segment from the point.
193
202
194
203
Parameters
195
204
----------
196
- start : ansys.edb.core.typing.PointLike
205
+ start : :term:`Point2DLike`
197
206
Start point of the line segment.
198
- end : ansys.edb.core.typing.PointLike
207
+ end : :term:`Point2DLike`
199
208
End point of the line segment.
200
209
201
210
Returns
202
211
-------
203
- typing.Optional[ PointData] or `` None` ` if either point is an arc.
212
+ . PointData or :obj:` None` if either point is an arc.
204
213
"""
205
214
if not self .is_arc :
206
215
return self .__stub .ClosestPoint (messages .point_data_with_line_message (self , start , end ))
207
216
208
- def distance (self , start , end = None ):
217
+ def distance (self , start : PointLike , end : PointLike = None ) -> float :
209
218
"""Compute the shortest distance from the point to a line segment when an end point is given. \
210
219
Otherwise, compute the distance between this point and another point.
211
220
212
221
Parameters
213
222
----------
214
- start : ansys.edb.core.typing.PointLike
223
+ start : :term:`Point2DLike`
215
224
Start point of the line segment.
216
- end : ansys.edb.core.typing.PointLike , default: None
225
+ end : :term:`Point2DLike` , default: None
217
226
End point of the line segment.
218
227
219
228
Returns
@@ -227,62 +236,62 @@ def distance(self, start, end=None):
227
236
messages .point_data_with_line_message (self , start , end )
228
237
).value
229
238
230
- def cross (self , other ) :
239
+ def cross (self , other : PointLike ) -> Value | None :
231
240
"""Compute the cross product of the point vector with another point vector.
232
241
233
242
Parameters
234
243
----------
235
- other : ansys.edb.core.typing.PointLike
244
+ other : :term:`Point2DLike`
236
245
Other point vector.
237
246
238
247
Returns
239
248
-------
240
- typing.Optional[. Value] or `` None` ` if either point is an arc.
249
+ . Value or :obj:` None` if either point is an arc.
241
250
"""
242
251
other = conversions .to_point (other )
243
252
if not self .is_arc and not other .is_arc :
244
253
return self .x * other .y - self .y * other .x
245
254
246
- def move (self , vector ) :
255
+ def move (self , vector : PointLike ) -> PointData :
247
256
"""Move the point by a vector.
248
257
249
258
Parameters
250
259
----------
251
- vector : ansys.edb.core.typing.PointLike
260
+ vector : :term:`Point2DLike`
252
261
Vector.
253
262
254
263
Returns
255
264
-------
256
- typing.Optional[ PointData] or `` None` ` if either point is an arc.
265
+ . PointData or :obj:` None` if either point is an arc.
257
266
"""
258
267
vector = conversions .to_point (vector )
259
268
if not self .is_arc and not vector .is_arc :
260
269
return self + vector
261
270
262
271
@parser .to_point_data
263
- def rotate (self , angle , center ) :
272
+ def rotate (self , angle : float , center : PointLike ) -> PointData | None :
264
273
"""Rotate a point at a given center by a given angle.
265
274
266
275
Parameters
267
276
----------
268
277
angle : float
269
278
Angle in radians.
270
- center : ansys.edb.core.typing.PointLike
279
+ center : :term:`Point2DLike`
271
280
Center.
272
281
273
282
Returns
274
283
-------
275
- typing.Optional[ PointData] or `` None` ` if either point is an arc.
284
+ . PointData or :obj:` None` if either point is an arc.
276
285
"""
277
286
if not self .is_arc :
278
287
return self .__stub .Rotate (messages .point_data_rotate_message (self , center , angle ))
279
288
280
- def dot (self , other ) :
289
+ def dot (self , other : PointLike ) -> float :
281
290
"""Perform per-component multiplication (dot product) of this point and another point.
282
291
283
292
Parameters
284
293
----------
285
- other : ansys.edb.core.typing.PointLike
294
+ other : :term:`Point2DLike`
286
295
Other point.
287
296
288
297
Returns
@@ -292,12 +301,12 @@ def dot(self, other):
292
301
"""
293
302
return sum (self ._map_reduce (other , operator .__mul__ ), value .Value (0 )).value
294
303
295
- def angle (self , other ) :
304
+ def angle (self , other : PointLike ) -> float :
296
305
"""Get the angle between this vector and another vector.
297
306
298
307
Parameters
299
308
----------
300
- other : ansys.edb.core.typing.PointLike
309
+ other : :term:`Point2DLike`
301
310
Other vector.
302
311
303
312
Returns
0 commit comments