urclib.fuzzylogic.geomutils
Simple geometry functions and methods
Author: Patrick Wingo
Version: 0.1
- External Dependencies:
Module Contents
Classes
Straightforward 2D point class. |
|
Abstract Base Class that defines the interface for all segment objects. |
|
Straight forward implementation of a linear line segment. |
|
Line segment representation that is discontinuous with the rest of the curve. |
|
A segment defined as a bezier curve. |
Functions
|
Check that a value is between boundaries, allowing for a small amount of drift or error. |
Retrieve a list of mappings of segment types and their display labels. |
|
Report the list of classnames for segment types defined in this module. |
|
Report the list of display-ready segment names in this module. |
|
Retrieve the class name for a segment based on a display-ready dlg_label. |
|
Retrieve the display-ready dlg_label based on a segment class name. |
|
|
Convert Python container to Pt2D object. |
Attributes
- 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:
str: The name of the segment class.
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:
objectStraightforward 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.
- class urclib.fuzzylogic.geomutils.BaseSegment(pt1, pt2)
Bases:
abc.ABCAbstract Base Class that defines the interface for all segment objects.
- Parameters:
- Raises:
TypeError – If either pt1 or pt2 is not a 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:
BaseSegmentStraight forward implementation of a linear line segment.
- Parameters:
See also
BaseSegment for documentation on inherited properties, attributes, and methods.
- 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:
BaseSegmentLine 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:
See also
BaseSegment for documentation on inherited properties, attributes, and methods.
- 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:
BaseSegmentA segment defined as a bezier curve.
- Parameters:
- 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 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