Skip to content

plycutter.geometry.geom1d

plycutter.geometry.geom1d.Geom1D

Immutable sum of closed-open intervals of an 1D line.

Supports the set operations &, |, ^, - as well as ~..

Basically, open intervals except that a union of (0, 1) and (1, 2) is (0, 2). One way to accomplish this theoretically is by not including the constructible numbers in the domain.

So none of the exact numbers 0, 1 or 2 can ever be part of the infinite set of numbers contained there, only numbers that are greater or less, so then the middle point gets removed nicely.

A simpler, equivalent definition is to use lower-bound closed, upper-bound open intervals a la Python ranges but the above is more symmetric in definition wrt the real numbers. :)

Note that - is defined as set difference.

The intervals can contain infinities.

    g = Geom1D([[0, 1], [2, 3]])
    g.locate(-1) --> -1
    g.locate(0) --> 0
    g.locate(0.5) --> 1
    g.locate(1.5) --> 0

    h = Geom1D([[1, 3]])

    i = g & h  # Equivalent to Geom1D([[2, 3]])
    j = g | h  # Equivalent to Geom1D([[0, 3]])
    k = g - h  # Equivalent to Geom1D([[0, 1]])
    l = g ^ h  # Equivalent to Geom1D([[0, 2]])
    m = ~h     # Equivalent to Geom1D([[-inf, 1], [3, inf]])

Methods

buffer(self, amount)

Minkowski sum with the interval [-amount, amount].

Amount can be negative to reduce the area.

disjoint_pieces(self)

Return separate Geom1D pieces for disjoint intervals in self.

empty() classmethod

Return an empty Geom1D.

filter(self, f)

Filter all disjoint intervals in this Geom1D through the function and return a new Geom1D with those intervals that pass the filter.

full() classmethod

Return a Geom1D that covers the full real line.

is_bounded(self)

Return true if the region described by this Geom1D is bounded.

is_empty(self)

Return true if this Geom1D is empty, i.e. 0-measure.

locate(self, point)

1 = in -1 = out 0 = indeterminate, possibly on edge, possibly on internal, virtual edge

measure1d(self)

Return the 1d measure (in length) of this object