-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Code Review #398
Comments
As I take an initial look in the code, I'm seeing that things are well-documented and readable, and looking in very good shape. Nice work! I wanted to start a discussion checklist of things to ask about--some of them more stylistic and about consistency across repos, and I wouldn't feel comfortable committing changes without discussing:
Subject: [PATCH] constructor properties
---
Index: js/quadrilateral/view/SideTicksNode.ts
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/js/quadrilateral/view/SideTicksNode.ts b/js/quadrilateral/view/SideTicksNode.ts
--- a/js/quadrilateral/view/SideTicksNode.ts (revision 5fbeaa88abbea17b05824e82b473027f60b711db)
+++ b/js/quadrilateral/view/SideTicksNode.ts (date 1677738730918)
@@ -25,10 +25,8 @@
const SCRATCH_LINE = new Line( new Vector2( 0, 0 ), new Vector2( 0, 0 ) );
class SideTicksNode extends Path {
- private readonly side: QuadrilateralSide;
- private readonly modelViewTransform: ModelViewTransform2;
- public constructor( side: QuadrilateralSide, modelViewTransform: ModelViewTransform2 ) {
+ public constructor( private readonly side: QuadrilateralSide, private readonly modelViewTransform: ModelViewTransform2 ) {
super( null, {
stroke: QuadrilateralColors.quadrilateralShapeStrokeColorProperty
} );
In discussion, @jessegreenberg and I agreed not to use that pattern in this sim.
Subject: [PATCH] constructor properties
---
Index: js/quadrilateral/model/QuadrilateralVertex.ts
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/js/quadrilateral/model/QuadrilateralVertex.ts b/js/quadrilateral/model/QuadrilateralVertex.ts
--- a/js/quadrilateral/model/QuadrilateralVertex.ts (revision 5fbeaa88abbea17b05824e82b473027f60b711db)
+++ b/js/quadrilateral/model/QuadrilateralVertex.ts (date 1677739581193)
@@ -56,7 +56,18 @@
public readonly rightConstrainedProperty = new BooleanProperty( false );
public readonly topConstrainedProperty = new BooleanProperty( false );
public readonly bottomConstrainedProperty = new BooleanProperty( false );
- public readonly numberOfConstrainingEdgesProperty: TReadOnlyProperty<number>;
+ public readonly numberOfConstrainingEdgesProperty = new DerivedProperty( [
+ this.topConstrainedProperty,
+ this.rightConstrainedProperty,
+ this.bottomConstrainedProperty,
+ this.leftConstrainedProperty
+ ], ( topConstrained, rightConstrained, bottomConstrained, leftConstrained ) => {
+ const topVal = topConstrained ? 1 : 0;
+ const rightVal = rightConstrained ? 1 : 0;
+ const bottomVal = bottomConstrained ? 1 : 0;
+ const leftVal = leftConstrained ? 1 : 0;
+ return topVal + rightVal + bottomVal + leftVal;
+ } );
// A reference to vertices connected to this vertex for so we can calculate the angle at this vertex.
// The orientation of vertex1 and vertex2 for angle calculations are as shown in the following diagram:
@@ -110,18 +121,6 @@
return new Bounds2( position.x - HALF_WIDTH, position.y - HALF_HEIGHT, position.x + HALF_WIDTH, position.y + HALF_HEIGHT );
} );
- this.numberOfConstrainingEdgesProperty = new DerivedProperty( [
- this.topConstrainedProperty,
- this.rightConstrainedProperty,
- this.bottomConstrainedProperty,
- this.leftConstrainedProperty
- ], ( topConstrained, rightConstrained, bottomConstrained, leftConstrained ) => {
- const topVal = topConstrained ? 1 : 0;
- const rightVal = rightConstrained ? 1 : 0;
- const bottomVal = bottomConstrained ? 1 : 0;
- const leftVal = leftConstrained ? 1 : 0;
- return topVal + rightVal + bottomVal + leftVal;
- } );
this.tandem = tandem;
}
Subject: [PATCH] constructor properties
---
Index: js/quadrilateral/model/QuadrilateralVertex.ts
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/js/quadrilateral/model/QuadrilateralVertex.ts b/js/quadrilateral/model/QuadrilateralVertex.ts
--- a/js/quadrilateral/model/QuadrilateralVertex.ts (revision 5fbeaa88abbea17b05824e82b473027f60b711db)
+++ b/js/quadrilateral/model/QuadrilateralVertex.ts (date 1677739825789)
@@ -72,7 +72,7 @@
// controlled by a prototype tangible. See smoothPosition().
private readonly smoothingLengthProperty: TReadOnlyProperty<number>;
- // The collection of SMOOTHING_LENGTH number of positions for prototype tangible control. See smoothPosition().
+ // The collection of n <= SMOOTHING_LENGTH number of positions for prototype tangible control. See smoothPosition().
private readonly positions: Vector2[] = [];
// in model coordinates, the width of the QuadrilateralVertex
Subject: [PATCH] constructor properties
---
Index: js/quadrilateral/model/ShapeSnapshot.ts
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/js/quadrilateral/model/ShapeSnapshot.ts b/js/quadrilateral/model/ShapeSnapshot.ts
--- a/js/quadrilateral/model/ShapeSnapshot.ts (revision 5fbeaa88abbea17b05824e82b473027f60b711db)
+++ b/js/quadrilateral/model/ShapeSnapshot.ts (date 1677739911289)
@@ -36,7 +36,7 @@
public readonly sideBCLength: number;
public readonly sideDALength: number;
public readonly sideCDLength: number;
- private readonly sideLengths: number[];
+ private readonly sideLengths: readonly number[];
public constructor( shapeModel: QuadrilateralShapeModel ) {
this.isParallelogram = shapeModel.isParallelogramProperty.value;
|
Subject: [PATCH] Use ternary operator, see https://github.com/phetsims/quadrilateral/issues/398
---
Index: js/quadrilateral/view/QuadrilateralIconFactory.ts
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/js/quadrilateral/view/QuadrilateralIconFactory.ts b/js/quadrilateral/view/QuadrilateralIconFactory.ts
--- a/js/quadrilateral/view/QuadrilateralIconFactory.ts (revision 4266288d3e5c19b3d84ef0bdad529510169aa581)
+++ b/js/quadrilateral/view/QuadrilateralIconFactory.ts (date 1677770615285)
@@ -24,13 +24,13 @@
* Creates an icon for the "Corner Labels" checkbox that toggles visibility of labels on each QuadrilateralVertex.
*/
createCornerLabelsIcon(): Node {
- const label = new Text( 'A', QuadrilateralConstants.SCREEN_TEXT_OPTIONS );
+
const circle = new Circle( QuadrilateralIconFactory.ICON_HEIGHT / 2, {
stroke: QuadrilateralColors.visibilityIconsColorProperty,
lineWidth: QuadrilateralIconFactory.ICON_LINE_WIDTH
} );
- label.center = circle.center;
+ const label = new Text( 'A', { center: circle.center, ...QuadrilateralConstants.SCREEN_TEXT_OPTIONS } );
circle.addChild( label );
return circle;
|
Current patch for QuadrilateralShapeDetector: Subject: [PATCH] Add REVIEW comments, see https://github.com/phetsims/quadrilateral/issues/398
---
Index: js/quadrilateral/model/QuadrilateralShapeDetector.ts
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/js/quadrilateral/model/QuadrilateralShapeDetector.ts b/js/quadrilateral/model/QuadrilateralShapeDetector.ts
--- a/js/quadrilateral/model/QuadrilateralShapeDetector.ts (revision a7db24118c6c8642e6e2018e7f282b5f7300cbec)
+++ b/js/quadrilateral/model/QuadrilateralShapeDetector.ts (date 1677801894817)
@@ -19,79 +19,93 @@
* @author Jesse Greenberg (PhET Interactive Simulations)
*/
-/* eslint-disable no-bitwise*/
-
import quadrilateral from '../../quadrilateral.js';
import QuadrilateralShapeModel from './QuadrilateralShapeModel.js';
import NamedQuadrilateral from './NamedQuadrilateral.js';
// Set up the bits for each shape property.
-const CONCAVE = Math.pow( 2, 0 );
-const ONE_PARALLEL_PAIR = Math.pow( 2, 1 );
-const TWO_PARALLEL_PAIR = Math.pow( 2, 2 );
-const TWO_EQUAL_ADJACENT_ANGLE_PAIR = Math.pow( 2, 4 ); // REVIEW: Are we skipping 3?
-const ONE_EQUAL_OPPOSITE_ANGLE_PAIR = Math.pow( 2, 5 );
-const TWO_EQUAL_OPPOSITE_ANGLE_PAIR = Math.pow( 2, 6 );
-const ALL_EQUAL_ANGLE = Math.pow( 2, 7 );// REVIEW: Are we skipping 8?
-const TWO_EQUAL_ADJACENT_SIDE_PAIR = Math.pow( 2, 9 );
-const ONE_EQUAL_OPPOSITE_SIDE_PAIR = Math.pow( 2, 10 );
-const TWO_EQUAL_OPPOSITE_SIDE_PAIR = Math.pow( 2, 11 );
-const ALL_EQUAL_SIDE = Math.pow( 2, 12 );
-const ONE_ANGLE_PIE = Math.pow( 2, 13 );
+const CONCAVE = 'CONCAVE';
+const ONE_PARALLEL_PAIR = 'ONE_PARALLEL_PAIR';
+const TWO_PARALLEL_PAIR = 'TWO_PARALLEL_PAIR';
+const TWO_EQUAL_ADJACENT_ANGLE_PAIR = 'TWO_EQUAL_ADJACENT_ANGLE_PAIR';
+const ONE_EQUAL_OPPOSITE_ANGLE_PAIR = 'ONE_EQUAL_OPPOSITE_ANGLE_PAIR';
+const TWO_EQUAL_OPPOSITE_ANGLE_PAIR = 'TWO_EQUAL_OPPOSITE_ANGLE_PAIR';
+const ALL_EQUAL_ANGLE = 'ALL_EQUAL_ANGLE';
+const TWO_EQUAL_ADJACENT_SIDE_PAIR = 'TWO_EQUAL_ADJACENT_SIDE_PAIR';
+const ONE_EQUAL_OPPOSITE_SIDE_PAIR = 'ONE_EQUAL_OPPOSITE_SIDE_PAIR';
+const TWO_EQUAL_OPPOSITE_SIDE_PAIR = 'TWO_EQUAL_OPPOSITE_SIDE_PAIR';
+const ALL_EQUAL_SIDE = 'ALL_EQUAL_SIDE';
+const ONE_ANGLE_PIE = 'ONE_ANGLE_PIE';
// Set up shape masks for each shape. The quadrilateral must at least these attributes to be considered a match.
-const CONCAVE_MASK = CONCAVE;
+const CONCAVE_REQUIREMENTS = [ CONCAVE ];
-const TRIANGLE_MASK = ONE_ANGLE_PIE;
+const TRIANGLE = [ ONE_ANGLE_PIE ];
-const DART_MASK = CONCAVE |
- ONE_EQUAL_OPPOSITE_ANGLE_PAIR |
- TWO_EQUAL_ADJACENT_SIDE_PAIR;
+const DART = [
+ CONCAVE,
+ ONE_EQUAL_OPPOSITE_ANGLE_PAIR,
+ TWO_EQUAL_ADJACENT_SIDE_PAIR
+];
-const KITE_MASK = ONE_EQUAL_OPPOSITE_ANGLE_PAIR |
- TWO_EQUAL_ADJACENT_SIDE_PAIR;
+const KITE = [
+ ONE_EQUAL_OPPOSITE_ANGLE_PAIR,
+ TWO_EQUAL_ADJACENT_SIDE_PAIR
+];
-const TRAPEZOID_MASK = ONE_PARALLEL_PAIR;
+const TRAPEZOID = [
+ ONE_PARALLEL_PAIR
+];
-const ISOSCELES_TRAPEZOID_MASK = ONE_PARALLEL_PAIR |
- TWO_EQUAL_ADJACENT_ANGLE_PAIR |
- ONE_EQUAL_OPPOSITE_SIDE_PAIR;
+const ISOSCELES_TRAPEZOID = [
+ ONE_PARALLEL_PAIR,
+ TWO_EQUAL_ADJACENT_ANGLE_PAIR,
+ ONE_EQUAL_OPPOSITE_SIDE_PAIR
+];
-const PARALLELOGRAM_MASK = ONE_PARALLEL_PAIR |
- TWO_PARALLEL_PAIR |
- ONE_EQUAL_OPPOSITE_ANGLE_PAIR |
- TWO_EQUAL_OPPOSITE_ANGLE_PAIR |
- ONE_EQUAL_OPPOSITE_SIDE_PAIR |
- TWO_EQUAL_OPPOSITE_SIDE_PAIR;
+const PARALLELOGRAM = [
+ ONE_PARALLEL_PAIR,
+ TWO_PARALLEL_PAIR,
+ ONE_EQUAL_OPPOSITE_ANGLE_PAIR,
+ TWO_EQUAL_OPPOSITE_ANGLE_PAIR,
+ ONE_EQUAL_OPPOSITE_SIDE_PAIR,
+ TWO_EQUAL_OPPOSITE_SIDE_PAIR
+];
-const RECTANGLE_MASK = ONE_PARALLEL_PAIR |
- TWO_PARALLEL_PAIR |
- TWO_EQUAL_ADJACENT_ANGLE_PAIR |
- ONE_EQUAL_OPPOSITE_ANGLE_PAIR |
- TWO_EQUAL_OPPOSITE_ANGLE_PAIR |
- ALL_EQUAL_ANGLE |
- ONE_EQUAL_OPPOSITE_SIDE_PAIR |
- TWO_EQUAL_OPPOSITE_SIDE_PAIR;
+const RECTANGLE = [
+ ONE_PARALLEL_PAIR,
+ TWO_PARALLEL_PAIR,
+ TWO_EQUAL_ADJACENT_ANGLE_PAIR,
+ ONE_EQUAL_OPPOSITE_ANGLE_PAIR,
+ TWO_EQUAL_OPPOSITE_ANGLE_PAIR,
+ ALL_EQUAL_ANGLE,
+ ONE_EQUAL_OPPOSITE_SIDE_PAIR,
+ TWO_EQUAL_OPPOSITE_SIDE_PAIR
+];
-const RHOMBUS_MASK = ONE_PARALLEL_PAIR |
- TWO_PARALLEL_PAIR |
- ONE_EQUAL_OPPOSITE_ANGLE_PAIR |
- TWO_EQUAL_OPPOSITE_ANGLE_PAIR |
- TWO_EQUAL_ADJACENT_SIDE_PAIR |
- ONE_EQUAL_OPPOSITE_SIDE_PAIR |
- TWO_EQUAL_OPPOSITE_SIDE_PAIR |
- ALL_EQUAL_SIDE;
+const RHOMBUS = [
+ ONE_PARALLEL_PAIR,
+ TWO_PARALLEL_PAIR,
+ ONE_EQUAL_OPPOSITE_ANGLE_PAIR,
+ TWO_EQUAL_OPPOSITE_ANGLE_PAIR,
+ TWO_EQUAL_ADJACENT_SIDE_PAIR,
+ ONE_EQUAL_OPPOSITE_SIDE_PAIR,
+ TWO_EQUAL_OPPOSITE_SIDE_PAIR,
+ ALL_EQUAL_SIDE
+];
-const SQUARE_MASK = ONE_PARALLEL_PAIR |
- TWO_PARALLEL_PAIR |
- TWO_EQUAL_ADJACENT_ANGLE_PAIR |
- ONE_EQUAL_OPPOSITE_ANGLE_PAIR |
- TWO_EQUAL_OPPOSITE_ANGLE_PAIR |
- ALL_EQUAL_ANGLE |
- TWO_EQUAL_ADJACENT_SIDE_PAIR |
- ONE_EQUAL_OPPOSITE_SIDE_PAIR |
- TWO_EQUAL_OPPOSITE_SIDE_PAIR |
- ALL_EQUAL_SIDE;
+const SQUARE = [
+ ONE_PARALLEL_PAIR,
+ TWO_PARALLEL_PAIR,
+ TWO_EQUAL_ADJACENT_ANGLE_PAIR,
+ ONE_EQUAL_OPPOSITE_ANGLE_PAIR,
+ TWO_EQUAL_OPPOSITE_ANGLE_PAIR,
+ ALL_EQUAL_ANGLE,
+ TWO_EQUAL_ADJACENT_SIDE_PAIR,
+ ONE_EQUAL_OPPOSITE_SIDE_PAIR,
+ TWO_EQUAL_OPPOSITE_SIDE_PAIR,
+ ALL_EQUAL_SIDE
+];
export default class QuadrilateralShapeDetector {
private readonly quadrilateralShapeModel: QuadrilateralShapeModel;
@@ -108,7 +122,7 @@
* QuadrilateralShapeModel.updateOrderDependentProperties for more information.
*/
public getShapeName(): NamedQuadrilateral {
- let currentConditionMask = 0;
+ const conditions: string[] = [];
// First, assemble a bitwise value representing the attributes of the current shape. Start by looking for
// a triangle, which is a unique case. If we have a triangle we can stop looking for more properties
@@ -116,60 +130,60 @@
// to produce the final properties of the shape.
const shapeModel = this.quadrilateralShapeModel;
if ( _.some( shapeModel.vertices, vertex => shapeModel.isFlatAngle( vertex.angleProperty.value! ) ) ) {
- currentConditionMask = currentConditionMask | TRIANGLE_MASK;
+ conditions.push( ONE_ANGLE_PIE );
}
else {
if ( _.some( shapeModel.vertices, vertex => vertex.angleProperty.value! > Math.PI ) ) {
- currentConditionMask = currentConditionMask | CONCAVE;
+ conditions.push( CONCAVE );
}
if ( shapeModel.parallelSidePairsProperty.value.length > 0 ) {
- currentConditionMask = currentConditionMask | ONE_PARALLEL_PAIR;
+ conditions.push( ONE_PARALLEL_PAIR );
}
if ( shapeModel.parallelSidePairsProperty.value.length > 1 ) {
- currentConditionMask = currentConditionMask | TWO_PARALLEL_PAIR;
+ conditions.push( TWO_PARALLEL_PAIR );
}
if ( shapeModel.adjacentEqualVertexPairsProperty.value.length > 1 ) {
- currentConditionMask = currentConditionMask | TWO_EQUAL_ADJACENT_ANGLE_PAIR;
+ conditions.push( TWO_EQUAL_ADJACENT_ANGLE_PAIR );
}
if ( shapeModel.oppositeEqualVertexPairsProperty.value.length > 0 ) {
- currentConditionMask = currentConditionMask | ONE_EQUAL_OPPOSITE_ANGLE_PAIR;
+ conditions.push( ONE_EQUAL_OPPOSITE_ANGLE_PAIR );
}
if ( shapeModel.oppositeEqualVertexPairsProperty.value.length > 1 ) {
- currentConditionMask = currentConditionMask | TWO_EQUAL_OPPOSITE_ANGLE_PAIR;
+ conditions.push( TWO_EQUAL_OPPOSITE_ANGLE_PAIR );
}
if ( shapeModel.allAnglesRightProperty.value ) {
- currentConditionMask = currentConditionMask | ALL_EQUAL_ANGLE;
+ conditions.push( ALL_EQUAL_ANGLE );
}
if ( shapeModel.adjacentEqualSidePairsProperty.value.length > 1 ) {
- currentConditionMask = currentConditionMask | TWO_EQUAL_ADJACENT_SIDE_PAIR;
+ conditions.push( TWO_EQUAL_ADJACENT_SIDE_PAIR );
}
if ( shapeModel.oppositeEqualSidePairsProperty.value.length > 0 ) {
- currentConditionMask = currentConditionMask | ONE_EQUAL_OPPOSITE_SIDE_PAIR;
+ conditions.push( ONE_EQUAL_OPPOSITE_SIDE_PAIR );
}
if ( shapeModel.oppositeEqualSidePairsProperty.value.length > 1 ) {
- currentConditionMask = currentConditionMask | TWO_EQUAL_OPPOSITE_SIDE_PAIR;
+ conditions.push( TWO_EQUAL_OPPOSITE_SIDE_PAIR );
}
if ( shapeModel.allLengthsEqualProperty.value ) {
- currentConditionMask = currentConditionMask | ALL_EQUAL_SIDE;
+ conditions.push( ALL_EQUAL_SIDE );
}
}
- // Find matches for the current condition - Order of these checks is very important. conditionMatchesMask
+ // Find matches for the current condition - Order of these checks is very important. conditionsMatchRequirements
// returns true if the condition matches the minimum requirements for a shape. But even after there is a match,
// we will continue to search for the most specific attribute matches.
let quadrilateralName: NamedQuadrilateral;
// First look for a triangle - it is unique in that if we have a triangle there are no more shapes "under"
// it that share attributes - so we can return this right away.
- if ( this.conditionMatchesMask( currentConditionMask, TRIANGLE_MASK ) ) {
+ if ( this.conditionsMatchRequirements( conditions, TRIANGLE ) ) {
quadrilateralName = NamedQuadrilateral.TRIANGLE;
}
- else if ( this.conditionMatchesMask( currentConditionMask, CONCAVE_MASK ) ) {
+ else if ( this.conditionsMatchRequirements( conditions, CONCAVE_REQUIREMENTS ) ) {
// if concave, the only attribute that can "build-up" from here is the dart property
quadrilateralName = NamedQuadrilateral.CONCAVE_QUADRILATERAL;
- if ( this.conditionMatchesMask( currentConditionMask, DART_MASK ) ) {
+ if ( this.conditionsMatchRequirements( conditions, DART ) ) {
quadrilateralName = NamedQuadrilateral.DART;
}
}
@@ -178,25 +192,25 @@
// most general case, shape properties "build-up" from a convex quadrilateral
quadrilateralName = NamedQuadrilateral.CONVEX_QUADRILATERAL;
- if ( this.conditionMatchesMask( currentConditionMask, TRAPEZOID_MASK ) ) {
+ if ( this.conditionsMatchRequirements( conditions, TRAPEZOID ) ) {
quadrilateralName = NamedQuadrilateral.TRAPEZOID;
}
- if ( this.conditionMatchesMask( currentConditionMask, ISOSCELES_TRAPEZOID_MASK ) ) {
+ if ( this.conditionsMatchRequirements( conditions, ISOSCELES_TRAPEZOID ) ) {
quadrilateralName = NamedQuadrilateral.ISOSCELES_TRAPEZOID;
}
- if ( this.conditionMatchesMask( currentConditionMask, KITE_MASK ) ) {
+ if ( this.conditionsMatchRequirements( conditions, KITE ) ) {
quadrilateralName = NamedQuadrilateral.KITE;
}
- if ( this.conditionMatchesMask( currentConditionMask, PARALLELOGRAM_MASK ) ) {
+ if ( this.conditionsMatchRequirements( conditions, PARALLELOGRAM ) ) {
quadrilateralName = NamedQuadrilateral.PARALLELOGRAM;
}
- if ( this.conditionMatchesMask( currentConditionMask, RECTANGLE_MASK ) ) {
+ if ( this.conditionsMatchRequirements( conditions, RECTANGLE ) ) {
quadrilateralName = NamedQuadrilateral.RECTANGLE;
}
- if ( this.conditionMatchesMask( currentConditionMask, RHOMBUS_MASK ) ) {
+ if ( this.conditionsMatchRequirements( conditions, RHOMBUS ) ) {
quadrilateralName = NamedQuadrilateral.RHOMBUS;
}
- if ( this.conditionMatchesMask( currentConditionMask, SQUARE_MASK ) ) {
+ if ( this.conditionsMatchRequirements( conditions, SQUARE ) ) {
quadrilateralName = NamedQuadrilateral.SQUARE;
}
}
@@ -206,18 +220,15 @@
/**
* Returns true when the condition state matches the conditions of the provided mask. Consider two values
- * 10110 (mask)
- * 11110 (condition)
*
- * The & operation returns 10110 (the original mask) if the condition has at least the bits of the mask. This is
- * useful because each mask lists out the requirements for a particular shape. If the condition has at least those
+ * Each mask lists out the requirements for a particular shape. If the condition has at least those
* requirements (or more) it will still be considered a match for that shape.
*
- * @param condition - bits representing the current shape conditions
- * @param mask - bits representing the requirements for a particular shape
+ * @param condition - current shape conditions
+ * @param requirements - requirements for a particular shape
*/
- private conditionMatchesMask( condition: number, mask: number ): boolean {
- return ( condition & mask ) === mask;
+ private conditionsMatchRequirements( conditions: string[], requirements: string[] ): boolean {
+ return requirements.every( maskElement => conditions.includes( maskElement ) );
}
}
|
…, so it makes sense to use set - responding to review comment in #398
…, so it makes sense to use set - responding to review comment in #398
…recommended by review, see #398
… recommended by review, see #398
…ngs and doesn't seem to work well for nested model components, see #398
OK, I hit every review comment and the side issues that came out of this one. Thank you so much for the review @samreid and @matthew-blackman. All recommendations were great improvements for the code and I went with almost all of them. The following two are the only exceptions. Feel free to give thoughts asynchronously, or we could briefly meet to discuss these and the larger changes in side issues.
I reivewed the components in QuadrilateralScreenView (where the model is distributed to view subcomponents) and decided not to do this. It didn't seem to improve readability too much. I didn't see a good way for The other two issues you may want to re-sign off on: |
The comments above seem good, thanks! Closing. |
Today @jessegreenberg met with me and @matthew-blackman to kick off the code review.
Checklist:
To begin a code review:
dev:code-review
.PhET Code-Review Checklist (a.k.a "CRC")
// REVIEW
comments in the codeSpecific Instructions
Provide specific instructions here. For example: known problems that will fail CRC items, files that can be skipped, code that is not completed, shared or common code that also needs to be reviewed,... If there are no specific instructions, then delete this section.
GitHub Issues
The following standard GitHub issues should exist. If these issues are missing, or have not been completed, pause code review until the issues have been created and addressed by the responsible dev.
brands=phet
, see {{GITHUB_ISSUE_LINK}}brands=phet-io
(if the sim is instrumented for PhET-iO), see {{GITHUB_ISSUE_LINK}}Build and Run Checks
If any of these items fail, pause code review.
ea
)fuzz&ea
)ea&shuffleListeners
andea&shuffleListeners&fuzz
)?deprecationWarnings
. Do not use deprecated methods in new code.Memory Leaks
grunt --minify.mangle=false
. Compare to testing results done by the responsible developer. Results can be found in {{GITHUB_ISSUE_LINK}}.there a call to that component’s
dispose
function, or is it obvious why it isn't necessary, or is there documentationabout why
dispose
isn't called? An example of why no call todispose
is needed is if the component is used ina
ScreenView
that would never be removed from the scene graph. Note that it's also acceptable (and encouraged!) to describe what needs to be disposed in implementation-notes.md.Property.link
orlazyLink
is accompanied byunlink
.Multilink.multilink
is accompanied byunmultilink
.Multilink
is accompanied bydispose
.DerivedProperty
is accompanied bydispose
.Emitter.addListener
is accompanied byremoveListener
.ObservableArrayDef.element*Emitter.addListener
is accompanied byObservableArrayDef.element*Emitter.removeListener
Node.addInputListener
is accompanied byremoveInputListener
PhetioObject
is accompanied bydispose
.dispose
function have one? This should expose a publicdispose
function that callsthis.disposeMyType()
, wheredisposeMyType
is a private function declared in the constructor.MyType
should exactly match the filename.Performance
webgl=false
)Usability
showPointerAreas
)showPointerAreas
) Overlap may be OK in some cases, depending on the z-ordering (if the front-most object is supposed to occlude pointer areas) and whether objects can be moved.Internationalization
Are there any strings that are not internationalized, and does the sim layout gracefully handle internationalized strings that are shorter than the English strings? (run with query parameter
stringTest=X
. You should see nothing but 'X' strings.)Does the sim layout gracefully handle internationalized strings that are longer than the English strings? (run with query parameters
stringTest=double
andstringTest=long
)Does the sim stay on the sim page (doesn't redirect to an external page) when running with the query parameter
stringTest=xss
? This test passes if sim does not redirect, OK if sim crashes or fails to fully start. Only test on onedesktop platform. For PhET-iO sims, additionally test
?stringTest=xss
in Studio to make sure i18n strings didn't leakto phetioDocumentation, see https://github.com/phetsims/phet-io/issues/1377
Avoid using concatenation to create strings that will be visible in the user interface. Use
StringUtils.fillIn
and a string pattern to ensure that strings are properly localized.Use named placeholders (e.g.
"{{value}} {{units}}"
) instead of numbered placeholders (e.g."{0} {1}"
).Make sure the string keys are all perfect, because they are difficult to change after 1.0.0 is published. Guidelines for string keys are:
(1) Strings keys should generally match their values. E.g.:
(2) If a string key would be exceptionally long, use a key name that is an abbreviated form of the string value, or that captures the purpose/essence of the value. E.g.:
(3) If string key names would collide, use your judgment to disambiguate. E.g.:
(4) String keys for screen names should have the general form
"screen.{{screenName}}"
. E.g.:(5) String patterns that contain placeholders (e.g.
"My name is {{first}} {{last}}"
) should use keys that are unlikely to conflict with strings that might be needed in the future. For example, for"{{price}}"
consider using key"pricePattern"
instead of"price"
, if you think there might be a future need for a"price"
string.(6) It is acceptable to prefix families of strings with a prefix, like so:
Nested substructure is not yet fully supported.
Repository Structure
The repository name should correspond to the sim title. For example, if the sim title is "Wave Interference", then the repository name should be "wave-interference".
Are all required files and directories present?
For a sim repository named “my-repo”, the general structure should look like this (where assets/, images/, mipmaps/ or sounds/ may be omitted if the sim doesn’t have those types of resource files).
*Any images used in model.md or implementation-notes.md should be added here. Images specific to aiding with documentation do not need their own license.
Verify that the same image file is not present in both images/ and mipmaps/. If you need a mipmap, use it for all occurrences of the image.
Is the js/ directory properly structured?
All JavaScript source should be in the js/ directory. There should be a subdirectory for each screen (this also applies for single-screen sims, where the subdirectory matches the repo name). For a multi-screen sim, code shared by 2 or more screens should be in a js/common/ subdirectory. Model and view code should be in model/ and view/ subdirectories for each screen and common/. For example, for a sim with screens “Introduction” and “Lab”, the general directory structure should look like this:
Do filenames use an appropriate prefix? Some filenames may be prefixed with the repository name,
e.g.
MolarityConstants.js
in molarity. If the repository name is long, the developer may choose to abbreviate therepository name, e.g.
EEConstants.js
in expression-exchange. If the abbreviation is already used by anotherrepository, then the full name must be used. For example, if the "EE" abbreviation is already used by
expression-exchange, then it should not be used in equality-explorer. Whichever convention is used, it should be used
consistently within a repository - don't mix abbreviations and full names.
Is there a file in assets/ for every resource file in sound/ and images/? Note that there is not necessarily a
1:1 correspondence between asset and resource files; for example, several related images may be in the same .ai file.
Check license.json for possible documentation of why some resources might not have a corresponding asset file.
For simulations, was the README.md generated by
grunt published-README
orgrunt unpublished-README
? Commoncode repos can have custom README files.
Does package.json refer to any dependencies that are not used by the sim?
Is the LICENSE file correct? (Generally GPL v3 for sims and MIT for common code,
see this thread for additional information).
Does .gitignore match the one in simula-rasa?
In GitHub, verify that all non-release branches have an associated issue that describes their purpose.
Are there any GitHub branches that are no longer needed and should be deleted?
Sim-specific query parameters (if any) should be identified and documented in one .js file in js/common/ or js/ (
if there is no common/). The .js file should be named
{{PREFIX}}QueryParameters.js
, for exampleArithmeticQueryParameters.js for the arithmetic repository, or FBQueryParameters.js for Function Builder (where
the
FB
prefix is used).Query parameters that are public-facing should be identified using
public: true
in the schema.All sims should use a color file named
MyRepoColors.js
or, if using abbreviations,MRColors.js
, anduse
ProfileColorProperty
where appropriate, even if they have a single (default) profile (to support color editingand PhET-iO Studio). The
ColorProfile
pattern was converted to*Colors.js
files inPhET-iO instrumentation for ColorProfile scenery-phet#515. Please see
GasPropertiesColors.js
for a good example.
Coding Conventions
deals with PhET coding conventions. You do not need to exhaustively check every item in this section, nor do you
necessarily need to check these items one at a time. The goal is to determine whether the code generally meets PhET standards.
TypeScript Conventions
Math Libraries
DOT/Utils.toFixed
orDOT/Utils.toFixedNumber
should be used instead oftoFixed
. JavaScript'stoFixed
is notoriously buggy. Behavior differs depending on browser, because the spec doesn't specify whether to round or floor.IE11
string.includes
andstring.startsWith
where possible.Organization, Readability, and Maintainability
TODO
orFIXME
orREVIEW
comments in the code? They should be addressed or promoted to GitHub issues.{{REPO}}Constants.js
file?PhetColorScheme
. Identify any colors that might be worth adding toPhetColorScheme
.DerivedProperty
instead ofProperty
?Accessibility
This section may be omitted if the sim has not been instrumented with accessibility features. Accessibility includes
various features, not all are always include. Ignore sections that do not apply.
General
Alternative Input
fuzzBoard&ea
)Interactive Description
Node.pdomOrder
used appropriately to maintain visual and PDOM layout balance?toUpperCase()
. Remember that one day these strings will be translatablePhET-iO
This section may be omitted if the sim has not been instrumented for PhET-iO, but is likely good to glance at no matter.
This could be an extensive bullet. At the very least, be sure to know what amount of instrumentation this sim
supports. Describing this further goes beyond the scope of this document.
It needs to be tested separately for memory leaks. To help isolate the nature of the memory leak, this test should
be run separately from the PhET brand memory leak test. Test with a colorized Data Stream, and Studio (easily
accessed from phetmarks). Compare to testing results done by the responsible developer and previous releases.
PhetioObject
instances are disposed, which unregisters their tandems.dt
values are used instead ofDate.now()
or other Date functions. Perhaps tryphet.joist.elapsedTime
. Though this has already been mentioned, it is necessary for reproducible playback via inputevents and deserves a comment in this PhET-iO section.
DOT/dotRandom
as an imported module (not a global), and all doing so after modules are declared (non-statically)? Forexample, the following methods (and perhaps others) should not be used:
Math.random
,_.shuffle
,_.sample
,_.random
.This also deserves re-iteration due to its effect on record/playback for PhET-iO.
undefined
values are omitted when serializing objects across frames. Consider this whendetermining whether
toStateObject
should usenull
orundefined
values.brands, but is more important for the PhET-iO API. See location vs position phet-info#126
AXON/EnabledProperty
. Thisshould be done in both the model and the view. If you're using a DerivedProperty, skip this item.
phetioDocumentaton
- it changes the PhET-iO API!The text was updated successfully, but these errors were encountered: