Closed samreid closed 1 year ago
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:
export default
inline? Like https://github.com/phetsims/balancing-chemical-equations/blob/f78783eeb2f32bf1572f7aed1dcab3b376912252/js/common/model/AtomCount.ts#L18. @jessegreenberg agreed this is a good idea and @samreid will implement it.Tandem
but phet-io
is not listed as a supported brand. How would you characterize the phet-io coverage? Is phet-io publication planned in the near future? @jessegreenberg says PhET-iO was added early on for some prototyping, but it is not thorough and not planned for production in the foreseeable future.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.
tangibleControlsTitle
in case it one day becomes i18nized? It's in the prototype realm though, so may not be on the road to i18n.EnumerationValue
. This sim uses 5 EnumerationValue vs 1 string literal union (ResponseReason
). Is that where we want to be for long-term maintainability? @jessegreenberg and I agreed this sim will continue to mostly use EnumerationValueleftConstrainedProperty
etc are initialized at the declaration site, we could do that for numberOfConstrainingEdgesProperty
as well. (But if those ever get phet-io tandems, they probably would all have to move into the constructor). CONSENSUS: Yes, we prefer initialization at declaration site.
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;
lowPriorityUtterance
created in advance and re-used instead of on-demand and single-use? ~ @jessegreenberg says: A single instance of an utterance is reused to leverage the utterance queue feature of collapsing the utterances so only the most recent one (added to the back last) from that priority level is spoken.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:
Code review complete. Nice work! The code was well organized and well documented when we got here, and we made several recommendations about how to make it even better. All review comments and side issues have been discussed with @jessegreenberg.
Excellent, thank you very much @samreid and @matthew-blackman! I will continue to make commits related to review comments against this issue and leave open for any further review or discussion. Ill close this one when all wrapped up.
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.
// REVIEW: In fuzzing, I saw this value go greater than Math.PI*2. // REVIEW: Can the angle be computed with: const a = vector1.angleBetween( vector2 );
Vector2.angleBetween
returns a value between 0 and PI, we need a value from 0-2PI in this sim to support concave quadrilaterals. I fuzzed the sim for 5 minutes or so and never saw an angle above Math.PI * 2. I added a line of doc about why there is a custom angle calculation and then decided not to go farther.
// REVIEW: In this case and others like it, we are plucking several attributes from the model, (potentially) renaming them // and passing them through. This makes it difficult to trace back to the source. // An alternative is to pass the entire model through, and use TypeScript to narrow what is accessible // Note the visibilityModel is also part of the model.
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 Pick
to expose fields on model subcomponents. For example, although visibilityModel
is part of the model, I don't want the QuadrilateralDiagonalGuidesNode
to take the whole model.visibilityModel
, I want it to take just the model.visibilityModel.diagonalGuidesVisibleProperty
.
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: