Global

Members

(constant) DATA_VERSION :number

The version of the JSON data format of the scene, which matches the major version number of the app starting from version 5.0.

Type:
  • number
Source:

(constant) usePreferencesStore

Create a Vue store for application preferences that persist to localStorage

Source:

(constant) useSceneStore

Create a Vue store for the scene, which is a wrapper around the Ray Optics Simulation core library Scene class. /** Create a Vue store for the scene, which is a wrapper around the Ray Optics Simulation core library Scene class.

Source:

(constant) useStatusStore

Create a Vue store for application status

Source:

(constant) useThemeStore

Create a Vue store for theme properties, which manages the nested theme structure from Scene.

Source:

(constant) vTooltipPopover

Vue directive for handling Bootstrap tooltips and popovers Usage:

  • For tooltips: v-tooltip-popover="{ title: 'Tooltip text' }"
  • For popovers: v-tooltip-popover:popover="{ title: 'Title', content: 'Content', popoverImage: 'image.svg' }"
Source:

Methods

CircleObjMixin(Base) → {T}

The mixin for the scene objects that are defined by a circle.

Parameters:
Name Type Description
Base T
Source:
Returns:
Type
T

LineObjMixin(Base) → {T}

The mixin for the scene objects that are defined by a line segment.

Parameters:
Name Type Description
Base T
Source:
Returns:
Type
T

ParamCurveObjMixin(Base) → {T}

The mixin for the scene objects that are defined by a line segment.

Parameters:
Name Type Description
Base T
Source:
Returns:
Type
T

checkRayIntersectsShape(ray) → {Point}

Check if a ray intersects the circle. In the child class, this can be called from the checkRayIntersects method.

Parameters:
Name Type Description
ray Ray

The ray.

Source:
Returns:

The intersection point, or null if there is no intersection.

Type
Point

checkRayIntersectsShape(ray) → {Point}

Check if a ray intersects the line segment. In the child class, this can be called from the checkRayIntersects method.

Parameters:
Name Type Description
ray Ray

The ray.

Source:
Returns:

The intersection point, or null if there is no intersection.

Type
Point

countIntersections(point) → {number}

Count intersections between a horizontal ray from the point and the parametric curve. Uses a more robust crossing number algorithm that handles dense/repeated points. Lazy-generates the path if needed.

Parameters:
Name Type Description
point Point

The point from which to cast the horizontal ray

Source:
Returns:

Number of intersections with the curve boundary

Type
number

deepEqual(obj1, obj2) → {boolean}

Recursively compare two objects for equality.

Parameters:
Name Type Description
obj1 *

First object

obj2 *

Second object

Source:
Returns:

True if objects are equal

Type
boolean

distancePointToSegment(point, segment) → {number}

Calculate distance from a point to a line segment.

Parameters:
Name Type Description
point Point

The point

segment Line

The line segment

Source:
Returns:

Distance from point to segment

Type
number

drawPath(canvasRenderer, offset)

Draw the parametric curve path on the canvas. This method sets up the canvas path but does not stroke or fill it.

Parameters:
Name Type Default Description
canvasRenderer CanvasRenderer

The canvas renderer

offset number 0

Optional offset distance perpendicular to the curve (positive = left side)

Source:

extractNonDefaults(obj, defaults) → {Object|null}

Recursively extract only non-default values from a nested object.

Parameters:
Name Type Description
obj Object

The object to extract from

defaults Object

The default values

Source:
Returns:

Object containing only non-default values, or null if all values are default

Type
Object | null

getRayIntersections(ray) → {Array}

Get all ray intersections with the parametric curve. Returns an array of intersection data with normal vectors and incident types consistent with CustomArcSurface conventions for counterclockwise arcs.

Parameters:
Name Type Description
ray Ray

The ray to check intersections with

Source:
Returns:

Array of intersection objects with properties:

  • s_point: intersection point
  • normal: {x, y} normal vector
  • incidentType: 1 (inside to outside), -1 (outside to inside), or NaN
  • incidentPiece: piece index (0-based)
  • incidentPos: parameter t value of the intersection
Type
Array

initPath() → {boolean}

Initialize the path points based on the parametric curve pieces. This method generates points for each piece from tMin to tMax with the given step.

Source:
Returns:

Whether the initialization was successful.

Type
boolean

isClosed() → {boolean}

Check if the parametric curve is closed (first point matches last point within floating point error). Lazy-generates the path if needed.

Source:
Returns:

True if the curve is closed, false otherwise

Type
boolean

isInside(point) → {boolean}

Check if a point is inside the parametric curve (using crossing number algorithm). Lazy-generates the path if needed.

Parameters:
Name Type Description
point Point

The point to test

Source:
Returns:

True if the point is inside the curve, false otherwise

Type
boolean

isOnBoundary(point) → {boolean}

Check if a point is on the boundary of the parametric curve. Uses distance-based approach similar to checkMouseOver for robustness. Lazy-generates the path if needed.

Parameters:
Name Type Description
point Point

The point to test

Source:
Returns:

True if the point is on the boundary, false otherwise

Type
boolean

isOutside(point) → {boolean}

Check if a point is outside the parametric curve (using crossing number algorithm). Lazy-generates the path if needed.

Parameters:
Name Type Description
point Point

The point to test

Source:
Returns:

True if the point is outside the curve, false otherwise

Type
boolean

isPositivelyOriented() → {boolean}

Check if the parametric curve is positively oriented (clockwise in the computer graphics coordinate system). Uses the shoelace formula to calculate signed area. Lazy-generates the path if needed.

Source:
Returns:

True if the curve is positively oriented false otherwise

Type
boolean

mergeWithDefaults(target, source, defaults, path) → {Object}

Recursively merge a nested object with its defaults.

Parameters:
Name Type Description
target Object

The target object to merge into

source Object

The source object to merge from

defaults Object

The default values

path string

The current path for error reporting

Source:
Returns:

The merged object

Type
Object

populateObjBarShape(objBar)

Populate the object bar with parametric curve controls. This method should be called from populateObjBar in subclasses.

Parameters:
Name Type Description
objBar ObjBar

The object bar instance

Source:

setViewportSize(width, height)

Set the size (in CSS pixels) for the viewport of the scene.

Parameters:
Name Type Description
width number
height number
Source:

toJSON() → {string}

Convert the scene to JSON.

Source:
Returns:

The JSON string representing the scene.

Type
string

useStatus() → {Object}

Composable for handling application status including mouse position, simulator metrics, and system status (errors/warnings)

Source:
Returns:

Reactive status state and computed properties

Type
Object

validateNestedKeys(obj, defaults, path) → {string|null}

Recursively validate that an object only contains known keys.

Parameters:
Name Type Description
obj Object

The object to validate

defaults Object

The default structure defining known keys

path string

The current path for error reporting

Source:
Returns:

The path of unknown key if found, null otherwise

Type
string | null

versionUpdate(jsonData) → {Object}

Update the scene JSON data to the latest version.

Parameters:
Name Type Description
jsonData Object
Source:
Returns:

The updated JSON data.

Type
Object

Type Definitions

BodyMergingObj

Every ray has a temporary bodyMerging object ("bodyMergingObj") as a property (this property exists only while the ray is inside a region of one or several overlapping grin objects - e.g. CircleGrinGlass and GrinGlass), which gets updated as the ray enters/exits into/from grin objects, using the "multRefIndex"/"devRefIndex" function, respectively.

Type:
  • Object
Properties:
Name Type Description
fn_p function

The refractive index function for the equivalent region of the simulation.

fn_p_der_x function

The x derivative of fn_p for the equivalent region of the simulation.

fn_p_der_y function

The y derivative of fn_p for the equivalent region of the simulation.

Source:

Circle

Type:
  • Object
Properties:
Name Type Description
c Point
r number | Line
Source:

ConstructReturn

Type:
  • Object
Properties:
Name Type Attributes Description
isDone boolean <optional>

Whether the construction is done.

requiresObjBarUpdate boolean <optional>

Whether the object bar should be updated.

isCancelled boolean <optional>

Whether the construction is cancelled.

Source:

ControlPoint

Type:
  • Object
Properties:
Name Type Description
dragContext DragContext

The drag context of the virtual mouse that is dragging the control point.

newPoint Point

The new position of the control point.

Source:

DragContext

Type:
  • Object
Properties:
Name Type Attributes Description
part number

The index of the part within the object being dragged. 0 for the whole object.

targetPoint Point <optional>

The target point where the user is dragging. This is recognized by the editor so that it can be used for popping up the coordinate box (when the user double-clicks or right-clicks such a point), or binding to a handle (when the user holds Ctrl and clicks such a point).

targetPoint_ Point <optional>

If this property is set instead of setting targetPoint, then the point will not be used for the coordinate box or handle, but is still recognized by the editor when deciding which part of which object the user want to interact with.

requiresObjBarUpdate boolean <optional>

Whether the object bar should be updated during the dragging.

cursor string <optional>

The cursor to be used during hovering and dragging.

snapContext SnapContext <optional>

The snap context.

hasDuplicated boolean <optional>

Whether the object is duplicated during the dragging. This is true when the user holds the Ctrl key and drags the whole object. Only set by the editor.

originalObj BaseSceneObj <optional>

The original object when the dragging starts. Only set by the editor.

isByHandle boolean <optional>

Whether the dragging is initiated by dragging a handle. Only set by the editor.

Source:

Line

Type:
  • Object
Properties:
Name Type Description
p1 Point
p2 Point
Source:

ModuleDef

Type:
  • Object
Properties:
Name Type Description
numPoints number

The number of control points of the module.

params Array.<string>

The parameters of the module.

vars Array.<string>

Mathematical variable definitions that can be used in the objects.

objs Array.<Object>

The objects in the module in the form of JSON objects with template syntax.

maxLoopLength number

The maximum length of the list in for loops to prevent infinite loops.

Source:

OutRay

Variables that can be used in the angle and brightness functions:

  • (\theta_0): The angle of the incident ray.
  • (\lambda): The wavelength of the incident ray.
  • (t): The position of the incident ray on the surface.
  • (p): The polarization of the incident ray. 0 for s-polarized, 1 for p-polarized.
  • (n_0): The refractive index of the source medium (glass merged at the same side as the incident ray).
  • (n_1): The refractive index of the destination medium (glass merged at the opposite side as the incident ray).
  • (\theta_1), (\theta_2), ..., (\theta_{j-1}): The angles of the previous outgoing rays. For (P_j), (\theta_j) can also be used.
  • (P_1), (P_2), ..., (P_{j-1}): The brightnesses of the previous outgoing rays.
Type:
  • Object
Properties:
Name Type Description
eqnTheta string

The LaTeX expression of the angle (\theta_j) of the jth outgoing ray.

eqnP string

The LaTeX expression of the brightness (P_j) of the jth outgoing ray.

Source:

Point

Type:
  • Object
Properties:
Name Type Description
x number
y number
Source:

Ray

Type:
  • Object
Properties:
Name Type Attributes Description
p1 Point

The starting point of the ray.

p2 Point

Another point on the ray.

brightness_s number

he intensity of the s-polarization component of the ray.

brightness_p number

The intensity of the p-polarization component of the ray. In this simulator the two polarization components are assumed to be of no phase coherence.

wavelength number <optional>

The wavelength of the ray in nanometers. Only has effect when "Simulate Colors" is on.

gap boolean

Whether the ray is the first ray in a bunch of "continuous" rays. This is for the detection of images to work correctly. The intersection of two rays is considered as a candidate of an image only if the second ray has gap === false.

isNew boolean

Whether the ray is just emitted by a source. This is to avoid drawing trivial initial extensions in the "Extended rays" mode.

Source:

SelectionSearchResult

Type:
  • Object
Properties:
Name Type Description
dragContext DragContext

The drag context.

targetObjIndex number

The index of the target object.

Source:

SimulationReturn

Type:
  • Object
Properties:
Name Type Attributes Description
isAbsorbed boolean <optional>

Whether the object absorbs the ray.

newRays Array.<Ray> <optional>

The new rays to be added.

truncation number <optional>

The brightness of truncated rays due to numerical cutoff (e.g. after a large number of partial internal reflections within a glass). This is used to estimate the error of the simulation.

brightnessScale number <optional>

The actual brightness of the ray divided by the brightness inferred from the properties of the object. This should be 1 when "ray density" is high enough. When "ray density" is low, the calculated brightness of the individual rays will be too high (alpha value for rendering will be larger than 1). In this case, the object should rescale all the brightness of the rays by a factor to keep the maximum alpha value to be 1. This factor should be returned here and is used to generate warnings.

isUndefinedBehavior boolean <optional>

Whether the behavior of the ray is undefined. For example, when the ray is incident on a corner of a glass.

Source:

SnapContext

Type:
  • Object
Properties:
Name Type Attributes Description
locked boolean <optional>

Whether the snapping direction is locked.

i0 number <optional>

The index of the locked direction.

Source:

loadJSONCallback(needFullUpdate, completed)

The callback function when the entire scene or a resource (e.g. image) is loaded.

Parameters:
Name Type Description
needFullUpdate boolean

Whether the scene needs a full update.

completed boolean

Whether the scene is completely loaded.

Source:

objBarValueChangeCallback(obj, value)

The callback function for when a value changes. If "Apply to all" is checked, this function will be called for each scene object of the same type.

Parameters:
Name Type Description
obj Object

The scene object whose value changed.

value any

The new value.

Source:

Events

requestUpdateErrorAndWarning

The event when the error and warning messages in the UI should be updated.

Source:

requestUpdateErrorAndWarning

The event when the error and warning messages in the UI should be updated.

Source:

webglContextLost

The event when the WebGL context is lost.

Source: