polliwog/polyline/polyline.py
def partition_by_length(self, max_length, ret_indices=False):
        """
        Subdivide each line segment longer than max_length with
        equal-length segments, such that none of the new segments
        are longer than max_length.

        ret_indices: If True, return the indices of the original vertices.
          Otherwise return self for chaining.

        """
        import itertools
        from ..segment.segment import partition_segment

        old_num_e = self.num_e
        old_num_v = self.num_v
        num_segments_needed = np.ceil(self.segment_lengths / max_length).astype(
            dtype=np.int64
        )
        es_to_subdivide, = (num_segments_needed > 1).nonzero()
        vs_to_insert = [
            partition_segment(
                self.v[self.e[old_e_index][0]],
                self.v[self.e[old_e_index][1]],
                np.int(num_segments_needed[old_e_index]),
                endpoint=False,
            )[
                # Exclude the start point, which like the endpoint, is already
                # present.
                1:
            ]
            for old_e_index in es_to_subdivide
        ]

        splits_of_original_vs = np.vsplit(self.v, es_to_subdivide + 1)
        self.v = np.concatenate(
            list(
                itertools.chain(
                    *zip(
                        splits_of_original_vs,
                        vs_to_insert + [np.empty((0, 3), dtype=np.float64)],
                    )
                )
            )
        )

        if ret_indices:
            # In a degenerate case, `partition_segment()` may return fewer than
            # the requested number of indices. So, recompute the actual number of
            # segments inserted.
            num_segments_inserted = np.zeros(old_num_e, dtype=np.int64)
            num_segments_inserted[es_to_subdivide] = [len(vs) for vs in vs_to_insert]
            stepwise_index_offsets = np.concatenate(
                [
                    # The first vertex is never moved.
                    np.zeros(1, dtype=np.int64),
                    # In a closed polyline, the last edge goes back to vertex
                    # 0. Subdivisions of that segment do not affect indexing of
                    # any of the vertices (since the original end vertex is
                    # still at index 0).
                    num_segments_inserted[:-1]
                    if self.is_closed
                    else num_segments_inserted,
                ]
            )
            cumulative_index_offsets = np.sum(
                np.tril(
                    np.broadcast_to(stepwise_index_offsets, (old_num_v, old_num_v))
                ),
                axis=1,
            )
            return np.arange(old_num_v) + cumulative_index_offsets
        else:
            return self

        Subdivide each line segment longer than max_length with
        equal-length segments, such that none of the new segments
        are longer than max_length.

        ret_indices: If True, return the indices of the original vertices.
          Otherwise return self for chaining.

        
Subdivide each line segment longer than max_length with
equal-length segments, such that none of the new segments
are longer than max_length.

If True, return the indices of the original vertices.
Otherwise return self for chaining.
Subdivide each line segment longer than max_length with equal - length segments such that none of the new segments are longer than max_length . If True return the indices of the original vertices . Otherwise return self for chaining .
def partition_by_length(self, max_length, ret_indices=False):
        import itertools
        from ..segment.segment import partition_segment
        old_num_e = self.num_e
        old_num_v = self.num_v
        num_segments_needed = np.ceil(self.segment_lengths / max_length).astype(
            dtype=np.int64
        )
        es_to_subdivide, = (num_segments_needed > 1).nonzero()
        vs_to_insert = [
            partition_segment(
                self.v[self.e[old_e_index][0]],
                self.v[self.e[old_e_index][1]],
                np.int(num_segments_needed[old_e_index]),
                endpoint=False,
            )[
                1:
            ]
            for old_e_index in es_to_subdivide
        ]
        splits_of_original_vs = np.vsplit(self.v, es_to_subdivide + 1)
        self.v = np.concatenate(
            list(
                itertools.chain(
                    *zip(
                        splits_of_original_vs,
                        vs_to_insert + [np.empty((0, 3), dtype=np.float64)],
                    )
                )
            )
        )
        if ret_indices:
            num_segments_inserted = np.zeros(old_num_e, dtype=np.int64)
            num_segments_inserted[es_to_subdivide] = [len(vs) for vs in vs_to_insert]
            stepwise_index_offsets = np.concatenate(
                [
                    np.zeros(1, dtype=np.int64),
                    num_segments_inserted[:-1]
                    if self.is_closed
                    else num_segments_inserted,
                ]
            )
            cumulative_index_offsets = np.sum(
                np.tril(
                    np.broadcast_to(stepwise_index_offsets, (old_num_v, old_num_v))
                ),
                axis=1,
            )
            return np.arange(old_num_v) + cumulative_index_offsets
        else:
            return self
def partition_by_length ( self , max_length , ret_indices = False ) : import itertools from . . segment . segment import partition_segment old_num_e = self . num_e old_num_v = self . num_v num_segments_needed = np . ceil ( self . segment_lengths / max_length ) . astype ( dtype = np . int64 ) es_to_subdivide , = ( num_segments_needed > 1 ) . nonzero ( ) vs_to_insert = [ partition_segment ( self . v [ self . e [ old_e_index ] [ 0 ] ] , self . v [ self . e [ old_e_index ] [ 1 ] ] , np . int ( num_segments_needed [ old_e_index ] ) , endpoint = False , ) [ 1 : ] for old_e_index in es_to_subdivide ] splits_of_original_vs = np . vsplit ( self . v , es_to_subdivide + 1 ) self . v = np . concatenate ( list ( itertools . chain ( * zip ( splits_of_original_vs , vs_to_insert + [ np . empty ( ( 0 , 3 ) , dtype = np . float64 ) ] , ) ) ) ) if ret_indices : num_segments_inserted = np . zeros ( old_num_e , dtype = np . int64 ) num_segments_inserted [ es_to_subdivide ] = [ len ( vs ) for vs in vs_to_insert ] stepwise_index_offsets = np . concatenate ( [ np . zeros ( 1 , dtype = np . int64 ) , num_segments_inserted [ : - 1 ] if self . is_closed else num_segments_inserted , ] ) cumulative_index_offsets = np . sum ( np . tril ( np . broadcast_to ( stepwise_index_offsets , ( old_num_v , old_num_v ) ) ) , axis = 1 , ) return np . arange ( old_num_v ) + cumulative_index_offsets else : return self
Subdivide each line segment longer than max_length with
equal-length segments, such that none of the new segments
are longer than max_length.
Subdivide each line segment longer than max_length with equal - length segments such that none of the new segments are longer than max_length .
"""
        Subdivide each line segment longer than max_length with
        equal-length segments, such that none of the new segments
        are longer than max_length.

        ret_indices: If True, return the indices of the original vertices.
          Otherwise return self for chaining.

        """ # Exclude the start point, which like the endpoint, is already # present. # In a degenerate case, `partition_segment()` may return fewer than # the requested number of indices. So, recompute the actual number of # segments inserted. # The first vertex is never moved. # In a closed polyline, the last edge goes back to vertex # 0. Subdivisions of that segment do not affect indexing of # any of the vertices (since the original end vertex is # still at index 0).
self
max_length
ret_indices