Goulib.drawing module¶
Read/Write and handle vector graphics in .dxf, .svg and .pdf formats
| requires: |
|---|
- svg.path for svg input
- matplotlib for bitmap + svg and pdf output
- dxfwrite for dxf output
| optional: |
|---|
- dxfgrabber for dxf input
- pdfminer.six for pdf input
-
Goulib.drawing.Trans(scale=1, offset=None, rotation=None)[source]¶ Parameters: - scale – float or (scalex,scaley) tuple of scale factor
- offset –
Vector3 - rotation – float angle in degrees
Returns: Matrix3of generalized scale+offset+rotation
-
class
Goulib.drawing.BBox(p1=None, p2=None)[source]¶ Bases:
Goulib.interval.Boxbounding box
Parameters: - pt1 –
Point2first corner (any) - pt2 –
Point2opposite corner (any)
-
__init__(p1=None, p2=None)[source]¶ Parameters: - pt1 –
Point2first corner (any) - pt2 –
Point2opposite corner (any)
- pt1 –
-
xmin¶
-
ymin¶
-
xmax¶
-
ymax¶
-
xmed¶
-
ymed¶
-
width¶
-
height¶
-
area¶
- pt1 –
-
class
Goulib.drawing.Entity[source]¶ Bases:
Goulib.plot.PlotBase class for all drawing entities
-
color= 'black'¶
-
setattr(**kwargs)[source]¶ set (graphic) attributes to entity :param kwargs: dict of attributes copied to entity
-
start¶
-
end¶
-
center¶
-
to_dxf(**attr)[source]¶ Parameters: attr – dict of attributes passed to the dxf entity, overriding those defined in self Returns: dxf entity
-
static
from_pdf(path, trans, color)[source]¶ Parameters: path – pdf path Returns: Entity of correct subtype
-
static
from_dxf(e, mat3)[source]¶ Parameters: - e – dxf.entity
- mat3 – Matrix3 transform
Returns: Entity of correct subtype
-
patches(**kwargs)[source]¶ Returns: list of (a single) Patchcorresponding to entityNote: this is the only method that needs to be overridden in descendants for draw, render and IPython _repr_xxx_ to work
-
static
figure(box, **kwargs)[source]¶ Parameters: - box –
drawing.BBoxbounds and clipping box - kwargs – parameters passed to ~matplotlib.pyplot.figure
Returns: matplotlib axis suitable for drawing
- box –
-
-
class
Goulib.drawing.Spline(points)[source]¶ Bases:
Goulib.drawing.Entity,Goulib.geom.Geometrycubic spline segment
Parameters: points – list of (x,y) tuples -
start¶
-
end¶
-
xy¶
-
length¶ Returns: float (very) approximate length
-
__abstractmethods__= frozenset()¶
-
-
class
Goulib.drawing.Group[source]¶ Bases:
list,Goulib.drawing._Groupgroup of Entities but it is a Geometry since we can intersect, connect and compute distances between Groups
-
color¶ str(object=’‘) -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.__str__() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to ‘strict’.
-
layer¶
-
append(entity, **kwargs)[source]¶ append entity to group :param entity: Entity :param kwargs: dict of attributes copied to entity :return: Group (or Chain) to which the entity was added, or None if entity was None
-
from_dxf(dxf, layers=None, only=[], ignore=['POINT'], trans=Matrix3(1.0, 0, 0, 0, 1.0, 0, 0, 0, 1.0), flatten=False)[source]¶ Parameters: - dxf – dxf.entity
- layers – list of layer names to consider. entities not on these layers are ignored. default=None: all layers are read
- only – list of dxf entity types names that are read. default=[]: all are read
- ignore – list of dxf entity types names that are ignored. default=[‘POINT’]: points and null length segments are ignored
- trans –
Transoptional transform matrix
Parm flatten: bool flatten block structure
Returns: Entityof correct subtype
-
__abstractmethods__= frozenset()¶
-
-
class
Goulib.drawing.Instance(group, trans)[source]¶ Bases:
Goulib.drawing._GroupParameters: - group – Group
- trans – optional mat3 of transformation
-
static
from_dxf(e, blocks, mat3)[source]¶ Parameters: - e – dxf.entity
- blocks – dict of Groups indexed by name
- mat3 – Matrix3 transform
-
__abstractmethods__= frozenset()¶
-
class
Goulib.drawing.Chain(data=[])[source]¶ Bases:
Goulib.drawing.Groupgroup of contiguous Entities (Polyline or similar)
-
start¶
-
end¶
-
contiguous(edge, abs_tol=1e-06, allow_swap=True)[source]¶ check if edge can be appended to the chain :param edge:
Entityto append :param tol: float tolerance on contiguity :param allow_swap: if True (default), tries to swap edge or self to find contiguity :return: int,bool index where to append in chain, swap of edge required
-
append(entity, tol=1e-06, allow_swap=True, mergeable=None, **attrs)[source]¶ append entity to chain, ensuring contiguity :param entity:
Entityto append :param tol: float tolerance on contiguity :param allow_swap: if True (default), tries to swap edge or self to find contiguity :param mergeable: function of the form f(e1,e2) returning True if entities e1,e2 can be merged :param attrs: attributes passed to Group.append :return: self, or None if edge is not contiguous
-
static
from_pdf(path, trans, color)[source]¶ Parameters: path – pdf path Returns: Entity of correct subtype See: http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/PDF32000_2008.pdf p. 132
-
static
from_dxf(e, mat3)[source]¶ Parameters: - e – dxf.entity
- mat3 – Matrix3 transform
Returns: Entity of correct subtype
-
to_dxf(split=False, **attr)[source]¶ Parameters: - split – bool if True, each segment in Chain is saved separately
- attr – dict of graphic attributes
Returns: polyline or list of entities along the chain
-
__abstractmethods__= frozenset()¶
-
-
Goulib.drawing.chains(group, tol=1e-06, mergeable=None)[source]¶ build chains from all possible segments in group :param mergeable: function(e1,e2) returning True if entities e1,e2 can be merged
-
class
Goulib.drawing.Rect(*args)[source]¶ Bases:
Goulib.drawing.Chaina rectangle starting at low/left and going trigowise through top/right
-
p1¶
-
p2¶
-
__abstractmethods__= frozenset()¶
-
-
class
Goulib.drawing.Text(text, point, size=12, rotation=0)[source]¶ Bases:
Goulib.drawing.EntityParameters: - text – string
- point – Point2
- size – size in points
- rotation – float angle in degrees trigowise
-
__init__(text, point, size=12, rotation=0)[source]¶ Parameters: - text – string
- point – Point2
- size – size in points
- rotation – float angle in degrees trigowise
-
length¶ Returns: float length of the text contour in mm
-
class
Goulib.drawing.Drawing(data=[], **kwargs)[source]¶ Bases:
Goulib.drawing.Grouplist of Entities representing a vector graphics drawing
-
read_pdf(filename, **kwargs)[source]¶ reads a vector graphics on a .pdf file only the first page is parsed
-
read_svg(content, **kwargs)[source]¶ appends svg content to drawing :param content: string, either filename or svg content
-
__abstractmethods__= frozenset()¶
-
Classes¶

Read/Write and handle vector graphics in .dxf, .svg and .pdf formats
| requires: |
|---|
- svg.path for svg input
- matplotlib for bitmap + svg and pdf output
- dxfwrite for dxf output
| optional: |
|---|
- dxfgrabber for dxf input
- pdfminer.six for pdf input
-
Goulib.drawing.Trans(scale=1, offset=None, rotation=None)[source] Parameters: - scale – float or (scalex,scaley) tuple of scale factor
- offset –
Vector3 - rotation – float angle in degrees
Returns: Matrix3of generalized scale+offset+rotation
-
class
Goulib.drawing.BBox(p1=None, p2=None)[source] Bases:
Goulib.interval.Boxbounding box
Parameters: - pt1 –
Point2first corner (any) - pt2 –
Point2opposite corner (any)
-
__init__(p1=None, p2=None)[source] Parameters: - pt1 –
Point2first corner (any) - pt2 –
Point2opposite corner (any)
- pt1 –
-
xmin
-
ymin
-
xmax
-
ymax
-
xmed
-
ymed
-
width
-
height
-
area
-
__contains__(other)[source] Returns: True if other lies in bounding box.
-
__iadd__(pt)[source] enlarge box if required to contain specified point :param pt1:
geom.Point2point to add
-
__call__()[source] Returns: list of flatten corners
-
size()[source] Returns: geom.Vector2with xy sizes
-
center()[source] Returns: Pt center
-
__add__(other)¶ enlarge box if required to contain specified point :param other:
Boxor (list of) N-tuple point(s) :return: new Box containing both
-
__class__¶ alias of
builtins.type
-
__delattr__¶ Implement delattr(self, name).
-
__delitem__¶ Delete self[key].
-
__dir__()¶ Default dir() implementation.
-
__eq__¶ Return self==value.
-
__format__()¶ Default object formatter.
-
__ge__¶ Return self>=value.
-
__getattribute__¶ Return getattr(self, name).
-
__getitem__()¶ x.__getitem__(y) <==> x[y]
-
__gt__¶ Return self>value.
-
__hash__= None¶
-
__imul__¶ Implement self*=value.
-
__init_subclass__()¶ This method is called when a class is subclassed.
The default implementation does nothing. It may be overridden to extend subclasses.
-
__iter__¶ Implement iter(self).
-
__le__¶ Return self<=value.
-
__len__¶ Return len(self).
-
__lt__¶ Return self<value.
-
__mul__¶ Return self*value.
-
__ne__¶ Return self!=value.
-
__new__()¶ Create and return a new object. See help(type) for accurate signature.
-
__nonzero__()¶
-
__reduce__()¶ Helper for pickle.
-
__reduce_ex__()¶ Helper for pickle.
-
__repr__¶ Return repr(self).
-
__reversed__()¶ Return a reverse iterator over the list.
-
__rmul__¶ Return value*self.
-
__setattr__¶ Implement setattr(self, name, value).
-
__setitem__¶ Set self[key] to value.
-
__sizeof__()¶ Return the size of the list in memory, in bytes.
-
__str__¶ Return str(self).
-
append()¶ Append object to the end of the list.
-
clear()¶ Remove all items from list.
-
copy()¶ Return a shallow copy of the list.
-
corner(n)¶ return n-th corner of box 0-th corner is “start” made of all minimal values of intervals -1.th corner is “end”, made of all maximal values of intervals
-
count()¶ Return number of occurrences of value.
-
empty()¶ Returns: True iff Box is empty.
-
end¶
-
extend()¶ Extend list by appending elements from the iterable.
-
index()¶ Return first index of value.
Raises ValueError if the value is not present.
-
insert()¶ Insert object before index.
-
max¶
-
min¶
-
pop()¶ Remove and return item at index (default last).
Raises IndexError if list is empty or index is out of range.
-
remove()¶ Remove first occurrence of value.
Raises ValueError if the value is not present.
-
reverse()¶ Reverse IN PLACE.
-
sort()¶ Stable sort IN PLACE.
-
start¶
- pt1 –
-
class
Goulib.drawing.Entity[source] Bases:
Goulib.plot.PlotBase class for all drawing entities
-
color= 'black'
-
setattr(**kwargs)[source] set (graphic) attributes to entity :param kwargs: dict of attributes copied to entity
-
start
-
end
-
__repr__()[source] Return repr(self).
-
center
-
isclosed()[source]
-
isline()[source]
-
isvertical(tol=0.01)[source]
-
ishorizontal(tol=0.01)[source]
-
to_dxf(**attr)[source] Parameters: attr – dict of attributes passed to the dxf entity, overriding those defined in self Returns: dxf entity
-
static
from_svg(path, color)[source] Parameters: path – svg path Returns: Entity of correct subtype
-
static
from_pdf(path, trans, color)[source] Parameters: path – pdf path Returns: Entity of correct subtype
-
static
from_dxf(e, mat3)[source] Parameters: - e – dxf.entity
- mat3 – Matrix3 transform
Returns: Entity of correct subtype
-
patches(**kwargs)[source] Returns: list of (a single) Patchcorresponding to entityNote: this is the only method that needs to be overridden in descendants for draw, render and IPython _repr_xxx_ to work
-
static
figure(box, **kwargs)[source] Parameters: - box –
drawing.BBoxbounds and clipping box - kwargs – parameters passed to ~matplotlib.pyplot.figure
Returns: matplotlib axis suitable for drawing
- box –
-
draw(fig=None, **kwargs)[source] draw entities :param fig: matplotlib figure where to draw. figure(g) is called if missing :return: fig,patch
-
render(fmt, **kwargs)[source] render graph to bitmap stream :return: matplotlib figure as a byte stream in specified format
-
__class__¶ alias of
builtins.type
-
__delattr__¶ Implement delattr(self, name).
-
__dir__()¶ Default dir() implementation.
-
__eq__¶ Return self==value.
-
__format__()¶ Default object formatter.
-
__ge__¶ Return self>=value.
-
__getattribute__¶ Return getattr(self, name).
-
__gt__¶ Return self>value.
-
__hash__¶ Return hash(self).
-
__init__¶ Initialize self. See help(type(self)) for accurate signature.
-
__init_subclass__()¶ This method is called when a class is subclassed.
The default implementation does nothing. It may be overridden to extend subclasses.
-
__le__¶ Return self<=value.
-
__lt__¶ Return self<value.
-
__ne__¶ Return self!=value.
-
__new__()¶ Create and return a new object. See help(type) for accurate signature.
-
__reduce__()¶ Helper for pickle.
-
__reduce_ex__()¶ Helper for pickle.
-
__setattr__¶ Implement setattr(self, name, value).
-
__sizeof__()¶ Size of object in memory, in bytes.
-
__str__¶ Return str(self).
-
html(**kwargs)¶
-
plot(**kwargs)¶ renders on IPython Notebook (alias to make usage more straightforward)
-
png(**kwargs)¶
-
save(filename, **kwargs)¶
-
svg(**kwargs)¶
-
-
class
Goulib.drawing.Spline(points)[source] Bases:
Goulib.drawing.Entity,Goulib.geom.Geometrycubic spline segment
Parameters: points – list of (x,y) tuples -
__init__(points)[source] Parameters: points – list of (x,y) tuples
-
start
-
end
-
xy
-
length Returns: float (very) approximate length
-
swap()[source] swap start and end
-
__abstractmethods__= frozenset()
-
__class__¶ alias of
abc.ABCMeta
-
__contains__(pt)¶
-
__delattr__¶ Implement delattr(self, name).
-
__dir__()¶ Default dir() implementation.
-
__eq__¶ Return self==value.
-
__format__()¶ Default object formatter.
-
__ge__¶ Return self>=value.
-
__getattribute__¶ Return getattr(self, name).
-
__gt__¶ Return self>value.
-
__hash__¶ Return hash(self).
-
__init_subclass__()¶ This method is called when a class is subclassed.
The default implementation does nothing. It may be overridden to extend subclasses.
-
__le__¶ Return self<=value.
-
__lt__¶ Return self<value.
-
__ne__¶ Return self!=value.
-
__new__()¶ Create and return a new object. See help(type) for accurate signature.
-
__reduce__()¶ Helper for pickle.
-
__reduce_ex__()¶ Helper for pickle.
-
__repr__()¶ Return repr(self).
-
__setattr__¶ Implement setattr(self, name, value).
-
__sizeof__()¶ Size of object in memory, in bytes.
-
__str__¶ Return str(self).
-
center¶
-
color= 'black'¶
-
connect(other)¶ Returns: Geometry shortest (Segment2 or Segment3) that connects self to other
-
distance(other)¶
-
draw(fig=None, **kwargs)¶ draw entities :param fig: matplotlib figure where to draw. figure(g) is called if missing :return: fig,patch
-
static
figure(box, **kwargs)¶ Parameters: - box –
drawing.BBoxbounds and clipping box - kwargs – parameters passed to ~matplotlib.pyplot.figure
Returns: matplotlib axis suitable for drawing
- box –
-
static
from_dxf(e, mat3)¶ Parameters: - e – dxf.entity
- mat3 – Matrix3 transform
Returns: Entity of correct subtype
-
static
from_pdf(path, trans, color)¶ Parameters: path – pdf path Returns: Entity of correct subtype
-
static
from_svg(path, color)¶ Parameters: path – svg path Returns: Entity of correct subtype
-
html(**kwargs)¶
-
intersect(other)¶
-
isclosed()¶
-
ishorizontal(tol=0.01)¶
-
isline()¶
-
isvertical(tol=0.01)¶
-
patches(**kwargs)¶ Returns: list of (a single) Patchcorresponding to entityNote: this is the only method that needs to be overridden in descendants for draw, render and IPython _repr_xxx_ to work
-
plot(**kwargs)¶ renders on IPython Notebook (alias to make usage more straightforward)
-
png(**kwargs)¶
-
point(u)¶ Returns: Point2 or Point3 at parameter u
-
render(fmt, **kwargs)¶ render graph to bitmap stream :return: matplotlib figure as a byte stream in specified format
-
save(filename, **kwargs)¶
-
setattr(**kwargs)¶ set (graphic) attributes to entity :param kwargs: dict of attributes copied to entity
-
svg(**kwargs)¶
-
tangent(u)¶ Returns: Vector2 or Vector3 tangent at parameter u
-
to_dxf(**attr)¶ Parameters: attr – dict of attributes passed to the dxf entity, overriding those defined in self Returns: dxf entity
-
-
class
Goulib.drawing.Group[source] Bases:
list,Goulib.drawing._Groupgroup of Entities but it is a Geometry since we can intersect, connect and compute distances between Groups
-
color str(object=’‘) -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.__str__() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to ‘strict’.
-
layer
-
append(entity, **kwargs)[source] append entity to group :param entity: Entity :param kwargs: dict of attributes copied to entity :return: Group (or Chain) to which the entity was added, or None if entity was None
-
extend(entities, **kwargs)[source] Extend list by appending elements from the iterable.
-
__copy__()[source]
-
swap()[source] swap start and end
-
chainify(mergeable)[source] merge all possible entities into chains
-
from_dxf(dxf, layers=None, only=[], ignore=['POINT'], trans=Matrix3(1.0, 0, 0, 0, 1.0, 0, 0, 0, 1.0), flatten=False)[source] Parameters: - dxf – dxf.entity
- layers – list of layer names to consider. entities not on these layers are ignored. default=None: all layers are read
- only – list of dxf entity types names that are read. default=[]: all are read
- ignore – list of dxf entity types names that are ignored. default=[‘POINT’]: points and null length segments are ignored
- trans –
Transoptional transform matrix
Parm flatten: bool flatten block structure
Returns: Entityof correct subtype
-
__abstractmethods__= frozenset()
-
__add__¶ Return self+value.
-
__class__¶ alias of
abc.ABCMeta
-
__contains__¶ Return key in self.
-
__delattr__¶ Implement delattr(self, name).
-
__delitem__¶ Delete self[key].
-
__dir__()¶ Default dir() implementation.
-
__eq__¶ Return self==value.
-
__format__()¶ Default object formatter.
-
__ge__¶ Return self>=value.
-
__getattribute__¶ Return getattr(self, name).
-
__getitem__()¶ x.__getitem__(y) <==> x[y]
-
__gt__¶ Return self>value.
-
__hash__= None¶
-
__iadd__¶ Implement self+=value.
-
__imul__¶ Implement self*=value.
-
__init__¶ Initialize self. See help(type(self)) for accurate signature.
-
__init_subclass__()¶ This method is called when a class is subclassed.
The default implementation does nothing. It may be overridden to extend subclasses.
-
__iter__¶ Implement iter(self).
-
__le__¶ Return self<=value.
-
__len__¶ Return len(self).
-
__lt__¶ Return self<value.
-
__mul__¶ Return self*value.
-
__ne__¶ Return self!=value.
-
__new__()¶ Create and return a new object. See help(type) for accurate signature.
-
__reduce__()¶ Helper for pickle.
-
__reduce_ex__()¶ Helper for pickle.
-
__repr__¶ Return repr(self).
-
__reversed__()¶ Return a reverse iterator over the list.
-
__rmul__¶ Return value*self.
-
__setattr__¶ Implement setattr(self, name, value).
-
__setitem__¶ Set self[key] to value.
-
__sizeof__()¶ Return the size of the list in memory, in bytes.
-
__str__¶ Return str(self).
-
bbox(filter=None)¶ Parameters: filter – optional function(entity):bool returning True if entity should be considered in box Returns: BBoxbounding box of Entity
-
center¶
-
clear()¶ Remove all items from list.
-
connect(other)¶ Returns: Geometry shortest (Segment2 or Segment3) that connects self to other
-
copy()¶ Return a shallow copy of the list.
-
count()¶ Return number of occurrences of value.
-
distance(other)¶
-
draw(fig=None, **kwargs)¶ draw entities :param fig: matplotlib figure where to draw. figure(g) is called if missing :return: fig,patch
-
end¶
-
static
figure(box, **kwargs)¶ Parameters: - box –
drawing.BBoxbounds and clipping box - kwargs – parameters passed to ~matplotlib.pyplot.figure
Returns: matplotlib axis suitable for drawing
- box –
-
static
from_pdf(path, trans, color)¶ Parameters: path – pdf path Returns: Entity of correct subtype
-
static
from_svg(path, color)¶ Parameters: path – svg path Returns: Entity of correct subtype
-
html(**kwargs)¶
-
index()¶ Return first index of value.
Raises ValueError if the value is not present.
-
insert()¶ Insert object before index.
-
intersect(other)¶ Parameters: other – geom.Entity Result: generate tuples (Point2,Entity_self) of intersections between other and each Entity
-
isclosed()¶
-
ishorizontal(tol=0.01)¶
-
isline()¶
-
isvertical(tol=0.01)¶
-
length¶
-
plot(**kwargs)¶ renders on IPython Notebook (alias to make usage more straightforward)
-
png(**kwargs)¶
-
point(u)¶ Returns: Point2 or Point3 at parameter u
-
pop()¶ Remove and return item at index (default last).
Raises IndexError if list is empty or index is out of range.
-
remove()¶ Remove first occurrence of value.
Raises ValueError if the value is not present.
-
render(fmt, **kwargs)¶ render graph to bitmap stream :return: matplotlib figure as a byte stream in specified format
-
reverse()¶ Reverse IN PLACE.
-
save(filename, **kwargs)¶
-
setattr(**kwargs)¶ set (graphic) attributes to entity :param kwargs: dict of attributes copied to entity
-
sort()¶ Stable sort IN PLACE.
-
start¶
-
svg(**kwargs)¶
-
tangent(u)¶ Returns: Vector2 or Vector3 tangent at parameter u
-
to_dxf(**kwargs)¶ Returns: flatten list of dxf entities
-
-
class
Goulib.drawing.Instance(group, trans)[source] Bases:
Goulib.drawing._GroupParameters: - group – Group
- trans – optional mat3 of transformation
-
__init__(group, trans)[source] Parameters: - group – Group
- trans – optional mat3 of transformation
-
static
from_dxf(e, blocks, mat3)[source] Parameters: - e – dxf.entity
- blocks – dict of Groups indexed by name
- mat3 – Matrix3 transform
-
__repr__()[source] Return repr(self).
-
__iter__()[source]
-
__abstractmethods__= frozenset()
-
__class__¶ alias of
abc.ABCMeta
-
__contains__(pt)¶
-
__delattr__¶ Implement delattr(self, name).
-
__dir__()¶ Default dir() implementation.
-
__eq__¶ Return self==value.
-
__format__()¶ Default object formatter.
-
__ge__¶ Return self>=value.
-
__getattribute__¶ Return getattr(self, name).
-
__gt__¶ Return self>value.
-
__hash__¶ Return hash(self).
-
__init_subclass__()¶ This method is called when a class is subclassed.
The default implementation does nothing. It may be overridden to extend subclasses.
-
__le__¶ Return self<=value.
-
__lt__¶ Return self<value.
-
__ne__¶ Return self!=value.
-
__new__()¶ Create and return a new object. See help(type) for accurate signature.
-
__reduce__()¶ Helper for pickle.
-
__reduce_ex__()¶ Helper for pickle.
-
__setattr__¶ Implement setattr(self, name, value).
-
__sizeof__()¶ Size of object in memory, in bytes.
-
__str__¶ Return str(self).
-
bbox(filter=None)¶ Parameters: filter – optional function(entity):bool returning True if entity should be considered in box Returns: BBoxbounding box of Entity
-
center¶
-
color= 'black'¶
-
connect(other)¶ Returns: Geometry shortest (Segment2 or Segment3) that connects self to other
-
distance(other)¶
-
draw(fig=None, **kwargs)¶ draw entities :param fig: matplotlib figure where to draw. figure(g) is called if missing :return: fig,patch
-
end¶
-
static
figure(box, **kwargs)¶ Parameters: - box –
drawing.BBoxbounds and clipping box - kwargs – parameters passed to ~matplotlib.pyplot.figure
Returns: matplotlib axis suitable for drawing
- box –
-
static
from_pdf(path, trans, color)¶ Parameters: path – pdf path Returns: Entity of correct subtype
-
static
from_svg(path, color)¶ Parameters: path – svg path Returns: Entity of correct subtype
-
html(**kwargs)¶
-
intersect(other)¶ Parameters: other – geom.Entity Result: generate tuples (Point2,Entity_self) of intersections between other and each Entity
-
isclosed()¶
-
ishorizontal(tol=0.01)¶
-
isline()¶
-
isvertical(tol=0.01)¶
-
length¶
-
plot(**kwargs)¶ renders on IPython Notebook (alias to make usage more straightforward)
-
png(**kwargs)¶
-
point(u)¶ Returns: Point2 or Point3 at parameter u
-
render(fmt, **kwargs)¶ render graph to bitmap stream :return: matplotlib figure as a byte stream in specified format
-
save(filename, **kwargs)¶
-
setattr(**kwargs)¶ set (graphic) attributes to entity :param kwargs: dict of attributes copied to entity
-
start¶
-
svg(**kwargs)¶
-
tangent(u)¶ Returns: Vector2 or Vector3 tangent at parameter u
-
to_dxf(**kwargs)¶ Returns: flatten list of dxf entities
-
class
Goulib.drawing.Chain(data=[])[source] Bases:
Goulib.drawing.Groupgroup of contiguous Entities (Polyline or similar)
-
__init__(data=[])[source] Initialize self. See help(type(self)) for accurate signature.
-
start
-
end
-
__repr__()[source] Return repr(self).
-
contiguous(edge, abs_tol=1e-06, allow_swap=True)[source] check if edge can be appended to the chain :param edge:
Entityto append :param tol: float tolerance on contiguity :param allow_swap: if True (default), tries to swap edge or self to find contiguity :return: int,bool index where to append in chain, swap of edge required
-
append(entity, tol=1e-06, allow_swap=True, mergeable=None, **attrs)[source] append entity to chain, ensuring contiguity :param entity:
Entityto append :param tol: float tolerance on contiguity :param allow_swap: if True (default), tries to swap edge or self to find contiguity :param mergeable: function of the form f(e1,e2) returning True if entities e1,e2 can be merged :param attrs: attributes passed to Group.append :return: self, or None if edge is not contiguous
-
static
from_pdf(path, trans, color)[source] Parameters: path – pdf path Returns: Entity of correct subtype See: http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/PDF32000_2008.pdf p. 132
-
static
from_svg(path, color)[source] Parameters: path – svg path Returns: Entity of correct subtype
-
static
from_dxf(e, mat3)[source] Parameters: - e – dxf.entity
- mat3 – Matrix3 transform
Returns: Entity of correct subtype
-
to_dxf(split=False, **attr)[source] Parameters: - split – bool if True, each segment in Chain is saved separately
- attr – dict of graphic attributes
Returns: polyline or list of entities along the chain
-
__abstractmethods__= frozenset()
-
__add__¶ Return self+value.
-
__class__¶ alias of
abc.ABCMeta
-
__contains__¶ Return key in self.
-
__copy__()¶
-
__delattr__¶ Implement delattr(self, name).
-
__delitem__¶ Delete self[key].
-
__dir__()¶ Default dir() implementation.
-
__eq__¶ Return self==value.
-
__format__()¶ Default object formatter.
-
__ge__¶ Return self>=value.
-
__getattribute__¶ Return getattr(self, name).
-
__getitem__()¶ x.__getitem__(y) <==> x[y]
-
__gt__¶ Return self>value.
-
__hash__= None¶
-
__iadd__¶ Implement self+=value.
-
__imul__¶ Implement self*=value.
-
__init_subclass__()¶ This method is called when a class is subclassed.
The default implementation does nothing. It may be overridden to extend subclasses.
-
__iter__¶ Implement iter(self).
-
__le__¶ Return self<=value.
-
__len__¶ Return len(self).
-
__lt__¶ Return self<value.
-
__mul__¶ Return self*value.
-
__ne__¶ Return self!=value.
-
__new__()¶ Create and return a new object. See help(type) for accurate signature.
-
__reduce__()¶ Helper for pickle.
-
__reduce_ex__()¶ Helper for pickle.
-
__reversed__()¶ Return a reverse iterator over the list.
-
__rmul__¶ Return value*self.
-
__setattr__¶ Implement setattr(self, name, value).
-
__setitem__¶ Set self[key] to value.
-
__sizeof__()¶ Return the size of the list in memory, in bytes.
-
__str__¶ Return str(self).
-
bbox(filter=None)¶ Parameters: filter – optional function(entity):bool returning True if entity should be considered in box Returns: BBoxbounding box of Entity
-
center¶
-
chainify(mergeable)¶ merge all possible entities into chains
-
clear()¶ Remove all items from list.
-
color¶ str(object=’‘) -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.__str__() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to ‘strict’.
-
connect(other)¶ Returns: Geometry shortest (Segment2 or Segment3) that connects self to other
-
copy()¶ Return a shallow copy of the list.
-
count()¶ Return number of occurrences of value.
-
distance(other)¶
-
draw(fig=None, **kwargs)¶ draw entities :param fig: matplotlib figure where to draw. figure(g) is called if missing :return: fig,patch
-
extend(entities, **kwargs)¶ Extend list by appending elements from the iterable.
-
static
figure(box, **kwargs)¶ Parameters: - box –
drawing.BBoxbounds and clipping box - kwargs – parameters passed to ~matplotlib.pyplot.figure
Returns: matplotlib axis suitable for drawing
- box –
-
html(**kwargs)¶
-
index()¶ Return first index of value.
Raises ValueError if the value is not present.
-
insert()¶ Insert object before index.
-
intersect(other)¶ Parameters: other – geom.Entity Result: generate tuples (Point2,Entity_self) of intersections between other and each Entity
-
isclosed()¶
-
ishorizontal(tol=0.01)¶
-
isline()¶
-
isvertical(tol=0.01)¶
-
layer¶
-
length¶
-
plot(**kwargs)¶ renders on IPython Notebook (alias to make usage more straightforward)
-
png(**kwargs)¶
-
point(u)¶ Returns: Point2 or Point3 at parameter u
-
pop()¶ Remove and return item at index (default last).
Raises IndexError if list is empty or index is out of range.
-
remove()¶ Remove first occurrence of value.
Raises ValueError if the value is not present.
-
render(fmt, **kwargs)¶ render graph to bitmap stream :return: matplotlib figure as a byte stream in specified format
-
reverse()¶ Reverse IN PLACE.
-
save(filename, **kwargs)¶
-
setattr(**kwargs)¶ set (graphic) attributes to entity :param kwargs: dict of attributes copied to entity
-
sort()¶ Stable sort IN PLACE.
-
svg(**kwargs)¶
-
swap()¶ swap start and end
-
tangent(u)¶ Returns: Vector2 or Vector3 tangent at parameter u
-
-
Goulib.drawing.chains(group, tol=1e-06, mergeable=None)[source] build chains from all possible segments in group :param mergeable: function(e1,e2) returning True if entities e1,e2 can be merged
-
class
Goulib.drawing.Rect(*args)[source] Bases:
Goulib.drawing.Chaina rectangle starting at low/left and going trigowise through top/right
-
__init__(*args)[source] Initialize self. See help(type(self)) for accurate signature.
-
p1
-
p2
-
__repr__()[source] Return repr(self).
-
__abstractmethods__= frozenset()
-
__add__¶ Return self+value.
-
__class__¶ alias of
abc.ABCMeta
-
__contains__¶ Return key in self.
-
__copy__()¶
-
__delattr__¶ Implement delattr(self, name).
-
__delitem__¶ Delete self[key].
-
__dir__()¶ Default dir() implementation.
-
__eq__¶ Return self==value.
-
__format__()¶ Default object formatter.
-
__ge__¶ Return self>=value.
-
__getattribute__¶ Return getattr(self, name).
-
__getitem__()¶ x.__getitem__(y) <==> x[y]
-
__gt__¶ Return self>value.
-
__hash__= None¶
-
__iadd__¶ Implement self+=value.
-
__imul__¶ Implement self*=value.
-
__init_subclass__()¶ This method is called when a class is subclassed.
The default implementation does nothing. It may be overridden to extend subclasses.
-
__iter__¶ Implement iter(self).
-
__le__¶ Return self<=value.
-
__len__¶ Return len(self).
-
__lt__¶ Return self<value.
-
__mul__¶ Return self*value.
-
__ne__¶ Return self!=value.
-
__new__()¶ Create and return a new object. See help(type) for accurate signature.
-
__reduce__()¶ Helper for pickle.
-
__reduce_ex__()¶ Helper for pickle.
-
__reversed__()¶ Return a reverse iterator over the list.
-
__rmul__¶ Return value*self.
-
__setattr__¶ Implement setattr(self, name, value).
-
__setitem__¶ Set self[key] to value.
-
__sizeof__()¶ Return the size of the list in memory, in bytes.
-
__str__¶ Return str(self).
-
append(entity, tol=1e-06, allow_swap=True, mergeable=None, **attrs)¶ append entity to chain, ensuring contiguity :param entity:
Entityto append :param tol: float tolerance on contiguity :param allow_swap: if True (default), tries to swap edge or self to find contiguity :param mergeable: function of the form f(e1,e2) returning True if entities e1,e2 can be merged :param attrs: attributes passed to Group.append :return: self, or None if edge is not contiguous
-
bbox(filter=None)¶ Parameters: filter – optional function(entity):bool returning True if entity should be considered in box Returns: BBoxbounding box of Entity
-
center¶
-
chainify(mergeable)¶ merge all possible entities into chains
-
clear()¶ Remove all items from list.
-
color¶ str(object=’‘) -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.__str__() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to ‘strict’.
-
connect(other)¶ Returns: Geometry shortest (Segment2 or Segment3) that connects self to other
-
contiguous(edge, abs_tol=1e-06, allow_swap=True)¶ check if edge can be appended to the chain :param edge:
Entityto append :param tol: float tolerance on contiguity :param allow_swap: if True (default), tries to swap edge or self to find contiguity :return: int,bool index where to append in chain, swap of edge required
-
copy()¶ Return a shallow copy of the list.
-
count()¶ Return number of occurrences of value.
-
distance(other)¶
-
draw(fig=None, **kwargs)¶ draw entities :param fig: matplotlib figure where to draw. figure(g) is called if missing :return: fig,patch
-
end¶
-
extend(entities, **kwargs)¶ Extend list by appending elements from the iterable.
-
static
figure(box, **kwargs)¶ Parameters: - box –
drawing.BBoxbounds and clipping box - kwargs – parameters passed to ~matplotlib.pyplot.figure
Returns: matplotlib axis suitable for drawing
- box –
-
static
from_dxf(e, mat3)¶ Parameters: - e – dxf.entity
- mat3 – Matrix3 transform
Returns: Entity of correct subtype
-
static
from_pdf(path, trans, color)¶ Parameters: path – pdf path Returns: Entity of correct subtype See: http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/PDF32000_2008.pdf p. 132
-
static
from_svg(path, color)¶ Parameters: path – svg path Returns: Entity of correct subtype
-
html(**kwargs)¶
-
index()¶ Return first index of value.
Raises ValueError if the value is not present.
-
insert()¶ Insert object before index.
-
intersect(other)¶ Parameters: other – geom.Entity Result: generate tuples (Point2,Entity_self) of intersections between other and each Entity
-
isclosed()¶
-
ishorizontal(tol=0.01)¶
-
isline()¶
-
isvertical(tol=0.01)¶
-
layer¶
-
length¶
-
plot(**kwargs)¶ renders on IPython Notebook (alias to make usage more straightforward)
-
png(**kwargs)¶
-
point(u)¶ Returns: Point2 or Point3 at parameter u
-
pop()¶ Remove and return item at index (default last).
Raises IndexError if list is empty or index is out of range.
-
remove()¶ Remove first occurrence of value.
Raises ValueError if the value is not present.
-
render(fmt, **kwargs)¶ render graph to bitmap stream :return: matplotlib figure as a byte stream in specified format
-
reverse()¶ Reverse IN PLACE.
-
save(filename, **kwargs)¶
-
setattr(**kwargs)¶ set (graphic) attributes to entity :param kwargs: dict of attributes copied to entity
-
sort()¶ Stable sort IN PLACE.
-
start¶
-
svg(**kwargs)¶
-
swap()¶ swap start and end
-
tangent(u)¶ Returns: Vector2 or Vector3 tangent at parameter u
-
to_dxf(split=False, **attr)¶ Parameters: - split – bool if True, each segment in Chain is saved separately
- attr – dict of graphic attributes
Returns: polyline or list of entities along the chain
-
-
class
Goulib.drawing.Text(text, point, size=12, rotation=0)[source] Bases:
Goulib.drawing.EntityParameters: - text – string
- point – Point2
- size – size in points
- rotation – float angle in degrees trigowise
-
__init__(text, point, size=12, rotation=0)[source] Parameters: - text – string
- point – Point2
- size – size in points
- rotation – float angle in degrees trigowise
-
length Returns: float length of the text contour in mm
-
intersect(other)[source]
-
to_dxf(**attr)[source] Parameters: attr – dict of attributes passed to the dxf entity, overriding those defined in self Returns: dxf entity
-
__class__¶ alias of
builtins.type
-
__delattr__¶ Implement delattr(self, name).
-
__dir__()¶ Default dir() implementation.
-
__eq__¶ Return self==value.
-
__format__()¶ Default object formatter.
-
__ge__¶ Return self>=value.
-
__getattribute__¶ Return getattr(self, name).
-
__gt__¶ Return self>value.
-
__hash__¶ Return hash(self).
-
__init_subclass__()¶ This method is called when a class is subclassed.
The default implementation does nothing. It may be overridden to extend subclasses.
-
__le__¶ Return self<=value.
-
__lt__¶ Return self<value.
-
__ne__¶ Return self!=value.
-
__new__()¶ Create and return a new object. See help(type) for accurate signature.
-
__reduce__()¶ Helper for pickle.
-
__reduce_ex__()¶ Helper for pickle.
-
__repr__()¶ Return repr(self).
-
__setattr__¶ Implement setattr(self, name, value).
-
__sizeof__()¶ Size of object in memory, in bytes.
-
__str__¶ Return str(self).
-
center¶
-
color= 'black'¶
-
draw(fig=None, **kwargs)¶ draw entities :param fig: matplotlib figure where to draw. figure(g) is called if missing :return: fig,patch
-
end¶
-
static
figure(box, **kwargs)¶ Parameters: - box –
drawing.BBoxbounds and clipping box - kwargs – parameters passed to ~matplotlib.pyplot.figure
Returns: matplotlib axis suitable for drawing
- box –
-
static
from_dxf(e, mat3)¶ Parameters: - e – dxf.entity
- mat3 – Matrix3 transform
Returns: Entity of correct subtype
-
static
from_pdf(path, trans, color)¶ Parameters: path – pdf path Returns: Entity of correct subtype
-
static
from_svg(path, color)¶ Parameters: path – svg path Returns: Entity of correct subtype
-
html(**kwargs)¶
-
isclosed()¶
-
ishorizontal(tol=0.01)¶
-
isline()¶
-
isvertical(tol=0.01)¶
-
plot(**kwargs)¶ renders on IPython Notebook (alias to make usage more straightforward)
-
png(**kwargs)¶
-
render(fmt, **kwargs)¶ render graph to bitmap stream :return: matplotlib figure as a byte stream in specified format
-
save(filename, **kwargs)¶
-
setattr(**kwargs)¶ set (graphic) attributes to entity :param kwargs: dict of attributes copied to entity
-
start¶
-
svg(**kwargs)¶
-
class
Goulib.drawing.Drawing(data=[], **kwargs)[source] Bases:
Goulib.drawing.Grouplist of Entities representing a vector graphics drawing
-
__init__(data=[], **kwargs)[source] Initialize self. See help(type(self)) for accurate signature.
-
load(filename, **kwargs)[source]
-
read_pdf(filename, **kwargs)[source] reads a vector graphics on a .pdf file only the first page is parsed
-
read_svg(content, **kwargs)[source] appends svg content to drawing :param content: string, either filename or svg content
-
__abstractmethods__= frozenset()
-
__add__¶ Return self+value.
-
__class__¶ alias of
abc.ABCMeta
-
__contains__¶ Return key in self.
-
__copy__()¶
-
__delattr__¶ Implement delattr(self, name).
-
__delitem__¶ Delete self[key].
-
__dir__()¶ Default dir() implementation.
-
__eq__¶ Return self==value.
-
__format__()¶ Default object formatter.
-
__ge__¶ Return self>=value.
-
__getattribute__¶ Return getattr(self, name).
-
__getitem__()¶ x.__getitem__(y) <==> x[y]
-
__gt__¶ Return self>value.
-
__hash__= None¶
-
__iadd__¶ Implement self+=value.
-
__imul__¶ Implement self*=value.
-
__init_subclass__()¶ This method is called when a class is subclassed.
The default implementation does nothing. It may be overridden to extend subclasses.
-
__iter__¶ Implement iter(self).
-
__le__¶ Return self<=value.
-
__len__¶ Return len(self).
-
__lt__¶ Return self<value.
-
__mul__¶ Return self*value.
-
__ne__¶ Return self!=value.
-
__new__()¶ Create and return a new object. See help(type) for accurate signature.
-
__reduce__()¶ Helper for pickle.
-
__reduce_ex__()¶ Helper for pickle.
-
__repr__¶ Return repr(self).
-
__reversed__()¶ Return a reverse iterator over the list.
-
__rmul__¶ Return value*self.
-
__setattr__¶ Implement setattr(self, name, value).
-
__setitem__¶ Set self[key] to value.
-
__sizeof__()¶ Return the size of the list in memory, in bytes.
-
__str__¶ Return str(self).
-
append(entity, **kwargs)¶ append entity to group :param entity: Entity :param kwargs: dict of attributes copied to entity :return: Group (or Chain) to which the entity was added, or None if entity was None
-
bbox(filter=None)¶ Parameters: filter – optional function(entity):bool returning True if entity should be considered in box Returns: BBoxbounding box of Entity
-
center¶
-
chainify(mergeable)¶ merge all possible entities into chains
-
clear()¶ Remove all items from list.
-
color¶ str(object=’‘) -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.__str__() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to ‘strict’.
-
connect(other)¶ Returns: Geometry shortest (Segment2 or Segment3) that connects self to other
-
copy()¶ Return a shallow copy of the list.
-
count()¶ Return number of occurrences of value.
-
distance(other)¶
-
draw(fig=None, **kwargs)¶ draw entities :param fig: matplotlib figure where to draw. figure(g) is called if missing :return: fig,patch
-
end¶
-
extend(entities, **kwargs)¶ Extend list by appending elements from the iterable.
-
static
figure(box, **kwargs)¶ Parameters: - box –
drawing.BBoxbounds and clipping box - kwargs – parameters passed to ~matplotlib.pyplot.figure
Returns: matplotlib axis suitable for drawing
- box –
-
from_dxf(dxf, layers=None, only=[], ignore=['POINT'], trans=Matrix3(1.0, 0, 0, 0, 1.0, 0, 0, 0, 1.0), flatten=False)¶ Parameters: - dxf – dxf.entity
- layers – list of layer names to consider. entities not on these layers are ignored. default=None: all layers are read
- only – list of dxf entity types names that are read. default=[]: all are read
- ignore – list of dxf entity types names that are ignored. default=[‘POINT’]: points and null length segments are ignored
- trans –
Transoptional transform matrix
Parm flatten: bool flatten block structure
Returns: Entityof correct subtype
-
static
from_pdf(path, trans, color)¶ Parameters: path – pdf path Returns: Entity of correct subtype
-
static
from_svg(path, color)¶ Parameters: path – svg path Returns: Entity of correct subtype
-
html(**kwargs)¶
-
index()¶ Return first index of value.
Raises ValueError if the value is not present.
-
insert()¶ Insert object before index.
-
intersect(other)¶ Parameters: other – geom.Entity Result: generate tuples (Point2,Entity_self) of intersections between other and each Entity
-
isclosed()¶
-
ishorizontal(tol=0.01)¶
-
isline()¶
-
isvertical(tol=0.01)¶
-
layer¶
-
length¶
-
plot(**kwargs)¶ renders on IPython Notebook (alias to make usage more straightforward)
-
png(**kwargs)¶
-
point(u)¶ Returns: Point2 or Point3 at parameter u
-
pop()¶ Remove and return item at index (default last).
Raises IndexError if list is empty or index is out of range.
-
read_dxf(filename, options=None, **kwargs)[source] reads a .dxf file :param filename: string path to .dxf file to read :param options: passed to
from_dxf
-
remove()¶ Remove first occurrence of value.
Raises ValueError if the value is not present.
-
render(fmt, **kwargs)¶ render graph to bitmap stream :return: matplotlib figure as a byte stream in specified format
-
reverse()¶ Reverse IN PLACE.
-
setattr(**kwargs)¶ set (graphic) attributes to entity :param kwargs: dict of attributes copied to entity
-
sort()¶ Stable sort IN PLACE.
-
start¶
-
svg(**kwargs)¶
-
swap()¶ swap start and end
-
tangent(u)¶ Returns: Vector2 or Vector3 tangent at parameter u
-
to_dxf(**kwargs)¶ Returns: flatten list of dxf entities
-
save(filename, **kwargs)[source] save graph in various formats
-