Goulib.drawing module

Read/Write and handle vector graphics in .dxf, .svg and .pdf formats

requires:
optional:
Goulib.drawing.Trans(scale=1, offset=None, rotation=None)[source]
Parameters:
  • scale – float or (scalex,scaley) tuple of scale factor
  • offsetVector3
  • rotation – float angle in degrees
Returns:

Matrix3 of generalized scale+offset+rotation

class Goulib.drawing.BBox(p1=None, p2=None)[source]

Bases: Goulib.interval.Box

bounding box

Parameters:
  • pt1Point2 first corner (any)
  • pt2Point2 opposite corner (any)
__init__(p1=None, p2=None)[source]
Parameters:
  • pt1Point2 first corner (any)
  • pt2Point2 opposite corner (any)
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.Point2 point to add

__call__()[source]
Returns:list of flatten corners
size()[source]
Returns:geom.Vector2 with xy sizes
center()[source]
Returns:Pt center
trans(trans)[source]
Parameters:trans – Xform
Returns:BBox = self transformed by trans
class Goulib.drawing.Entity[source]

Bases: Goulib.plot.Plot

Base 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]
center
bbox()[source]
Returns:BBox bounding box of Entity
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) Patch corresponding to entity
Note: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:
  • boxdrawing.BBox bounds and clipping box
  • kwargs – parameters passed to ~matplotlib.pyplot.figure
Returns:

matplotlib axis suitable for drawing

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 Goulib.drawing.Spline(points)[source]

Bases: Goulib.drawing.Entity, Goulib.geom.Geometry

cubic 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
bbox()[source]
swap()[source]

swap start and end

__abstractmethods__ = frozenset()
class Goulib.drawing.Group[source]

Bases: list, Goulib.drawing._Group

group of Entities but it is a Geometry since we can intersect, connect and compute distances between Groups

color
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]
__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
  • transTrans optional transform matrix
Parm flatten:

bool flatten block structure

Returns:

Entity of correct subtype

__abstractmethods__ = frozenset()
class Goulib.drawing.Instance(group, trans)[source]

Bases: Goulib.drawing._Group

Parameters:
  • 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]
__iter__()[source]
__abstractmethods__ = frozenset()
class Goulib.drawing.Chain(data=[])[source]

Bases: Goulib.drawing.Group

group of contiguous Entities (Polyline or similar)

__init__(data=[])[source]
start
end
__repr__()[source]
contiguous(edge, abs_tol=1e-06, allow_swap=True)[source]

check if edge can be appended to the chain :param edge: Entity to 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: Entity to 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()
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.Chain

a rectangle starting at low/left and going trigowise through top/right

__init__(*args)[source]
p1
p2
__repr__()[source]
__abstractmethods__ = frozenset()
class Goulib.drawing.Text(text, point, size=12, rotation=0)[source]

Bases: Goulib.drawing.Entity

Parameters:
  • 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
bbox()[source]
length
Returns:float length of the text contour in mm
intersect(other)[source]
to_dxf(**attr)[source]
patches(**kwargs)[source]
Returns:list of (a single) Patch corresponding to entity
class Goulib.drawing.Drawing(data=[], **kwargs)[source]

Bases: Goulib.drawing.Group

list of Entities representing a vector graphics drawing

__abstractmethods__ = frozenset()
__init__(data=[], **kwargs)[source]
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

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

save(filename, **kwargs)[source]

save graph in various formats

Classes

Inheritance diagram of BBox, Entity, Spline, Group, Chain, Drawing

Read/Write and handle vector graphics in .dxf, .svg and .pdf formats

requires:
optional:
Goulib.drawing.Trans(scale=1, offset=None, rotation=None)[source]
Parameters:
  • scale – float or (scalex,scaley) tuple of scale factor
  • offsetVector3
  • rotation – float angle in degrees
Returns:

Matrix3 of generalized scale+offset+rotation

class Goulib.drawing.BBox(p1=None, p2=None)[source]

Bases: Goulib.interval.Box

bounding box

Parameters:
  • pt1Point2 first corner (any)
  • pt2Point2 opposite corner (any)
__init__(p1=None, p2=None)[source]
Parameters:
  • pt1Point2 first corner (any)
  • pt2Point2 opposite corner (any)
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.Point2 point to add

__call__()[source]
Returns:list of flatten corners
size()[source]
Returns:geom.Vector2 with xy sizes
center()[source]
Returns:Pt center
trans(trans)[source]
Parameters:trans – Xform
Returns:BBox = self transformed by trans
__add__(other)

enlarge box if required to contain specified point :param other: Box or (list of) N-tuple point(s) :return: new Box containing both

__class__

alias of type

__delattr__

Implement delattr(self, name).

__delitem__

Delete self[key].

__dir__() → list

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.

__iter__

Implement iter(self).

__le__

Return self<=value.

__len__

Return len(self).

__lt__

Return self<value.

__mul__

Return self*value.n

__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__()

L.__reversed__() – return a reverse iterator over the list

__rmul__

Return self*value.

__setattr__

Implement setattr(self, name, value).

__setitem__

Set self[key] to value.

__sizeof__()

L.__sizeof__() – size of L in memory, in bytes

__str__

Return str(self).

append(object) → None -- append object to end
clear() → None -- remove all items from L
copy() → list -- a shallow copy of L
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(value) → integer -- return number of occurrences of value
empty()
Returns:True iff Box is empty.
end
extend(iterable) → None -- extend list by appending elements from the iterable
index(value[, start[, stop]]) → integer -- return first index of value.

Raises ValueError if the value is not present.

insert()

L.insert(index, object) – insert object before index

max
min
pop([index]) → item -- remove and return item at index (default last).

Raises IndexError if list is empty or index is out of range.

remove(value) → None -- remove first occurrence of value.

Raises ValueError if the value is not present.

reverse()

L.reverse() – reverse IN PLACE

sort(key=None, reverse=False) → None -- stable sort *IN PLACE*
start
class Goulib.drawing.Entity[source]

Bases: Goulib.plot.Plot

Base 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]
center
bbox()[source]
Returns:BBox bounding box of Entity
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) Patch corresponding to entity
Note: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:
  • boxdrawing.BBox bounds and clipping box
  • kwargs – parameters passed to ~matplotlib.pyplot.figure
Returns:

matplotlib axis suitable for drawing

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 type

__delattr__

Implement delattr(self, name).

__dir__() → list

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.

__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__() → int

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.Geometry

cubic 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
bbox()[source]
swap()[source]

swap start and end

__abstractmethods__ = frozenset()
__class__

alias of ABCMeta

__contains__(pt)
__delattr__

Implement delattr(self, name).

__dir__() → list

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).

__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__()
__setattr__

Implement setattr(self, name, value).

__sizeof__() → int

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

figure(box, **kwargs)
Parameters:
  • boxdrawing.BBox bounds and clipping box
  • kwargs – parameters passed to ~matplotlib.pyplot.figure
Returns:

matplotlib axis suitable for drawing

from_dxf(e, mat3)
Parameters:
  • e – dxf.entity
  • mat3 – Matrix3 transform
Returns:

Entity of correct subtype

from_pdf(path, trans, color)
Parameters:path – pdf path
Returns:Entity of correct subtype
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) Patch corresponding to entity
Note: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._Group

group of Entities but it is a Geometry since we can intersect, connect and compute distances between Groups

color
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]
__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
  • transTrans optional transform matrix
Parm flatten:

bool flatten block structure

Returns:

Entity of correct subtype

__abstractmethods__ = frozenset()
__add__

Return self+value.

__class__

alias of ABCMeta

__contains__

Return key in self.

__delattr__

Implement delattr(self, name).

__delitem__

Delete self[key].

__dir__() → list

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.

__iter__

Implement iter(self).

__le__

Return self<=value.

__len__

Return len(self).

__lt__

Return self<value.

__mul__

Return self*value.n

__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__()

L.__reversed__() – return a reverse iterator over the list

__rmul__

Return self*value.

__setattr__

Implement setattr(self, name, value).

__setitem__

Set self[key] to value.

__sizeof__()

L.__sizeof__() – size of L 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:BBox bounding box of Entity
center
clear() → None -- remove all items from L
connect(other)
copy() → list -- a shallow copy of L
count(value) → integer -- 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
figure(box, **kwargs)
Parameters:
  • boxdrawing.BBox bounds and clipping box
  • kwargs – parameters passed to ~matplotlib.pyplot.figure
Returns:

matplotlib axis suitable for drawing

from_pdf(path, trans, color)
Parameters:path – pdf path
Returns:Entity of correct subtype
from_svg(path, color)
Parameters:path – svg path
Returns:Entity of correct subtype
html(**kwargs)
index(value[, start[, stop]]) → integer -- return first index of value.

Raises ValueError if the value is not present.

insert()

L.insert(index, object) – insert object before index

intersect(other)
Parameters:othergeom.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
patches(**kwargs)
Returns:list of Patch corresponding to group
plot(**kwargs)

renders on IPython Notebook (alias to make usage more straightforward)

png(**kwargs)
point(u)
Returns:Point2 or Point3 at parameter u
pop([index]) → item -- remove and return item at index (default last).

Raises IndexError if list is empty or index is out of range.

remove(value) → None -- 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()

L.reverse() – reverse IN PLACE

save(filename, **kwargs)
setattr(**kwargs)

set (graphic) attributes to entity :param kwargs: dict of attributes copied to entity

sort(key=None, reverse=False) → None -- 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._Group

Parameters:
  • 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]
__iter__()[source]
__abstractmethods__ = frozenset()
__class__

alias of ABCMeta

__contains__(pt)
__delattr__

Implement delattr(self, name).

__dir__() → list

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).

__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__() → int

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:BBox bounding box of Entity
center
color = 'black'
connect(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
figure(box, **kwargs)
Parameters:
  • boxdrawing.BBox bounds and clipping box
  • kwargs – parameters passed to ~matplotlib.pyplot.figure
Returns:

matplotlib axis suitable for drawing

from_pdf(path, trans, color)
Parameters:path – pdf path
Returns:Entity of correct subtype
from_svg(path, color)
Parameters:path – svg path
Returns:Entity of correct subtype
html(**kwargs)
intersect(other)
Parameters:othergeom.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
patches(**kwargs)
Returns:list of Patch corresponding to group
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.Group

group of contiguous Entities (Polyline or similar)

__init__(data=[])[source]
start
end
__repr__()[source]
contiguous(edge, abs_tol=1e-06, allow_swap=True)[source]

check if edge can be appended to the chain :param edge: Entity to 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: Entity to 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 ABCMeta

__contains__

Return key in self.

__copy__()
__delattr__

Implement delattr(self, name).

__delitem__

Delete self[key].

__dir__() → list

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.

__iter__

Implement iter(self).

__le__

Return self<=value.

__len__

Return len(self).

__lt__

Return self<value.

__mul__

Return self*value.n

__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__()

L.__reversed__() – return a reverse iterator over the list

__rmul__

Return self*value.

__setattr__

Implement setattr(self, name, value).

__setitem__

Set self[key] to value.

__sizeof__()

L.__sizeof__() – size of L 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:BBox bounding box of Entity
center
chainify(mergeable)

merge all possible entities into chains

clear() → None -- remove all items from L
color
connect(other)
copy() → list -- a shallow copy of L
count(value) → integer -- 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)
figure(box, **kwargs)
Parameters:
  • boxdrawing.BBox bounds and clipping box
  • kwargs – parameters passed to ~matplotlib.pyplot.figure
Returns:

matplotlib axis suitable for drawing

html(**kwargs)
index(value[, start[, stop]]) → integer -- return first index of value.

Raises ValueError if the value is not present.

insert()

L.insert(index, object) – insert object before index

intersect(other)
Parameters:othergeom.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
patches(**kwargs)
Returns:list of Patch corresponding to group
plot(**kwargs)

renders on IPython Notebook (alias to make usage more straightforward)

png(**kwargs)
point(u)
Returns:Point2 or Point3 at parameter u
pop([index]) → item -- remove and return item at index (default last).

Raises IndexError if list is empty or index is out of range.

remove(value) → None -- 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()

L.reverse() – reverse IN PLACE

save(filename, **kwargs)
setattr(**kwargs)

set (graphic) attributes to entity :param kwargs: dict of attributes copied to entity

sort(key=None, reverse=False) → None -- 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.Chain

a rectangle starting at low/left and going trigowise through top/right

__init__(*args)[source]
p1
p2
__repr__()[source]
__abstractmethods__ = frozenset()
__add__

Return self+value.

__class__

alias of ABCMeta

__contains__

Return key in self.

__copy__()
__delattr__

Implement delattr(self, name).

__delitem__

Delete self[key].

__dir__() → list

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.

__iter__

Implement iter(self).

__le__

Return self<=value.

__len__

Return len(self).

__lt__

Return self<value.

__mul__

Return self*value.n

__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__()

L.__reversed__() – return a reverse iterator over the list

__rmul__

Return self*value.

__setattr__

Implement setattr(self, name, value).

__setitem__

Set self[key] to value.

__sizeof__()

L.__sizeof__() – size of L 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: Entity to 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:BBox bounding box of Entity
center
chainify(mergeable)

merge all possible entities into chains

clear() → None -- remove all items from L
color
connect(other)
contiguous(edge, abs_tol=1e-06, allow_swap=True)

check if edge can be appended to the chain :param edge: Entity to 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() → list -- a shallow copy of L
count(value) → integer -- 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)
figure(box, **kwargs)
Parameters:
  • boxdrawing.BBox bounds and clipping box
  • kwargs – parameters passed to ~matplotlib.pyplot.figure
Returns:

matplotlib axis suitable for drawing

from_dxf(e, mat3)
Parameters:
  • e – dxf.entity
  • mat3 – Matrix3 transform
Returns:

Entity of correct subtype

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
from_svg(path, color)
Parameters:path – svg path
Returns:Entity of correct subtype
html(**kwargs)
index(value[, start[, stop]]) → integer -- return first index of value.

Raises ValueError if the value is not present.

insert()

L.insert(index, object) – insert object before index

intersect(other)
Parameters:othergeom.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
patches(**kwargs)
Returns:list of Patch corresponding to group
plot(**kwargs)

renders on IPython Notebook (alias to make usage more straightforward)

png(**kwargs)
point(u)
Returns:Point2 or Point3 at parameter u
pop([index]) → item -- remove and return item at index (default last).

Raises IndexError if list is empty or index is out of range.

remove(value) → None -- 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()

L.reverse() – reverse IN PLACE

save(filename, **kwargs)
setattr(**kwargs)

set (graphic) attributes to entity :param kwargs: dict of attributes copied to entity

sort(key=None, reverse=False) → None -- 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.Entity

Parameters:
  • 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
bbox()[source]
length
Returns:float length of the text contour in mm
intersect(other)[source]
to_dxf(**attr)[source]
patches(**kwargs)[source]
Returns:list of (a single) Patch corresponding to entity
__class__

alias of type

__delattr__

Implement delattr(self, name).

__dir__() → list

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).

__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__()
__setattr__

Implement setattr(self, name, value).

__sizeof__() → int

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
figure(box, **kwargs)
Parameters:
  • boxdrawing.BBox bounds and clipping box
  • kwargs – parameters passed to ~matplotlib.pyplot.figure
Returns:

matplotlib axis suitable for drawing

from_dxf(e, mat3)
Parameters:
  • e – dxf.entity
  • mat3 – Matrix3 transform
Returns:

Entity of correct subtype

from_pdf(path, trans, color)
Parameters:path – pdf path
Returns:Entity of correct subtype
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.Group

list of Entities representing a vector graphics drawing

__abstractmethods__ = frozenset()
__add__

Return self+value.

__class__

alias of ABCMeta

__contains__

Return key in self.

__copy__()
__delattr__

Implement delattr(self, name).

__delitem__

Delete self[key].

__dir__() → list

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__(data=[], **kwargs)[source]
__iter__

Implement iter(self).

__le__

Return self<=value.

__len__

Return len(self).

__lt__

Return self<value.

__mul__

Return self*value.n

__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__()

L.__reversed__() – return a reverse iterator over the list

__rmul__

Return self*value.

__setattr__

Implement setattr(self, name, value).

__setitem__

Set self[key] to value.

__sizeof__()

L.__sizeof__() – size of L 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:BBox bounding box of Entity
center
chainify(mergeable)

merge all possible entities into chains

clear() → None -- remove all items from L
color
connect(other)
copy() → list -- a shallow copy of L
count(value) → integer -- 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)
figure(box, **kwargs)
Parameters:
  • boxdrawing.BBox bounds and clipping box
  • kwargs – parameters passed to ~matplotlib.pyplot.figure
Returns:

matplotlib axis suitable for drawing

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
  • transTrans optional transform matrix
Parm flatten:

bool flatten block structure

Returns:

Entity of correct subtype

from_pdf(path, trans, color)
Parameters:path – pdf path
Returns:Entity of correct subtype
from_svg(path, color)
Parameters:path – svg path
Returns:Entity of correct subtype
html(**kwargs)
index(value[, start[, stop]]) → integer -- return first index of value.

Raises ValueError if the value is not present.

insert()

L.insert(index, object) – insert object before index

intersect(other)
Parameters:othergeom.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
patches(**kwargs)
Returns:list of Patch corresponding to group
plot(**kwargs)

renders on IPython Notebook (alias to make usage more straightforward)

png(**kwargs)
point(u)
Returns:Point2 or Point3 at parameter u
pop([index]) → item -- remove and return item at index (default last).

Raises IndexError if list is empty or index is out of range.

remove(value) → None -- 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()

L.reverse() – reverse IN PLACE

setattr(**kwargs)

set (graphic) attributes to entity :param kwargs: dict of attributes copied to entity

sort(key=None, reverse=False) → None -- 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
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

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

save(filename, **kwargs)[source]

save graph in various formats