Class: Blocker

sceneObjs.Blocker()

Line blocker / filter.

Tools -> Blocker -> Line Blocker

Constructor

new Blocker()

Properties:
Name Type Description
p1 Point

The first endpoint.

p2 Point

The second endpoint.

filter boolean

Whether it is a filter.

invert boolean

If true, the ray with wavelength outside the bandwidth is blocked. If false, the ray with wavelength inside the bandwidth is blocked.

wavelength number

The target wavelength if filter is enabled. The unit is nm.

bandwidth number

The bandwidth if filter is enabled. The unit is nm.

Source:

Extends

Members

error

Properties:
Name Type Description
error string | null

The error message of the object.

Inherited From:
Source:

isOptical

Whether the object is optical (i.e. is a light source, interacts with rays, or detects rays).

Overrides:
Source:

scene

Properties:
Name Type Description
scene Scene

The scene the object belongs to.

Inherited From:
Source:

serializableDefaults

The default values of the properties of the object which are to be serialized. The keys are the property names and the values are the default values. If some properties is default, they will not be serialized and will be deserialized to the default values.

Overrides:
Source:

supportsSurfaceMerging

Whether the object supports surface merging. (This is currently only for glasses, where the surfaces of two glasses are merged to form a single surface if the surfaces overlap.)

Inherited From:
Source:

type

The type of the object.

Overrides:
Source:

warning

Properties:
Name Type Description
warning string | null

The warning message of the object.

Inherited From:
Source:

Methods

arePropertiesDefault(propertyNames) → {boolean}

Check whether the given properties of the object are all the default values.

Parameters:
Name Type Description
propertyNames Array.<string>

The property names to be checked.

Inherited From:
Source:
Returns:

Whether the properties are all the default values.

Type
boolean

checkMouseOver(mouse) → {DragContext|null}

Check whether the mouse is over the object, which is called when the user moves the mouse over the scene. This is used for deciding the highlighting of the object, and also for deciding that if the user starts dragging at this position, which part of the object should be dragged.

Parameters:
Name Type Description
mouse Mouse

The mouse object.

Inherited From:
Source:
Returns:

The drag context if the user starts dragging at this position, or null if the mouse is not over the object.

Type
DragContext | null

checkRayIntersectFilter(ray) → {boolean}

Checks if the ray interacts with the filter at the level of the wavelength.

Parameters:
Name Type Description
ray Ray

The ray to be checked.

Inherited From:
Source:
Returns:
  • If true, the ray interacts with the filter at the level of the wavelength.
Type
boolean

checkRayIntersects(ray) → {Point|null}

Check whether the object intersects with the given ray. Called during the ray tracing when ray is to be tested whether it intersects with the object. Find whether they intersect and find the nearset intersection if so. Implemented only by optical elements that affects or detect rays.

Parameters:
Name Type Description
ray Ray

The ray.

Overrides:
Source:
Returns:
  • The intersection (closest to the beginning of the ray) if they intersect.
Type
Point | null

draw(canvasRenderer, isAboveLight, isHovered)

Draw the object on the canvas. Called once before the simulator renders the light with isAboveLight === false and once after with isAboveLight === true. Due to historical reason, some objects use this function to do some initialization. This should be avoided in the future.

Parameters:
Name Type Description
canvasRenderer CanvasRenderer

The canvas renderer.

isAboveLight boolean

Whether the rendering layer is above the light layer.

isHovered boolean

Whether the object is hovered by the mouse, which determines the style of the object to be drawn, e.g., with lighlighted color.

Overrides:
Source:

getError() → {string|null}

Get the error message of the object.

Inherited From:
Source:
Returns:

The error message.

Type
string | null

getWarning() → {string|null}

Get the warning message of the object.

Inherited From:
Source:
Returns:

The warning message.

Type
string | null

getZIndex() → {number}

Get the z-index of the object for the sequence of drawing. Called before the simulator starts to draw the scene.

Inherited From:
Source:
Returns:

The z-index. The smaller the number is, the earlier draw is called.

Type
number

move(diffX, diffY)

Move the object by the given displacement. Called when the user use arrow keys to move the object.

Parameters:
Name Type Description
diffX number

The x-coordinate displacement.

diffY number

The y-coordinate displacement.

Inherited From:
Source:

onConstructMouseDown(mouse, ctrl, shift) → {ConstructReturn}

Mouse down event when the object is being constructed by the user.

Parameters:
Name Type Description
mouse Mouse

The mouse object.

ctrl boolean

Whether the control key is pressed.

shift boolean

Whether the shift key is pressed.

Inherited From:
Source:
Returns:

The return value.

Type
ConstructReturn

onConstructMouseMove(mouse, ctrl, shift) → {ConstructReturn}

Mouse move event when the object is being constructed by the user.

Parameters:
Name Type Description
mouse Mouse

The mouse object.

ctrl boolean

Whether the control key is pressed.

shift boolean

Whether the shift key is pressed.

Inherited From:
Source:
Returns:

The return value.

Type
ConstructReturn

onConstructMouseUp(mouse, ctrl, shift) → {ConstructReturn}

Mouse up event when the object is being constructed by the user.

Parameters:
Name Type Description
mouse Mouse

The mouse object.

ctrl boolean

Whether the control key is pressed.

shift boolean

Whether the shift key is pressed.

Inherited From:
Source:
Returns:

The return value.

Type
ConstructReturn

onConstructUndo() → {ConstructReturn}

Undo event when the object is being constructed by the user.

Inherited From:
Source:
Returns:

The return value.

Type
ConstructReturn

onDrag(mouse, dragContext, ctrl, shift)

The event when the user drags the object, which is fired on every step during the dragging. The object should be updated according to DragContext which is returned by checkMouseOver. dragContext can be modified during the dragging.

Parameters:
Name Type Description
mouse Mouse

The mouse object.

dragContext DragContext

The drag context.

ctrl boolean

Whether the control key is pressed.

shift boolean

Whether the shift key is pressed.

Inherited From:
Source:

onRayIncident(ray, rayIndex, incidentPoint, surfaceMergingObjs) → {SimulationReturn|null}

The event when a ray is incident on the object. Called during the ray tracing when ray has been calculated to be incident on the object at the incidentPoint. Perform the interaction between ray and the object. Implemented only by optical elements that affects or detect rays. If ray is absorbed by the object, return { isAbsorbed: true }. If there is a primary outgoing ray, directly modify ray to be the outgoing ray. This includes the case when the object is a detector that does not modify the direction of the ray. If there are secondary rays to be emitted, return { newRays: [ray1, ray2, ...] }. Note that if there are more than one secondary rays, image detection does not work in the current version, and rayN.gap should be set to true. But for future support, the secondary ray which is to be of the same continuous bunch or rays should have consistent index in the newRays array. Sometimes keeping tracks of all the rays may result in infinite loop (such as in a glass). Depending on the situation, some rays with brightness below a certain threshold (such as 0.01) may be truncated. In this case, the brightness of the truncated rays should be returned as truncation.

Parameters:
Name Type Description
ray Ray

The ray.

rayIndex number

The index of the ray in the array of all rays currently in the scene in the simulator. In particular, in a bunch of continuous rays, the rays are ordered by the time they are emitted, and the index is the order of emission. This can be used to downsample the rays and increase the individual brightness if it is too low.

incidentPoint Point

The point where the ray is incident on the object, which is the intersection point found by checkRayIntersects.

surfaceMergingObjs Array.<BaseSceneObj>

The objects that are merged with the current object. If two or more objects with supportsSurfaceMerging === true has overlapping surfaces (often acheived by using the grid), and if a ray is incident on those surfaces together, only one of the object will be have onRayIncident being called, and the other objects will be in surfaceMergingObjs. In this case, this function must also deal with the combination of the surface before doing the actual interaction. Note that treating them as two very close surfaces may not give the correct result due to an essential discontinuity of ray optics (which is smoothed out at the scale of the wavelength in reality).

Overrides:
Source:
Returns:

The return value.

Type
SimulationReturn | null

onSimulationStart() → {SimulationReturn|null}

The event when the simulation starts. If this object is a light source, it should emit rays here by setting newRays. If the object is a detector, it may do some initialization here.

Inherited From:
Source:
Returns:

The return value.

Type
SimulationReturn | null

populateObjBar(objBar)

Populate the object bar. Called when the user selects the object (it is selected automatically when the user creates it, so the construction may not be completed at this stage).

Parameters:
Name Type Description
objBar ObjBar

The object bar to be populated.

Overrides:
Source:

rotate(cw)

Rotate the object. (This feature is incomplete and currently only implemented for ConcaveDiffractionGrating.)

Parameters:
Name Type Description
cw number
Inherited From:
Source:

serialize() → {Object}

Serializes the object to a JSON object.

Inherited From:
Source:
Returns:

The serialized JSON object.

Type
Object