MCPcopy Index your code
hub / github.com/TheAlgorithms/Python / _construct_points

Function _construct_points

divide_and_conquer/convex_hull.py:88–132  ·  view source on GitHub ↗

constructs a list of points from an array-like object of numbers Arguments --------- list_of_tuples: array-like object of type numbers. Acceptable types so far are lists, tuples and sets. Returns -------- points: a list where each item is of type Point. This conta

(
    list_of_tuples: list[Point] | list[list[float]] | Iterable[list[float]],
)

Source from the content-addressed store, hash-verified

86
87
88def _construct_points(
89 list_of_tuples: list[Point] | list[list[float]] | Iterable[list[float]],
90) -> list[Point]:
91 """
92 constructs a list of points from an array-like object of numbers
93
94 Arguments
95 ---------
96
97 list_of_tuples: array-like object of type numbers. Acceptable types so far
98 are lists, tuples and sets.
99
100 Returns
101 --------
102 points: a list where each item is of type Point. This contains only objects
103 which can be converted into a Point.
104
105 Examples
106 -------
107 >>> _construct_points([[1, 1], [2, -1], [0.3, 4]])
108 [(1.0, 1.0), (2.0, -1.0), (0.3, 4.0)]
109 >>> _construct_points([1, 2])
110 Ignoring deformed point 1. All points must have at least 2 coordinates.
111 Ignoring deformed point 2. All points must have at least 2 coordinates.
112 []
113 >>> _construct_points([])
114 []
115 >>> _construct_points(None)
116 []
117 """
118
119 points: list[Point] = []
120 if list_of_tuples:
121 for p in list_of_tuples:
122 if isinstance(p, Point):
123 points.append(p)
124 else:
125 try:
126 points.append(Point(p[0], p[1]))
127 except IndexError, TypeError:
128 print(
129 f"Ignoring deformed point {p}. All points"
130 " must have at least 2 coordinates."
131 )
132 return points
133
134
135def _validate_input(points: list[Point] | list[list[float]]) -> list[Point]:

Callers 1

_validate_inputFunction · 0.85

Calls 2

PointClass · 0.70
appendMethod · 0.45

Tested by

no test coverage detected