urclib.fuzzylogic.geomutils

Simple geometry functions and methods

Author: Patrick Wingo

Version: 0.1

External Dependencies:

Module Contents

Classes

Pt2D

Straightforward 2D point class.

BaseSegment

Abstract Base Class that defines the interface for all segment objects.

LinearSegment

Straight forward implementation of a linear line segment.

StepwiseSegment

Line segment representation that is discontinuous with the rest of the curve.

BezierSegment

A segment defined as a bezier curve.

Functions

bounds_check(inval[, lo, hi, eps])

Check that a value is between boundaries, allowing for a small amount of drift or error.

get_segmentlabelmappings()

Retrieve a list of mappings of segment types and their display labels.

segment_types()

Report the list of classnames for segment types defined in this module.

pretty_segment_names()

Report the list of display-ready segment names in this module.

pretty_segment_to_type(lbl)

Retrieve the class name for a segment based on a display-ready dlg_label.

type_segment_to_pretty(lbl)

Retrieve the display-ready dlg_label based on a segment class name.

to_pt2d(invals)

Convert Python container to Pt2D object.

Attributes

ABC

urclib.fuzzylogic.geomutils.ABC
urclib.fuzzylogic.geomutils.bounds_check(inval, lo=0.0, hi=1.0, eps=1e-06)

Check that a value is between boundaries, allowing for a small amount of drift or error.

Parameters:
  • inval (float) – The value to test.

  • lo (float, optional) – The lower boundary; defaults to 0.0.

  • hi (float, optional) – The upper boundary; defaults to 1.0.

  • eps (float,optional) – The epsilon value, which determines how much drift is tolerated; defaults to 1e-6.

Returns:

float or None

  • float: The value of inval if it falls between lo and hi, or the nearest boundary value if inval is within the tolerance value eps.

  • None: If inval is out of bounds.

Raises:

ValueError – If inval out of bounds and outside the tolerance range.

urclib.fuzzylogic.geomutils.get_segmentlabelmappings()

Retrieve a list of mappings of segment types and their display labels.

Returns:

tuples with the following values:
  1. str: The name of the segment class.

  2. str: The display name of the segment type.

Return type:

list

urclib.fuzzylogic.geomutils.segment_types()

Report the list of classnames for segment types defined in this module.

Returns:

Names of BaseSegment-subclasses ready to be used.

Return type:

list

urclib.fuzzylogic.geomutils.pretty_segment_names()

Report the list of display-ready segment names in this module.

Returns:

Display Names of segment types defined in this module.

Return type:

list

urclib.fuzzylogic.geomutils.pretty_segment_to_type(lbl)

Retrieve the class name for a segment based on a display-ready dlg_label.

Parameters:

lbl (str) – The dlg_label to query.

Returns:

The class name that is mapped to the value in lbl. * None: If lbl does not match any class names.

Return type:

  • str

urclib.fuzzylogic.geomutils.type_segment_to_pretty(lbl)

Retrieve the display-ready dlg_label based on a segment class name.

Parameters:

lbl (str) – The class name to query.

Returns:

The pretty dlg_label that is mapped to the value in lbl. * None: If lbl does not match any pretty labels.

Return type:

  • str

class urclib.fuzzylogic.geomutils.Pt2D(x=0, y=0)

Bases: object

Straightforward 2D point class.

Parameters:
  • x (float, optional) – The initial x-coordinate. Defaults to 0.

  • y (float, optional) – The initial y-coordinate. Defaults to 0.

property x

The x-coordinate of the point.

Type:

float

property y

The y-coordinate of the point.

Type:

float

__eq__(rhs)

Return self==value.

__ne__(rhs)

Return self!=value.

__getitem__(ind)

Index operator overload.

Parameters:

ind (int or str) – Reference to the coordinate to retrieve.

Returns:

The value of the request coordinate.

Return type:

float

Raises:

IndexError – If ind is not a coordinate name or a valid index.

__setitem__(ind, val)

Index operator overload.

Parameters:
  • ind (int or str) – The reference to the coordinate to assign.

  • val (float) – The value to assign.

Raises:

IndexError – If ind is not a coordinate name or a valid index.

__repr__()

Return repr(self).

__str__()

Return str(self).

__add__(p2)
__sub__(p2)
__truediv__(p2)
__mul__(p2)
static copy(pt)

Create a copy of a Pt2D object.

Parameters:

pt (Pt2D) – Point to copy.

Returns:

A copy of pt.

Return type:

Pt2D

clone()

Create a duplicate of this point.

Returns:

A copy of this point.

Return type:

Pt2D

class urclib.fuzzylogic.geomutils.BaseSegment(pt1, pt2)

Bases: abc.ABC

Abstract Base Class that defines the interface for all segment objects.

Parameters:
  • pt1 (Pt2D) – The first endpoint of the segment.

  • pt2 (Pt2D) – The second endpoint of the segment.

Raises:

TypeError – If either pt1 or pt2 is not a Pt2D.

property leftpoint

The leftmost point of the segment.

Type:

Pt2D

property rightpoint

The rightmost point of the segment.

Type:

Pt2D

abstract property maxpoint

point with the largest y value.

Type:

Pt2D

abstract property minpoint

Point with the smallest y value.

Type:

Pt2D

abstract property equation_args

Key-value pairs representing additional equation arguments.

Type:

dict

property drawpoints

Enough points to draw the segment.

Type:

list

property ctrlpoints

Points that aren’t part of the line, but influence the shape.

Type:

list

__getitem__(ind)
__len__()
__eq__(rhs)

Return self==value.

x_inrange(xval)

Test to see if x-value is between x-values of line segment.

Parameters:

xval (float) – The x-value to test.

Returns:

True if xVal falls within range of the segment; False otherwise.

Return type:

bool

abstract y_for_x(x)
Retrieve the y value for a provide x value; basically calling

f(x) for the segment.

Parameters:

x (float) – The value to query with.

Returns:

The value for processing x.

Return type:

float

__call__(x)
abstract split(ratio=0.5)

split a segment into two sub-segments.

Parameters:

ratio (float) – The relative position of the point of the split, within range [0,1].

Reurns:

tuple: Two segments that represent the split segment.

abstract subsegment(x1, x2)

Derive a subsegment from this segment.

Parameters:
  • x1 (float) – The leftmost x-location of the subsegment.

  • x2 (float) – The rightmost x-location of the subsegment.

Returns:

A subsegment defined by the provided x-boundaries.

Return type:

float

class urclib.fuzzylogic.geomutils.LinearSegment(pt1, pt2)

Bases: BaseSegment

Straight forward implementation of a linear line segment.

Parameters:
  • pt1 (Pt2D) – The first endpoint of the segment.

  • pt2 (Pt2D) – The second endpoint of the segment.

See also

BaseSegment for documentation on inherited properties, attributes, and methods.

property maxpoint

point with the largest y value.

Type:

Pt2D

property minpoint

Point with the smallest y value.

Type:

Pt2D

property equation_args

Key-value pairs representing additional equation arguments.

Type:

dict

property drawpoints

Enough points to draw the segment.

Type:

list

property lowpoint

y value for lowest x-ordinate

Type:

float

property highpoint

y value for highest x-ordinate

Type:

float

refresh_coefficients()

refresh the reference coefficients to match the points provided.

__repr__()

Return repr(self).

__eq__(rhs)

Return self==value.

y_for_x(x)
Retrieve the y value for a provide x value; basically calling

f(x) for the segment.

Parameters:

x (float) – The value to query with.

Returns:

The value for processing x.

Return type:

float

split(ratio=0.5)

split a segment into two sub-segments.

Parameters:

ratio (float) – The relative position of the point of the split, within range [0,1].

Returns:

Two segments that represent the split segment.

Return type:

tuple

subsegment(x1, x2)

Derive a subsegment from this segment.

Parameters:
  • x1 (float) – The leftmost x-location of the subsegment.

  • x2 (float) – The rightmost x-location of the subsegment.

Returns:

A subsegment defined by the provided x-boundaries.

Return type:

float

class urclib.fuzzylogic.geomutils.StepwiseSegment(pt1, pt2, height=None)

Bases: BaseSegment

Line segment representation that is discontinuous with the rest of the curve.

Control Points are where adjacent points are picked up; actual shelf is determined by height value.

height

The height of the horizontal line.

Type:

float

Parameters:
  • pt1 (Pt2D) – The first endpoint of the segment.

  • pt2 (Pt2D) – The second endpoint of the segment.

  • height (float, optional) – The height of the step. If None, defaults to mid-height between pt1 and pt2.

See also

BaseSegment for documentation on inherited properties, attributes, and methods.

property maxpoint

point with the largest y value.

Type:

Pt2D

property minpoint

Point with the smallest y value.

Type:

Pt2D

property equation_args

Key-value pairs representing additional equation arguments.

Type:

dict

property drawpoints

return enough points to draw accurately.

__repr__()

Return repr(self).

__eq__(rhs)

Return self==value.

y_for_x(x)
Retrieve the y value for a provide x value; basically calling

f(x) for the segment.

Parameters:

x (float) – The value to query with.

Returns:

The value for processing x.

Return type:

float

subsegment(x1, x2)

Derive a subsegment from this segment.

Parameters:
  • x1 (float) – The leftmost x-location of the subsegment.

  • x2 (float) – The rightmost x-location of the subsegment.

Returns:

A subsegment defined by the provided x-boundaries.

Return type:

float

split(ratio=0.5)

split a segment into two sub-segments.

Parameters:

ratio (float) – The relative position of the point of the split, within range [0,1].

Reurns:

tuple: Two segments that represent the split segment.

class urclib.fuzzylogic.geomutils.BezierSegment(pt1, pt2, ctrl1=None)

Bases: BaseSegment

A segment defined as a bezier curve.

Parameters:
  • pt1 (Pt2D) – The first endpoint of the segment.

  • pt2 (Pt2D) – The second endpoint of the segment.

  • ctrl1 (Pt2D, optional) – The point controlling the shape of the curve. If None, defaults to midpoint along linear segment between pt1 and pt2.

Raises:

ValueError – If pt1 and pt2 are equal.

See also

BaseSegment for documentation on inherited properties, attributes, and methods.

property equation_args

Key-value pairs representing additional equation arguments.

Type:

dict

property maxpoint

point with the largest y value.

Type:

Pt2D

property minpoint

Point with the smallest y value.

Type:

Pt2D

property xadjust

The x-value of the control point.

Type:

float

property yadjust

The y-value of the control point.

Type:

float

property ctrlpoints

Points that aren’t part of the line, but influence the shape.

Type:

list

__repr__()

Return repr(self).

__eq__(rhs)

Return self==value.

y_for_x(x)
Retrieve the y value for a provide x value; basically calling

f(x) for the segment.

Parameters:

x (float) – The value to query with.

Returns:

The value for processing x.

Return type:

float

split(ratio=0.5)

split a segment into two sub-segments.

Parameters:

ratio (float) – The relative position of the point of the split, within range [0,1].

Reurns:

tuple: Two segments that represent the split segment.

subsegment(x1, x2)

Derive a subsegment from this segment.

Parameters:
  • x1 (float) – The leftmost x-location of the subsegment.

  • x2 (float) – The rightmost x-location of the subsegment.

Returns:

A subsegment defined by the provided x-boundaries.

Return type:

float

urclib.fuzzylogic.geomutils.to_pt2d(invals)

Convert Python container to Pt2D object.

Parameters:

invals (object) – The python container with the x,y values in the first two indices.

Returns:

Point with values of invals[0:1].

Return type:

Pt2D