Skip to content

Commit

Permalink
Improve types, see #401
Browse files Browse the repository at this point in the history
  • Loading branch information
samreid committed Oct 11, 2021
1 parent 666c44c commit 17a9372
Show file tree
Hide file tree
Showing 7 changed files with 6 additions and 14 deletions.
4 changes: 1 addition & 3 deletions js/common/model/BendingLightModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const DEFAULT_LASER_DISTANCE_FROM_PIVOT = 9.225E-6;
const CHARACTERISTIC_LENGTH = BendingLightConstants.WAVELENGTH_RED;

abstract class BendingLightModel {
readonly rays: LightRay[]; // Comes from ObservableArray
readonly rays: ObservableArray<LightRay>;
mediumColorFactory: MediumColorFactory;
readonly modelWidth: number;
readonly modelHeight: number;
Expand Down Expand Up @@ -97,8 +97,6 @@ abstract class BendingLightModel {
*/
clearModel() {
for ( let i = 0; i < this.rays.length; i++ ) {

// @ts-ignore createObservableArray
this.rays[ i ].particles.clear();
}
this.rays.length = 0;
Expand Down
2 changes: 1 addition & 1 deletion js/common/model/LightRay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class LightRay {
numWavelengthsPhaseOffset: number;
extend: boolean;
vectorForm: Vector2;
particles: WaveParticle[];
particles: ObservableArray<WaveParticle>;
time: number;
rayType: string;
unitVector: Vector2;
Expand Down
2 changes: 1 addition & 1 deletion js/common/model/WaveParticle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import bendingLight from '../../bendingLight.js';
class WaveParticle {
private readonly position: Vector2;
private readonly width: number;
private readonly color: string;
readonly color: string;
readonly angle: number;
readonly height: number;
readonly particleGradientColor: string;
Expand Down
4 changes: 1 addition & 3 deletions js/intro/view/AngleNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class AngleNode extends Node {
* @param {ModelViewTransform2} modelViewTransform
* @param {function} addStepListener -
*/
constructor( showAnglesProperty: Property, laserOnProperty: Property, showNormalProperty: Property, rays: LightRay[], modelViewTransform: ModelViewTransform2,
constructor( showAnglesProperty: Property, laserOnProperty: Property, showNormalProperty: Property, rays: ObservableArray<LightRay>, modelViewTransform: ModelViewTransform2,
addStepListener: ( x: () => void ) => void ) {
super();

Expand Down Expand Up @@ -111,9 +111,7 @@ class AngleNode extends Node {
dirty = true;
};

// @ts-ignore
rays.addItemAddedListener( markDirty );
// @ts-ignore
rays.addItemRemovedListener( markDirty );

/**
Expand Down
2 changes: 0 additions & 2 deletions js/intro/view/WaveCanvasNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,10 @@ class WaveCanvasNode extends CanvasNode {
const wavelength = this.modelViewTransform.modelToViewDeltaX( particle.height );

// Fill the background with the dark color, in the entire clip area
// @ts-ignore
context.fillStyle = particle.particleGradientColor;
context.fillRect( -1000, -1000, 2000, 2000 );

// Set up the color for the wave crests
// @ts-ignore
context.fillStyle = particle.color;

// Render each crest, but we don't need as many wavelengths for the incoming light
Expand Down
4 changes: 2 additions & 2 deletions js/intro/view/WaveWebGLNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ const scratchFloatArray2 = new Float32Array( 9 );

class WaveWebGLNode extends WebGLNode {
readonly modelViewTransform: ModelViewTransform2;
readonly rays: LightRay[];
readonly rays: ObservableArray<LightRay>;

/**
* @param {ModelViewTransform2} modelViewTransform - Transform between model and view coordinate frames
* @param {ObservableArrayDef.<LightRay>} rays - light rays
*/
constructor( modelViewTransform: ModelViewTransform2, rays: LightRay[] ) {
constructor( modelViewTransform: ModelViewTransform2, rays: ObservableArray<LightRay> ) {
super( WavePainter );
this.modelViewTransform = modelViewTransform; // @public (read-only)
this.rays = rays; // @private
Expand Down
2 changes: 0 additions & 2 deletions js/prisms/view/PrismsScreenView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,6 @@ class PrismsScreenView extends BendingLightScreenView {
stageWidth,
stageHeight,
bendingLightModel.rays,

// @ts-ignore
bendingLightModel.environmentMediumProperty,
bendingLightModel.mediumColorFactory
);
Expand Down

0 comments on commit 17a9372

Please sign in to comment.