Skip to content

Commit

Permalink
Support array or element, and update REVIEW comments for query parame…
Browse files Browse the repository at this point in the history
…ters, see #398
  • Loading branch information
samreid committed Mar 3, 2023
1 parent 877f658 commit c0af6b5
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 21 deletions.
3 changes: 1 addition & 2 deletions js/quadrilateral/QuadrilateralQueryParameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import quadrilateral from '../quadrilateral.js';
import { SoundDesign } from './model/QuadrilateralSoundOptionsModel.js';

// REVIEW: Which of these should be marked as public?
const QuadrilateralQueryParameters = QueryStringMachine.getAll( {

// The tolerance interval for the angle calculations which determine when sides opposite sides are parallel.
Expand Down Expand Up @@ -118,8 +119,6 @@ const QuadrilateralQueryParameters = QueryStringMachine.getAll( {
// QuadrilateralSoundOptionsModel.SoundDesign as a string. See https://github.com/phetsims/quadrilateral/blob/master/js/quadrilateral/model/QuadrilateralSoundOptionsModel.ts#L37-L53
soundDesign: {
type: 'string',

// REVIEW: This value doesn't seem to be cased like other query parameter values
defaultValue: 'TRACKS_LAYER',
validValues: SoundDesign.enumeration.keys
},
Expand Down
34 changes: 18 additions & 16 deletions js/quadrilateral/model/QuadrilateralShapeModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,13 @@ export default class QuadrilateralShapeModel {
public readonly adjacentVertexMap: Map<QuadrilateralVertex, QuadrilateralVertex[]>;

// A map that provides the opposite vertex from a give vertex.
public readonly oppositeVertexMap: Map<QuadrilateralVertex, QuadrilateralVertex[]>;
public readonly oppositeVertexMap: Map<QuadrilateralVertex, QuadrilateralVertex>;

// A map that provides the adjacent sides to the provided QuadrilateralSide.
public readonly adjacentSideMap: Map<QuadrilateralSide, QuadrilateralSide[]>;

// A map that provides the opposite side from the provided QuadrilateralSide.
public readonly oppositeSideMap: Map<QuadrilateralSide, QuadrilateralSide[]>;
public readonly oppositeSideMap: Map<QuadrilateralSide, QuadrilateralSide>;

// An array of all the adjacent VertexPairs that currently have equal angles.
public readonly adjacentEqualVertexPairsProperty: Property<VertexPair[]>;
Expand Down Expand Up @@ -162,12 +162,10 @@ export default class QuadrilateralShapeModel {
this.vertices = [ this.vertexA, this.vertexB, this.vertexC, this.vertexD ];

this.oppositeVertexMap = new Map( [

// REVIEW: Should the values be arrays? It looks like they are always accessed with [0].
[ this.vertexA, [ this.vertexC ] ],
[ this.vertexB, [ this.vertexD ] ],
[ this.vertexC, [ this.vertexA ] ],
[ this.vertexD, [ this.vertexB ] ]
[ this.vertexA, this.vertexC ],
[ this.vertexB, this.vertexD ],
[ this.vertexC, this.vertexA ],
[ this.vertexD, this.vertexB ]
] );

this.adjacentVertexMap = new Map( [
Expand All @@ -184,10 +182,10 @@ export default class QuadrilateralShapeModel {
this.sides = [ this.sideAB, this.sideBC, this.sideCD, this.sideDA ];

this.oppositeSideMap = new Map( [
[ this.sideAB, [ this.sideCD ] ],
[ this.sideBC, [ this.sideDA ] ],
[ this.sideCD, [ this.sideAB ] ],
[ this.sideDA, [ this.sideBC ] ]
[ this.sideAB, this.sideCD ],
[ this.sideBC, this.sideDA ],
[ this.sideCD, this.sideAB ],
[ this.sideDA, this.sideBC ]
] );

this.adjacentSideMap = new Map( [
Expand Down Expand Up @@ -512,10 +510,12 @@ export default class QuadrilateralShapeModel {
/**
* Update a provided Property that holds a list of equal angles (either opposite or adjacent).
*/
private updateEqualVertexPairs( equalVertexPairsProperty: Property<VertexPair[]>, vertexMap: Map<QuadrilateralVertex, QuadrilateralVertex[]> ): void {
private updateEqualVertexPairs( equalVertexPairsProperty: Property<VertexPair[]>, vertexMap: Map<QuadrilateralVertex, QuadrilateralVertex[] | QuadrilateralVertex> ): void {
const currentVertexPairs = equalVertexPairsProperty.value;
vertexMap.forEach( ( relatedVertices, keyVertex, map ) => {
relatedVertices.forEach( relatedVertex => {

const relatedVerticesArray = Array.isArray( relatedVertices ) ? relatedVertices : [ relatedVertices ];
relatedVerticesArray.forEach( relatedVertex => {
const vertexPair = new VertexPair( keyVertex, relatedVertex );

const firstAngle = vertexPair.vertex1.angleProperty.value!;
Expand Down Expand Up @@ -551,11 +551,13 @@ export default class QuadrilateralShapeModel {
/**
* Update a provided Property holding a list of sides that are equal in length (either opposite or adjacent).
*/
private updateEqualSidePairs( equalSidePairsProperty: Property<SidePair[]>, sideMap: Map<QuadrilateralSide, QuadrilateralSide[]> ): void {
private updateEqualSidePairs( equalSidePairsProperty: Property<SidePair[]>, sideMap: Map<QuadrilateralSide, QuadrilateralSide[] | QuadrilateralSide> ): void {
const currentSidePairs = equalSidePairsProperty.value;

sideMap.forEach( ( relatedSides, keySide ) => {
relatedSides.forEach( relatedSide => {

const relatedSidesArray = Array.isArray( relatedSides ) ? relatedSides : [ relatedSides ];
relatedSidesArray.forEach( relatedSide => {
const sidePair = new SidePair( keySide, relatedSide );

const firstLength = sidePair.side1.lengthProperty.value;
Expand Down
2 changes: 1 addition & 1 deletion js/quadrilateral/view/QuadrilateralAlerter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ export default class QuadrilateralAlerter extends Alerter {
const currentAngle = vertex.angleProperty.value!;
const previousAngle = this.previousObjectResponseShapeSnapshot.getAngleFromVertexLabel( vertex.vertexLabel );

const oppositeVertex = shapeModel.oppositeVertexMap.get( vertex )![ 0 ];
const oppositeVertex = shapeModel.oppositeVertexMap.get( vertex )!;
const oppositeVertexAngle = oppositeVertex.angleProperty.value!;

const adjacentVertices = shapeModel.adjacentVertexMap.get( vertex )!;
Expand Down
2 changes: 1 addition & 1 deletion js/quadrilateral/view/SideDescriber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export default class SideDescriber {
*/
public getSideObjectResponse(): string {
let response = '';
const oppositeSide = this.quadrilateralShapeModel.oppositeSideMap.get( this.side )![ 0 ];
const oppositeSide = this.quadrilateralShapeModel.oppositeSideMap.get( this.side )!;

const parallelSidePairs = this.quadrilateralShapeModel.parallelSidePairsProperty.value;
const thisSideIsParallel = _.some( parallelSidePairs, sidePair => sidePair.side1 === this.side || sidePair.side2 === this.side );
Expand Down
2 changes: 1 addition & 1 deletion js/quadrilateral/view/VertexDescriber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export default class VertexDescriber {
public getVertexObjectResponse(): string {
let response = '';

const oppositeVertex = this.quadrilateralShapeModel.oppositeVertexMap.get( this.vertex )![ 0 ];
const oppositeVertex = this.quadrilateralShapeModel.oppositeVertexMap.get( this.vertex )!;

const shapeName = this.quadrilateralShapeModel.shapeNameProperty.value;
const oppositeComparisonString = this.getAngleComparisonDescription( oppositeVertex, shapeName );
Expand Down

0 comments on commit c0af6b5

Please sign in to comment.