differt2d.abc module¶
Abstract classes to be implemented by the user.
- class Interactable[source]¶
Bases:
ABCAbstract 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:
- 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 toactivation.
- 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. Apatchvalue greater than1indicates that the object is enlarged, and a value between0and1indicates that the object is compressed. Patching the object size can be useful when combined withapprox=True, because smoothing objects can virtually reduce this object’s size, so using apatchvalue greater than1can compensate this effect.approx (
Optional[bool], default:None) – Whether approximation is enabled or not.kwargs (
Any) – Keyword arguments passed toactivation.
- 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_pathandblies 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,InteractableAbstract class for any object implementing both
PlottableandInteractable.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:
ABCAbstract 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:
- Return type:
- 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.
- 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.