# 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:
  - Scene.js, line 30

### Methods

#### CircleObjMixin(Base) → {T}

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

##### Parameters:

Name | Type | Description
--- | --- | ---
`Base` | T |

Source:
  - sceneObjs/CircleObjMixin.js, line 26

##### 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:
  - sceneObjs/LineObjMixin.js, line 26

##### 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:
  - sceneObjs/CircleObjMixin.js, line 136

##### 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:
  - sceneObjs/LineObjMixin.js, line 137

##### Returns:

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

Type
  Point

#### setViewportSize(width, height)

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

##### Parameters:

Name | Type | Description
--- | --- | ---
`width` | number |
`height` | number |

Source:
  - Scene.js, line 99

#### toJSON() → {string}

Convert the scene to JSON.

Source:
  - Scene.js, line 230

##### Returns:

The JSON string representing the scene.

Type
  string

#### versionUpdate(jsonData) → {Object}

Update the scene JSON data to the latest version.

##### Parameters:

Name | Type | Description
--- | --- | ---
`jsonData` | Object |

Source:
  - versionUpdate.js, line 185

##### 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:
  - sceneObjs/BaseGrinGlass.js, line 25

#### Circle

##### Type:

- Object

##### Properties:

Name | Type | Description
--- | --- | ---
`c` | Point |
`r` | number | Line |

Source:
  - geometry.js, line 29

#### 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:
  - sceneObjs/BaseSceneObj.js, line 17

#### 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:
  - Editor.js, line 48

#### 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:
  - Editor.js, line 29

#### Line

##### Type:

- Object

##### Properties:

Name | Type | Description
--- | --- | ---
`p1` | Point |
`p2` | Point |

Source:
  - geometry.js, line 23

#### 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.
`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:
  - sceneObjs/special/ModuleObj.js, line 23

#### Point

##### Type:

- Object

##### Properties:

Name | Type | Description
--- | --- | ---
`x` | number |
`y` | number |

Source:
  - geometry.js, line 17

#### 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:
  - Simulator.js, line 28

#### SelectionSearchResult

##### Type:

- Object

##### Properties:

Name | Type | Description
--- | --- | ---
`dragContext` | DragContext | The drag context.
`targetObjIndex` | number | The index of the target object.

Source:
  - Editor.js, line 42

#### 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.

Source:
  - sceneObjs/BaseSceneObj.js, line 24

#### 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:
  - Editor.js, line 54

#### 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:
  - Scene.js, line 141

#### 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:
  - ObjBar.js, line 95

### Events

#### requestUpdateErrorAndWarning

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

Source:
  - Editor.js, line 268

#### requestUpdateErrorAndWarning

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

Source:
  - Simulator.js, line 195