differt2d.abc module

Abstract classes to be implemented by the user.

class Interactable[source]

Bases: ABC

Abstract class for any object that a ray path can interact with.

abstract static parameters_count()[source]

Returns how many parameters (s, t, …) are needed to define an interaction point on this object.

Typically, this equals to one for 2D surfaces.

Return type:

int

Returns:

The number of parameters.

Warning

This method is abstract and must be implemented by any of its subsclasses.

abstract parametric_to_cartesian(param_coords)[source]

Converts parametric coordinates to cartesian coordinates.

Parameters:

param_coords (Array, 'parameters_counts']) – Parametric coordinates.

Return type:

Array, '2']

Returns:

Cartesian coordinates.

Warning

This method is abstract and must be implemented by any of its subsclasses.

sample(key)[source]

Samples a random point on this object.

Parameters:

key (Union[Array, ''], Array, '2']]) – The random key to be used.

Return type:

Array, '2']

Returns:

The cartesian coordinates of the point.

Examples:

>>> from differt2d.geometry import Wall
>>> import jax
>>> import jax.numpy as jnp
>>> key = jax.random.PRNGKey(1234)
>>> wall = Wall(xys=jnp.array([[0.0, 0.0], [3.0, 4.0]]))
>>> wall.sample(key=key)  
Array([0.88359046, 1.1781206 ], dtype=float32)
abstract cartesian_to_parametric(carte_coords)[source]

Converts cartesian coordinates to parametric coordinates.

Parameters:

carte_coords (Array, '2']) – Cartesian coordinates.

Return type:

Array, 'parameters_counts']

Returns:

Parametric coordinates.

Warning

This method is abstract and must be implemented by any of its subsclasses.

abstract contains_parametric(param_coords, approx=None, **kwargs)[source]

Checks if the given coordinates are within the object.

Parameters:
  • param_coords (Array, 'parameters_counts']) – Parametric coordinates.

  • approx (Optional[bool], default: None) – Whether approximation is enabled or not.

  • kwargs (Any) – Keyword arguments passed to activation.

Return type:

Union[Array, '*batch'], Array, '*batch']]

Returns:

True if object contains these coordinates.

Warning

This method is abstract and must be implemented by any of its subsclasses.

abstract intersects_cartesian(ray, patch=0.0, approx=None, **kwargs)[source]

Ray intersection test on the current object.

Parameters:
  • ray (Array, '2 2']) – Ray coordinates.

  • patch (Union[Array, ''], float], default: 0.0) – The patch ratio, to virtually resize the object prior to intersection check. A patch value greater than 1 indicates that the object is enlarged, and a value between 0 and 1 indicates that the object is compressed. Patching the object size can be useful when combined with approx=True, because smoothing objects can virtually reduce this object’s size, so using a patch value greater than 1 can compensate this effect.

  • approx (Optional[bool], default: None) – Whether approximation is enabled or not.

  • kwargs (Any) – Keyword arguments passed to activation.

Return type:

Union[Array, '*batch'], Array, '*batch']]

Returns:

True if it intersects.

Warning

This method is abstract and must be implemented by any of its subsclasses.

abstract evaluate_cartesian(ray_path)[source]

Evaluates the given interaction triplet.

Evaluation is performed such that:

  • incident vector is defined as v_in = b - a;

  • bouncing vector is defined as v_out = c - b;

with a, b, c = ray_path and b lies on the current object.

A return value of 0 indicates that the interaction is successful.

The returned value cannot be negative.

Parameters:

ray_path (Array, '3 2']) – Ray path coordinates.

Return type:

Array, '']

Returns:

Interaction score.

Warning

This method is abstract and must be implemented by any of its subsclasses.

Loc

Literal type for all valid locations.

alias of Literal[‘N’, ‘E’, ‘S’, ‘W’, ‘C’, ‘NE’, ‘NW’, ‘SE’, ‘SW’]

class Object[source]

Bases: Plottable, Interactable

Abstract class for any object implementing both Plottable and Interactable.

This type is actually needed to please Python type checkers, since using typing.Union[Plottable, Interactable] is understood as implementing one of either classes, not both.

class Plottable[source]

Bases: ABC

Abstract class for any object that can be plotted using matplotlib.

abstract plot(ax, *args, **kwargs)[source]

Plot this object on the given axes and returns the results.

Parameters:
  • ax (Axes) – The axes to plot on.

  • args (Any) – Arguments passed to the plot function.

  • kwargs (Any) – Keyword arguments passed to the plot function.

Return type:

MutableSequence[Artist]

Returns:

The artist(s).

Warning

This method is abstract and must be implemented by any of its subsclasses.

abstract bounding_box()[source]

Returns the bounding box of this object.

This is: [[min_x, min_y], [max_x, max_y]].

Return type:

Array, '2 2']

Returns:

The min. and max. coordinates of this object.

Warning

This method is abstract and must be implemented by any of its subsclasses.

grid(m=50, n=None)[source]

Returns a (mesh) grid that overlays the current object.

Parameters:
  • m (int, default: 50) – The number of sample along x dimension.

  • n (Optional[int], default: None) – The number of sample along y dimension, defaults to m is left unspecified.

Return type:

tuple[Array, 'n_or_m {m}'], Array, 'n_or_m {m}']]

Returns:

A tuple of (X, Y) coordinates.

center()[source]

Returns the center coordinates of this object.

This is: [avg_x, avg_y].

Return type:

Array, '2']

Returns:

The average coordinates of this object.

get_location(location)[source]

Returns the relative location within this object’s extents.

‘N’, ‘E’, ‘S’, ‘W’, ‘C’ stand, respectively for North, East, South, West, and center. You can also combine two letters to define one of the four corners.

Parameters:

location (Literal['N', 'E', 'S', 'W', 'C', 'NE', 'NW', 'SE', 'SW']) – A literal referring to the location.

Return type:

Array, '2']

Returns:

The location coordinates within this object’s extents.