Coord

Main Classes

Most classes in this module are collections.namedtuple objects.

Class Description Attributes
Dim Linear dimension value units
Box A Box width depth
Pad Padding around a tree object prev next, parent child
Margin Padding around an object left right top bottom
Pt A point in Cartesian space x y

Reference

exception cpip.plot.Coord.ExceptionCoord

Exception class for representing Coordinates.

exception cpip.plot.Coord.ExceptionCoordUnitConvert

Exception raised when converting units.

cpip.plot.Coord.units()

Returns the unsorted list of acceptable units.

cpip.plot.Coord.convert(val, unitFrom, unitTo)

Convert a value from one set of units to another.

class cpip.plot.Coord.Dim

Represents a dimension as an engineering value i.e. a number and units.

scale(factor)

Returns a new Dim() scaled by a factor, units are unchanged.

convert(u)

Returns a new Dim() with units changed and value converted.

__add__(other)

Overload self+other, returned result has the sum of self and other. The units chosen are self’s unless self’s units are None in which case other’s units are used (if not None).

__sub__(other)

Overload self-other, returned result has the difference of self and other. The units chosen are self’s unless self’s units are None in which case other’s units are used (if not None).

__iadd__(other)

Addition in place, value of other is converted to my units and added.

__isub__(other)

Subtraction in place, value of other is subtracted.

__lt__(other)

Returns true if self value < other value after unit conversion.

__le__(other)

Returns true if self value <= other value after unit conversion.

__eq__(other)

Returns true if self value == other value after unit conversion.

__ne__(other)

Returns true if self value != other value after unit conversion.

__gt__(other)

Returns true if self value > other value after unit conversion.

__ge__(other)

Returns true if self value >= other value after unit conversion.

class cpip.plot.Coord.Pad

Padding around another object that forms the Bounding Box. All 4 attributes are Dim() objects

__str__()

Stringifying.

class cpip.plot.Coord.Pt

A point, an absolute x/y position on the plot area. Members are Coord.Dim().

__eq__(other)

Comparison.

__str__()

Stringifying.

convert(u)

Returns a new Pt() with units changed and value converted.

scale(factor)

Returns a new Pt() scaled by a factor, units are unchanged.

cpip.plot.Coord.baseUnitsDim(theLen)

Returns a Coord.Dim() of length and units BASE_UNITS.

cpip.plot.Coord.zeroBaseUnitsDim()

Returns a Coord.Dim() of zero length and units BASE_UNITS.

cpip.plot.Coord.zeroBaseUnitsBox()

Returns a Coord.Box() of zero dimensions and units BASE_UNITS.

cpip.plot.Coord.zeroBaseUnitsPad()

Returns a Coord.Pad() of zero dimensions and units BASE_UNITS.

cpip.plot.Coord.zeroBaseUnitsPt()

Returns a Coord.Dim() of zero length and units BASE_UNITS.

cpip.plot.Coord.newPt(theP, incX=None, incY=None)

Returns a new Pt object by incrementing existing point incX, incY that are both Dim() objects or None.

cpip.plot.Coord.convertPt(theP, theUnits)

Returns a new point with the dimensions of theP converted to theUnits.

Examples

Coord.Dim()

Creation, addition and subtraction:

d = Coord.Dim(1, 'in') + Coord.Dim(18, 'px')
# d is 1.25 inches
d = Coord.Dim(1, 'in') - Coord.Dim(18, 'px')
# d is 0.75 inches
d += Coord.Dim(25.4, 'mm')
# d is 1.75 inches

Scaling and unit conversion returns a new object:

a = Coord.Dim(12, 'px')
b = myObj.scale(6.0)
# b is 72 pixels
c = b.convert('in')
# 1 is 1 inch

Comparison:

assert(Coord.Dim(1, 'in') == Coord.Dim(72, 'px'))
assert(Coord.Dim(1, 'in') >= Coord.Dim(72, 'px'))
assert(Coord.Dim(1, 'in') <= Coord.Dim(72, 'px'))
assert(Coord.Dim(1, 'in') > Coord.Dim(71, 'px'))
assert(Coord.Dim(1, 'in') < Coord.Dim(73, 'px'))

Coord.Pt()

Creation:

p = Coord.Pt(
        Coord.Dim(12, 'px'),
        Coord.Dim(24, 'px'),
        )
print(p)
# Prints: 'Pt(x=Dim(12px), y=Dim(24px))'
p.x # Coord.Dim(12, 'px'))
p.y # Coord.Dim(24, 'px'))
# Scale up by 6 and convert units
pIn = p.scale(6).convert('in')
# pIn now 'Pt(x=Dim(1in), y=Dim(2in))'

Testing

The unit tests are in test/TestCoord.py.

Table Of Contents

Previous topic

cpip.plot

Next topic

PlotNode

This Page