Tools

class shapepy.tools.Is[source]

Bases: object

Contains functions to test the objects, telling if an object is a number, or it’s integer, etc

static bool(obj: Any) bool[source]

Tells if the object is a boolean

static callable(obj: Any) bool[source]

Tells if the object is callable

finite() bool

Check if a number is finite.

Parameters

numberReal

The number to check for being finite

Returns

bool

True if the number is finite, False otherwise

Examples

>>> Is.finite(float("inf"))
False
>>> Is.finite(0)
True
infinity() bool

Check if a number is negative or positive infinity.

Parameters

numberReal

The number to check for being infinity

Returns

bool

True if the number is infinity, False otherwise

Examples

>>> Is.infinity(-float("inf"))
True
>>> Is.infinity(float("inf"))
True
>>> Is.infinity(0)
False
instance(class_or_tuple, /)

Return whether an object is an instance of a class or of a subclass thereof.

A tuple, as in isinstance(x, (A, B, ...)), may be given as the target to check against. This is equivalent to isinstance(x, A) or isinstance(x, B) or ... etc.

integer() bool

Check if a number is integer.

Parameters

numberReal

The number to check for being an integer

Returns

bool

True if the number is integer, False otherwise

Examples

>>> Is.integer(1)
True
>>> Is.integer(1.2)
False
static iterable(obj: Any) bool[source]

Tells if the object is iterable

lazy() bool

Tells if the given subset is a Lazy evaluated instance

rational() bool

Check if a number is integer or rational.

Parameters

numberReal

The number to check for rationality

Returns

bool

True if the number is rational, False otherwise

Examples

>>> Is.rational(1)
True
>>> Is.rational(Fraction(1, 2))
True
>>> Is.rational(0.5)
real() bool

Check if a number is a real number.

Parameters

valueobject

The object to check for being a number

Returns

bool

True if the number is a number, False otherwise

Examples

>>> Is.real(float("inf"))
True
>>> Is.real(0)
True
>>> Is.real("asd")
False
class shapepy.tools.To[source]

Bases: object

Contains static methods to transform objects to some type numbers

angle() Angle

Converts an object to an Angle instance

  • If it’s already an angle, gives the same instance

  • If it’s a string, decides depending on the content:
    • “10deg” -> degrees(10)

    • “0.25tur” -> turns(0.25)

    • “2.1rad” -> radians(2.1)

  • If it’s any another type, converts to a number, and gives it in radians

Example

>>> angle("10deg")
>>> angle("0.25tur")
>>> angle("2.1rad")
>>> angle(1.25)
finite() Real

Converts the number to an finite number.

Parameters

numberAny

Number to be converted to an integer

Returns

Real

The converted number in integer

Raises

ValueError

If the number is not finite

Examples

>>> To.finite(-1)
-1
>>> To.finite(0)
0
>>> To.finite(1)
1
>>> To.finite(1.5)
1.5
class float(x=0, /)

Bases: object

Convert a string or number to a floating point number, if possible.

as_integer_ratio()

Return integer ratio.

Return a pair of integers, whose ratio is exactly equal to the original float and with a positive denominator.

Raise OverflowError on infinities and a ValueError on NaNs.

>>> (10.0).as_integer_ratio()
(10, 1)
>>> (0.0).as_integer_ratio()
(0, 1)
>>> (-.25).as_integer_ratio()
(-1, 4)
conjugate()

Return self, the complex conjugate of any float.

fromhex()

Create a floating-point number from a hexadecimal string.

>>> float.fromhex('0x1.ffffp10')
2047.984375
>>> float.fromhex('-0x1p-1074')
-5e-324
hex()

Return a hexadecimal representation of a floating-point number.

>>> (-0.1).hex()
'-0x1.999999999999ap-4'
>>> 3.14159.hex()
'0x1.921f9f01b866ep+1'
imag

the imaginary part of a complex number

is_integer()

Return True if the float is an integer.

real

the real part of a complex number

integer() Integral

Converts the number to an integer.

Parameters

numberReal

Number to be converted to an integer

Returns

int

The converted number in integer

Examples

>>> To.integer(-1)
-1
>>> To.integer(0)
0
>>> To.integer(1)
1
point() Point2D

Converts a point to a Point2D object

Parameters

pointPoint2D or tuple of two reals

The point to be converted

Returns

Point2D

The converted point

rational(denominator: Rational = 1) Rational

Divide two rational numbers and return the result as a fraction. If any input is not integer/rational, performs standard division.

Parameters

numeratorint or rational or float

The numerator number

denominatorint or rational or float

The divisor number

Returns

Rational

A instance if inputs are integers/rational

Raises

ZeroDivisionError

If denominator is zero

TypeError

If inputs are not numeric types

Notes

This function preserves exact rational representation when inputs are integers or rational numbers. For example:

Examples

>>> To.rational(1, 2)
Fraction(1, 2)
>>> To.rational(12, 9)
Fraction(4, 3)
>>> To.rational(22, 7)
Fraction(22, 7)
real() Real

Converts the number to a real number.

Parameters

numberAny

Number to be converted to a real number

Returns

Real

The converted real number

Examples

>>> To.real(-1)
-1
>>> To.real(0)
0
>>> To.real(1)
1
>>> To.real(1.5)
1.5
>>> To.real(float("inf"))
inf
>>> To.real("inf")
inf

Scalar

class shapepy.scalar.reals.Math[source]

Bases: object

Contains static methods for mathematical functions

NEGINF = -inf
POSINF = inf
static atan2(ycoord: Real, xcoord: Real) Real[source]

Compute the arc tangent of y/x choosing the quadrant correctly.

Parameters

ycoordReal

The y-coordinate of the point

xcoordReal

The x-coordinate of the point

Returns

float

Array of angles in radians in the range [-pi, pi)

Examples

>>> arctan2(1, 1)  # 45 degrees = π/4 radians
0.7853981633974483
>>> arctan2(-1, 1)  # -45 degrees = -π/4 radians
-0.7853981633974483
>>> arctan2(1, -1)  # 135 degrees = 3π/4 radians
2.3561944901923448
binom(k, /)

Number of ways to choose k items from n items without repetition and without order.

Evaluates to n! / (k! * (n - k)!) when k <= n and evaluates to zero when k > n.

Also called the binomial coefficient because it is equivalent to the coefficient of k-th term in polynomial expansion of the expression (1 + x)**n.

Raises TypeError if either of the arguments are not integers. Raises ValueError if either of the arguments are negative.

cosh()

Return the hyperbolic cosine of x.

static degrees(angle: Real) Real[source]

Convert an angle from radians to degrees.

This function performs the angular conversion using the mathematical relationship that pi radians equals 180 degrees. The conversion factor is calculated as 180/pi, ensuring precise transformation between the two angular measurement systems.

Parameters

angleReal

The angle in radians to convert

Returns

Real

The equivalent angle in degrees

Examples

>>> degrees(0)
0
>>> degrees(pi / 2)
90
>>> degrees(pi)
180

Notes

This function uses the math module’s degrees() function internally, which handles edge cases and provides optimal numerical precision for the conversion.

Raises:

TypeError: If the input is not a numeric type

factorial()

Find x!.

Raise a ValueError if x is negative or non-integral.

static fmod(numer: Real, denom: Real) Real[source]

Returns the floating-point remainder of division x1/x2.

Parameters

numerfloat

Dividend

denomfloat

Divisor

Returns

float

The remainder of x divided by y, with the same sign as x.

Examples

>>> fmod(5.0, 2.0)
1.0
>>> fmod(-5.0, 2.0)
-1.0
>>> fmod(5.0, -2.0)
1.0
static hypot(xcoord: Real, ycoord: Real) Real[source]

Calculate Euclidean distance from origin point (0,0).

Parameters

xcoordfloat

The x-coordinate of the point

ycoordfloat

The y-coordinate of the point

Returns

float

The Euclidean distance from the origin point (0,0)

Examples

>>> calculate_distance_from_origin(3, 4)
5.0
>>> calculate_distance_from_origin(0, 0)
0.0
radcos()

Return the cosine of x (measured in radians).

radsin()

Return the sine of x (measured in radians).

sinh()

Return the hyperbolic sine of x.

sqrt()

Return the square root of x.

tau: Real = 6.283185307179586
static turcos(angle: Real)[source]

Compute the cossinus of an angle in unitary form (turns).

This function is equivalent to math.cos(2*math.pi*angle)

Reference: * https://en.wikipedia.org/wiki/Turn_(angle)

Parameters

angleReal

Angle in turns measure

Returns

float

Cossinus of the unitary angle

Examples

>>> turcos(0)  # cossinus of 0 degrees
1
>>> turcos(0.25)  # cossinus of 90 degrees
0
>>> turcos(0.5)  # cossinus of 180 degrees
-1
>>> turcos(0.75)  # cossinus of 270 degrees
0
>>> turcos(1)  # cossinus of 360 degrees
1
static tursin(angle: Real)[source]

Compute the sine of an angle in unitary form (turns).

This function is equivalent to math.sin(2*math.pi*angle)

Reference: * https://en.wikipedia.org/wiki/Turn_(angle)

Parameters

angleReal

Angle in turns measure

Returns

float

Sine of the unitary angle

Examples

>>> tursin(0)  # sine of 0 degrees
0
>>> tursin(0.25)  # sine of 90 degrees
1
>>> tursin(0.5)  # sine of 180 degrees
0
>>> tursin(0.75)  # sine of 270 degrees
-1
>>> tursin(1)  # sine of 360 degrees
0

class shapepy.scalar.angle.Angle(direction: int, part: Real)[source]

Bases: object

Class that stores an angle.

Handles the operations such as __add__, __sub__, etc

cos() Real[source]

Computes the cossinus value for the angle

Return

Real

The cossinus result of the angle

Example

>>> degrees(0).cos()
1
>>> degrees(45).cos()
0.7071067811865476
>>> degrees(90).cos()
0
property degrees: Real

Gives the angle measure in degrees

Example

>>> degrees(0).degrees
0
>>> degrees(45).degrees
45
>>> degrees(90).degrees
90
>>> degrees(180).degrees
180
>>> degrees(270).degrees
270
>>> degrees(360).degrees
0
property direction: int

Gives the nearest axis to the angle

Example

>>> degrees(0).direction  # +x axis
0
>>> degrees(30).direction  # +x axis
0
>>> degrees(60).direction  # +y axis
1
>>> degrees(90).direction  # +y axis
1
>>> degrees(120).direction  # +y axis
1
>>> degrees(180).direction  # -x axis
2
>>> degrees(270).direction  # -y axis
3
property part: int

Gives the distance between the angle and the nearest axis

Example

>>> degrees(0).part
0
>>> degrees(30).part
0.08333333333333333
>>> degrees(45).part
0.125
>>> degrees(60)
-0.08333333333333333
>>> degrees(90).part
0
>>> degrees(120).part
0.08333333333333333
property radians: Real

Gives the angle measure in radians

Example

>>> degrees(0).radians
0
>>> degrees(45).radians
0.7853981633974483
>>> degrees(90).radians
1.5707963267948966
>>> degrees(180).radians
3.141592653589793
>>> degrees(270).radians
4.71238898038469
>>> degrees(360).radians
0
sin() Real[source]

Computes the sinus value for the angle

Return

Real

The sinus result of the angle

Example

>>> degrees(0).sin()
0
>>> degrees(45).sin()
0.7071067811865476
>>> degrees(90).sin()
1
property turns: Real

Gives the angle measure in turns

Example

>>> degrees(0).turns
0
>>> degrees(45).turns
0.125
>>> degrees(90).turns
0.25
>>> degrees(180).turns
0.5
>>> degrees(270).turns
0.75
>>> degrees(360).turns
0



class shapepy.scalar.nodes_sample.NodeSampleFactory[source]

Functions to get node samples

static chebyshev(npts: int) Tuple[Real][source]

Gives a set of numbers in interval (0, 1)

Example

>>> custom_open_formula(1)
(0.5, )
>>> custom_open_formula(2)
(0.14645, 0.85355)
>>> custom_open_formula(3)
(0.06699, 0.5, 0.93301)
>>> custom_open_formula(4)
(0.03806, 0.30866, 0.69134, 0.96194)
>>> custom_open_formula(4)
(0.02447, 0.20611, 0.5, 0.79389, 0.97553)
static closed_linspace(npts: int) Tuple[Rational, ...][source]

Gives a set of numbers in interval [0, 1]

Example

>>> closed_linspace(2)
(0, 1)
>>> closed_linspace(3)
(0, 0.5, 1)
>>> closed_linspace(4)
(0, 0.33, 0.66, 1)
>>> closed_linspace(5)
(0, 0.25, 0.5, 0.75, 1)
static closed_newton_cotes(npts: int) Tuple[Real][source]

Gives a set of numbers in interval [0, 1]

Example

>>> closed_newton_cotes(2)
(0, 1)
>>> closed_newton_cotes(3)
(0, 1/2, 1)
>>> closed_newton_cotes(4)
(0, 1/3, 2/3, 1)
>>> closed_newton_cotes(5)
(0, 1/4, 2/4, 3/4, 1)
static custom_open_formula(npts: int) Tuple[Real][source]

Gives a set of numbers in interval (0, 1)

Example

>>> custom_open_formula(1)
(1/2, )
>>> custom_open_formula(2)
(1/4, 3/4)
>>> custom_open_formula(3)
(1/6, 3/6, 5/6)
>>> custom_open_formula(4)
(1/8, 3/8, 5/8, 7/8)
static open_newton_cotes(npts: int) Tuple[Real][source]

Gives a set of numbers in interval (0, 1)

Example

>>> open_newton_cotes(1)
(1/2, )
>>> open_newton_cotes(2)
(1/3, 2/3)
>>> open_newton_cotes(3)
(1/4, 2/4, 3/4)
>>> open_newton_cotes(4)
(1/5, 2/5, 3/5, 4/5)

class shapepy.scalar.quadrature.DirectIntegrator(nodes: Iterable[Real], weights: Iterable[Real])[source]

Defines an integrator, to integrate a scalar function in a given interval

integrate(function: Callable[[Real], Real], interval: Tuple[Real, Real]) Real[source]

Computes the integral of func in [a, b]

property nodes: Tuple[Real, ...]

Get the nodes used by the integrator

property weights: Tuple[Real, ...]

Get the weights used by the integrator


class shapepy.scalar.quadrature.IntegratorFactory[source]

Defines methods that creates Direct Integrators

static clenshaw_curtis(npts: int, convert: type = <function to_finite>) DirectIntegrator[source]

Gives a set of numbers in interval (0, 1)

Example

>>> clenshaw_curtis(1)
{"nodes": (0.5, ),
 "weights": (1.0, )}
>>> clenshaw_curtis(2)
{"nodes": (0.14645, 0.85355),
 "weights": (0.5, 0.5)}
>>> clenshaw_curtis(3)
{"nodes": (0.06699, 0.5, 0.93301),
 "weights": (0.22222, 0.55556, 0.22222)}
>>> clenshaw_curtis(4)
{"nodes": (0.03806, 0.30866, 0.69134, 0.96194),
 "weights": (0.13215, 0.36785, 0.36785, 0.13215)}
>>> clenshaw_curtis(5)
{"nodes": (0.02447, 0.20611, 0.5, 0.79389, 0.97553),
 "weights": (0.08389, 0.26278, 0.30667, 0.26278, 0.08389)}
static closed_newton_cotes(npts: int, convert: type = <function to_rational>) DirectIntegrator[source]

Gives a set of numbers in interval (0, 1)

Example

>>> closed_newton_cotes(2)
{"nodes": (0, 1),
 "weights": (1/2, 1/2)}
>>> closed_newton_cotes(3)
{"nodes": (0, 1/2, 1),
 "weights": (1/2, 1/2)}
>>> closed_newton_cotes(4)
{"nodes": (0, 1/3, 2/3, 1),
 "weights": (2/3, -1/3, 2/3)}
>>> closed_newton_cotes(5)
{"nodes": (0, 1/4, 2/4, 3/4, 1),
 "weights": (11/24, 1/24, 1/24, 11/24)}
static custom_open_formula(npts: int, convert: type = <function to_rational>) DirectIntegrator[source]

Gives a set of numbers in interval (0, 1)

Example

>>> custom_open_formula(1)
{"nodes": (1/2, ),
 "weights": (1, )}
>>> custom_open_formula(2)
{"nodes": (1/4, 3/4),
 "weights": (1/2, 1/2)}
>>> custom_open_formula(3)
{"nodes": (1/6, 3/6, 5/6),
 "weights": (3/8, 1/4, 3/8)}
>>> custom_open_formula(4)
{"nodes": (1/8, 3/8, 5/8, 7/8),
 "weights": (13/48, 11/48, 11/48, 13/48)}
>>> custom_open_formula(5)
{"nodes": (1/10, 3/10, 5/10, 7/10, 9/10),
 "weights": (275/1152, 25/288, 67/192, 25/288, 275/1152)}
static open_newton_cotes(npts: int, convert: type = <function to_rational>) DirectIntegrator[source]

Gives a set of numbers in interval (0, 1)

Example

>>> open_newton_cotes(1)
{"nodes": (1/2, ),
 "weights": (1, )}
>>> open_newton_cotes(2)
{"nodes": (1/3, 2/3),
 "weights": (1/2, 1/2)}
>>> open_newton_cotes(3)
{"nodes": (1/4, 2/4, 3/4),
 "weights": (2/3, -1/3, 2/3)}
>>> open_newton_cotes(4)
{"nodes": (1/5, 2/5, 3/5, 4/5),
 "weights": (11/24, 1/24, 1/24, 11/24)}
>>> open_newton_cotes(5)
{"nodes": (1/6, 2/6, 3/6, 4/6, 5/6),
 "weights": (11/20, -14/20, 26/20, -14/20, 11/20)}

class shapepy.scalar.quadrature.AdaptativeIntegrator(integrator: DirectIntegrator, tolerance: Real = 1e-09, maxdepth: int = 12)[source]

Bases: object

Defines an adaptative integrator that uses the open newton-cotes formula to compute the integral of a function.

integrate(function: Callable[[Real], Real], interval: Tuple[Real, Real]) Real[source]

Computes the integral of func in [a, b]

property integrator: DirectIntegrator

The direct integrator used to calculate the integral

property maxdepth: Real

The maximal depth to stop the quadrature when it does not converge

property tolerance: Real

The tolerance to know when to stop the adaptative quadrature


Geometry

class shapepy.geometry.point.Point2D(xcoord: Real | None = None, ycoord: Real | None = None, radius: Real | None = None, angle: Angle | None = None)[source]

Defines a Point in the plane,

It can be described in cartesian way: (x, y) Or also in a polar way: (radius:angle)

property angle: Angle

The angle the point (x, y) forms with respect to the horizontal

property radius: Real

The norm L2 of the point: sqrt(x*x + y*y)

property xcoord: Real

The horizontal coordinate of the point

property ycoord: Real

The vertical coordinate of the point


class shapepy.geometry.box.Box(lowpt: Point2D, toppt: Point2D)[source]

Box class, which speeds up the evaluation of __contains__ in classes like Segment, JordanCurve and SimpleShape.

Since it’s faster to evaluate if a point is in a rectangle (this box), we avoid some computations like projecting the point on a curve and verifying if the distance is big enough to consider whether the point is the object


class shapepy.geometry.segment.Segment(xfunc: IAnalytic, yfunc: IAnalytic, *, domain: IntervalR1 | WholeR1)[source]

Bases: IParametrizedCurve

Defines a planar curve in the plane, that contains a bezier curve inside it

box() Box[source]

Returns two points which defines the minimal exterior rectangle

Returns the pair (A, B) with A[0] <= B[0] and A[1] <= B[1]

derivate(times: int | None = 1) Segment[source]

Gives the first derivative of the curve

property domain: IntervalR1 | WholeR1

The domain where the curve is defined.

eval(node: Real, derivate: int = 0) Point2D[source]

Evaluates the curve at given node

property knots: Tuple[Real, Real]

The subdivisions on the domain

property length: Real

The length of the curve If the curve is not bounded, returns infinity

parametrize() IParametrizedCurve

Gives a parametrized curve

section(domain: IntervalR1 | WholeR1) Segment[source]

Extracts a subsegment from the given segment

property xfunc: IAnalytic

Gives the analytic function x(t) from p(t) = (x(t), y(t))

property yfunc: IAnalytic

Gives the analytic function y(t) from p(t) = (x(t), y(t))


class shapepy.geometry.jordancurve.JordanCurve(usegments: Iterable[Segment | USegment])[source]

Jordan Curve is an arbitrary closed curve which doesn’t intersect itself. It stores a list of ‘segments’, each segment is a bezier curve

property area: Real

The internal area

box() Box

The box which encloses the jordan curve

Returns:

The box which encloses the jordan curve

Return type:

Box

Example use

>>> from shapepy import JordanCurve
>>> vertices = [(0, 0), (4, 0), (0, 3)]
>>> jordan = FactoryJordan.polygon(vertices)
>>> jordan.box()
Box with vertices (0, 0) and (4, 3)
property length: Real

The length of the curve

parametrize() PiecewiseCurve

Gives a parametrized curve

vertices() Iterator[Point2D][source]

Vertices

Returns in order, all the non-repeted control points from jordan curve’s segments

Getter:

Returns a tuple of

Type:

Tuple[Point2D]

Example use

>>> from shapepy import JordanCurve
>>> vertices = [(0, 0), (4, 0), (0, 3)]
>>> jordan = FactoryJordan.polygon(vertices)
>>> print(jordan.vertices)
((0, 0), (4, 0), (0, 3))

Boolean 2D

class shapepy.bool2d.primitive.Primitive[source]

Primitive class with functions to create classical shapes such as circle, triangle, square, regular_polygon and a generic polygon

Note

This class also contains empty and whole instances to easy access

static circle(radius: float = 1, center: Point2D = (0, 0), ndivangle: int = 16) SimpleShape[source]

Creates a circle

Parameters

radiusfloat, default: 1

Radius of the circle

centerPoint2D, default: (0, 0)

Center of the circle

ndivangleint, 16

Number of divisions of the circle, minimum 4


returnSimpleShape

The simple shape that represents the circle

Example use

>>> from shapepy import Primitive
>>> circle = Primitive.circle()
../_images/positive_circle.svg

Note

We represent the circle by many quadratic segments. NURBS are not implemented in this code to represent exactly circles. You can choose the number of quadratic terms by changing ndivangle.

empty = EmptyShape
static polygon(vertices: Tuple[Point2D]) SimpleShape[source]

Creates a generic polygon

vertices: tuple[Point2D]

Vertices of the polygon


returnSimpleShape

The simple shape that represents the polygon

Example use

>>> from shapepy import Primitive
>>> vertices = [(1, 0), (0, 1), (-1, 1), (0, -1)]
>>> shape = Primitive.polygon(vertices)
../_images/diamond.svg
static regular_polygon(nsides: int, radius: float = 1, center: Point2D = (0, 0)) SimpleShape[source]

Creates a regular polygon

Parameters

nsidesint

Number of sides of regular polygon, >= 3

radiusfloat, default: 1

Radius of the external circle that contains the polygon.

centerPoint2D, default: (0, 0)

The geometric center of the regular polygon


returnSimpleShape

The simple shape that represents the regular polygon

Example use

>>> from shapepy import Primitive
>>> triangle = Primitive.regular_polygon(nsides = 3)
../_images/regular3.svg ../_images/regular4.svg ../_images/regular5.svg
static square(side: float = 1, center: Point2D = (0, 0)) SimpleShape[source]

Creates a square with sides aligned with axis

Parameters

sidefloat, default: 1

Side of the square.

centerPoint2D, default: (0, 0)

The geometric center of the square


returnSimpleShape

The simple shape that represents the square

Example use

>>> from shapepy import Primitive
>>> square = Primitive.square()
../_images/square.svg
static triangle(side: float = 1, center: Point2D = (0, 0)) SimpleShape[source]

Create a right triangle

Parameters

sidefloat, default: 1

Width and height of the triangle

centerPoint2D, default: (0, 0)

Position of the vertex of right angle


returnSimpleShape

The simple shape that represents the triangle

Example use

>>> from shapepy import Primitive
>>> triangle = Primitive.triangle()
../_images/triangle.svg
whole = WholeShape



class shapepy.bool2d.shape.SimpleShape(jordancurve: JordanCurve, boundary: bool = True)[source]

Bases: SubSetR2

SimpleShape class

Is a shape which is defined by only one jordan curve. It represents the interior/exterior region of the jordan curve if the jordan curve is counter-clockwise/clockwise

property area: Real

The internal area that is enclosed by the shape

property boundary: bool

The flag that informs if the boundary is inside the Shape

box() Box[source]

Box that encloses all jordan curves

Parameters

return:

The box that encloses all

rtype:

Box

Example use

>>> from shapepy import Primitive, IntegrateShape
>>> circle = Primitive.circle(radius = 1)
>>> circle.box()
Box with vertices (-1.0, -1.0) and (1., 1.0)
clean() SubSetR2

Cleans the subset, changing its representation into a simpler form

Parameters

return:

The same instance

rtype:

SubSetR2

Example use

>>> from shapepy import Primitive
>>> circle = Primitive.circle()
>>> circle.clean()
density(center: Point2D) Density[source]

Computes the density of the subset around given point

Parameters

centerPoint2D

The position to measure the density

return:

The density in the interval [0, 1]

rtype:

Real

Example use

>>> from shapepy import Primitive
>>> circle = Primitive.circle(radius=1)
>>> circle.density((0, 0))
1
>>> circle.density((5, 0))
0
>>> circle.density((1, 0))
0.5
property jordan: JordanCurve

Gives the jordan curve that defines the boundary

property jordans: Tuple[JordanCurve]

Gives the jordan curve that defines the boundary

move(vector: Point2D) SimpleShape[source]

Moves/translate entire shape by an amount

Parameters

pointPoint2D

The amount to move

return:

The same instance

rtype:

SubSetR2

Example use

>>> from shapepy import Primitive
>>> circle = Primitive.circle()
>>> circle.move(1, 2)
rotate(angle: Angle) SimpleShape[source]

Rotates entire shape around the origin by an amount

Parameters

angleAngle

The amount to rotate around origin

return:

The same instance

rtype:

SubSetR2

Example use

>>> from shapepy import Primitive
>>> circle = Primitive.circle()
>>> circle.rotate(degrees(90))
scale(amount: Real | Tuple[Real, Real]) SimpleShape[source]

Scales entire subset by an amount

Parameters

amountReal | Tuple[Real, Real]

The amount to scale in horizontal and vertical direction

return:

The same instance

rtype:

SubSetR2

Example use

>>> from shapepy import Primitive
>>> circle = Primitive.circle()
>>> circle.scale((2, 3))

class shapepy.bool2d.shape.ConnectedShape(subshapes: Iterable[SimpleShape])[source]

Bases: SubSetR2

ConnectedShape Class

A shape defined by intersection of two or more SimpleShapes

property area: Real

The internal area that is enclosed by the shape

box() Box[source]

Box that encloses all jordan curves

Parameters

return:

The box that encloses all

rtype:

Box

Example use

>>> from shapepy import Primitive, IntegrateShape
>>> circle = Primitive.circle(radius = 1)
>>> circle.box()
Box with vertices (-1.0, -1.0) and (1., 1.0)
clean() SubSetR2

Cleans the subset, changing its representation into a simpler form

Parameters

return:

The same instance

rtype:

SubSetR2

Example use

>>> from shapepy import Primitive
>>> circle = Primitive.circle()
>>> circle.clean()
density(center: Point2D) Density[source]

Computes the density of the subset around given point

Parameters

centerPoint2D

The position to measure the density

return:

The density in the interval [0, 1]

rtype:

Real

Example use

>>> from shapepy import Primitive
>>> circle = Primitive.circle(radius=1)
>>> circle.density((0, 0))
1
>>> circle.density((5, 0))
0
>>> circle.density((1, 0))
0.5
property jordans: Tuple[JordanCurve, ...]

Jordan curves that defines the shape

Getter:

Returns a set of jordan curves

Type:

tuple[JordanCurve]

move(vector: Point2D) ConnectedShape[source]

Moves/translate entire shape by an amount

Parameters

pointPoint2D

The amount to move

return:

The same instance

rtype:

SubSetR2

Example use

>>> from shapepy import Primitive
>>> circle = Primitive.circle()
>>> circle.move(1, 2)
rotate(angle: Angle) ConnectedShape[source]

Rotates entire shape around the origin by an amount

Parameters

angleAngle

The amount to rotate around origin

return:

The same instance

rtype:

SubSetR2

Example use

>>> from shapepy import Primitive
>>> circle = Primitive.circle()
>>> circle.rotate(degrees(90))
scale(amount: Real | Tuple[Real, Real]) ConnectedShape[source]

Scales entire subset by an amount

Parameters

amountReal | Tuple[Real, Real]

The amount to scale in horizontal and vertical direction

return:

The same instance

rtype:

SubSetR2

Example use

>>> from shapepy import Primitive
>>> circle = Primitive.circle()
>>> circle.scale((2, 3))

class shapepy.bool2d.shape.DisjointShape(subshapes: Iterable[SimpleShape | ConnectedShape])[source]

Bases: SubSetR2

DisjointShape Class

A shape defined by the union of some SimpleShape instances and ConnectedShape instances

property area: Real

The internal area that is enclosed by the shape

box() Box[source]

Box that encloses all jordan curves

Parameters

return:

The box that encloses all

rtype:

Box

Example use

>>> from shapepy import Primitive, IntegrateShape
>>> circle = Primitive.circle(radius = 1)
>>> circle.box()
Box with vertices (-1.0, -1.0) and (1., 1.0)
clean() SubSetR2

Cleans the subset, changing its representation into a simpler form

Parameters

return:

The same instance

rtype:

SubSetR2

Example use

>>> from shapepy import Primitive
>>> circle = Primitive.circle()
>>> circle.clean()
density(center: Point2D) Real[source]

Computes the density of the subset around given point

Parameters

centerPoint2D

The position to measure the density

return:

The density in the interval [0, 1]

rtype:

Real

Example use

>>> from shapepy import Primitive
>>> circle = Primitive.circle(radius=1)
>>> circle.density((0, 0))
1
>>> circle.density((5, 0))
0
>>> circle.density((1, 0))
0.5
property jordans: Tuple[JordanCurve, ...]

Jordan curves that defines the shape

Getter:

Returns a set of jordan curves

Type:

tuple[JordanCurve]

move(vector: Point2D) DisjointShape[source]

Moves/translate entire shape by an amount

Parameters

pointPoint2D

The amount to move

return:

The same instance

rtype:

SubSetR2

Example use

>>> from shapepy import Primitive
>>> circle = Primitive.circle()
>>> circle.move(1, 2)
rotate(angle: Angle) DisjointShape[source]

Rotates entire shape around the origin by an amount

Parameters

angleAngle

The amount to rotate around origin

return:

The same instance

rtype:

SubSetR2

Example use

>>> from shapepy import Primitive
>>> circle = Primitive.circle()
>>> circle.rotate(degrees(90))
scale(amount: Real | Tuple[Real, Real]) DisjointShape[source]

Scales entire subset by an amount

Parameters

amountReal | Tuple[Real, Real]

The amount to scale in horizontal and vertical direction

return:

The same instance

rtype:

SubSetR2

Example use

>>> from shapepy import Primitive
>>> circle = Primitive.circle()
>>> circle.scale((2, 3))