@doenet/doenetml 0.6.0-alpha1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.prettierrc +3 -0
- package/LICENSE +661 -0
- package/README.md +146 -0
- package/cypress/e2e/ActivityViewer/activityVariants.cy.js +1770 -0
- package/cypress/e2e/ActivityViewer/compiledActivity.cy.js +83 -0
- package/cypress/e2e/ActivityViewer/relationshipsAmongPages.cy.js +697 -0
- package/cypress/e2e/answerValidation/errorinnumbers.cy.js +2125 -0
- package/cypress/e2e/answerValidation/factoring.cy.js +1945 -0
- package/cypress/e2e/answerValidation/factoringOldAlgorithm.cy.js +892 -0
- package/cypress/e2e/answerValidation/functionanswers.cy.js +314 -0
- package/cypress/e2e/answerValidation/matchingpatterns.cy.js +287 -0
- package/cypress/e2e/answerValidation/matchpartial.cy.js +6711 -0
- package/cypress/e2e/answerValidation/pointlocation.cy.js +3989 -0
- package/cypress/e2e/answerValidation/symbolicequality.cy.js +1893 -0
- package/cypress/e2e/answerValidation/videoProgress.cy.js +210 -0
- package/cypress/e2e/assignNames/basiccopy.cy.js +2376 -0
- package/cypress/e2e/assignNames/collections.cy.js +9247 -0
- package/cypress/e2e/assignNames/selects.cy.js +105 -0
- package/cypress/e2e/assignNames/sequences.cy.js +1964 -0
- package/cypress/e2e/baseComponent/basecomponentproperties.cy.js +999 -0
- package/cypress/e2e/baseComponent/doenetMLtext.cy.js +427 -0
- package/cypress/e2e/chemistry/atom.cy.js +201 -0
- package/cypress/e2e/chemistry/ion.cy.js +608 -0
- package/cypress/e2e/chemistry/ioniccompound.cy.js +133 -0
- package/cypress/e2e/dynamicalsystem/cobwebpolyline.cy.js +2653 -0
- package/cypress/e2e/dynamicalsystem/equilibriumcurve.cy.js +311 -0
- package/cypress/e2e/dynamicalsystem/equilibriumline.cy.js +279 -0
- package/cypress/e2e/dynamicalsystem/equilibriumpoint.cy.js +283 -0
- package/cypress/e2e/dynamicalsystem/odesystem.cy.js +1834 -0
- package/cypress/e2e/equality/mathexpressions.cy.js +948 -0
- package/cypress/e2e/graphing/graphreferences.cy.js +978 -0
- package/cypress/e2e/graphing/graphreferences2.cy.js +615 -0
- package/cypress/e2e/linearAlgebra/eigenDecomposition.cy.js +401 -0
- package/cypress/e2e/tagSpecific/angle.cy.js +3898 -0
- package/cypress/e2e/tagSpecific/animatefromsequence.cy.js +2306 -0
- package/cypress/e2e/tagSpecific/answer.cy.js +31647 -0
- package/cypress/e2e/tagSpecific/bestfitline.cy.js +612 -0
- package/cypress/e2e/tagSpecific/blockquote.cy.js +30 -0
- package/cypress/e2e/tagSpecific/boolean.cy.js +742 -0
- package/cypress/e2e/tagSpecific/booleaninput.cy.js +1283 -0
- package/cypress/e2e/tagSpecific/booleanlist.cy.js +588 -0
- package/cypress/e2e/tagSpecific/booleanoperators.cy.js +596 -0
- package/cypress/e2e/tagSpecific/booleanoperatorsonmath.cy.js +498 -0
- package/cypress/e2e/tagSpecific/callaction.cy.js +2835 -0
- package/cypress/e2e/tagSpecific/choiceinput.cy.js +3205 -0
- package/cypress/e2e/tagSpecific/circle.cy.js +22036 -0
- package/cypress/e2e/tagSpecific/codeeditor.cy.js +1995 -0
- package/cypress/e2e/tagSpecific/collect.cy.js +5035 -0
- package/cypress/e2e/tagSpecific/componentsize.cy.js +502 -0
- package/cypress/e2e/tagSpecific/conditionalcontent.cy.js +3495 -0
- package/cypress/e2e/tagSpecific/contentBrowser.cy.js +335 -0
- package/cypress/e2e/tagSpecific/contentpicker.cy.js +261 -0
- package/cypress/e2e/tagSpecific/copy.cy.js +12627 -0
- package/cypress/e2e/tagSpecific/copy2.cy.js +5698 -0
- package/cypress/e2e/tagSpecific/curve.bezier.cy.js +12440 -0
- package/cypress/e2e/tagSpecific/curve.cy.js +1716 -0
- package/cypress/e2e/tagSpecific/curve.function.cy.js +1471 -0
- package/cypress/e2e/tagSpecific/curve.parametrized.cy.js +920 -0
- package/cypress/e2e/tagSpecific/document.cy.js +234 -0
- package/cypress/e2e/tagSpecific/endpoint.cy.js +197 -0
- package/cypress/e2e/tagSpecific/evaluate.cy.js +8895 -0
- package/cypress/e2e/tagSpecific/extract.cy.js +2282 -0
- package/cypress/e2e/tagSpecific/feedback.cy.js +2941 -0
- package/cypress/e2e/tagSpecific/function.cy.js +9450 -0
- package/cypress/e2e/tagSpecific/functioniterates.cy.js +1178 -0
- package/cypress/e2e/tagSpecific/functionoperators.cy.js +4047 -0
- package/cypress/e2e/tagSpecific/graph.cy.js +2491 -0
- package/cypress/e2e/tagSpecific/group.cy.js +683 -0
- package/cypress/e2e/tagSpecific/hint.cy.js +204 -0
- package/cypress/e2e/tagSpecific/image.cy.js +770 -0
- package/cypress/e2e/tagSpecific/integer.cy.js +206 -0
- package/cypress/e2e/tagSpecific/label.cy.js +800 -0
- package/cypress/e2e/tagSpecific/legend.cy.js +1001 -0
- package/cypress/e2e/tagSpecific/line.cy.js +12167 -0
- package/cypress/e2e/tagSpecific/linesegment.cy.js +4749 -0
- package/cypress/e2e/tagSpecific/lorem.cy.js +289 -0
- package/cypress/e2e/tagSpecific/map.cy.js +4476 -0
- package/cypress/e2e/tagSpecific/matchespattern.cy.js +693 -0
- package/cypress/e2e/tagSpecific/math.cy.js +10990 -0
- package/cypress/e2e/tagSpecific/mathdisplay.cy.js +2689 -0
- package/cypress/e2e/tagSpecific/mathinput.cy.js +15628 -0
- package/cypress/e2e/tagSpecific/mathinputgraph.cy.js +566 -0
- package/cypress/e2e/tagSpecific/mathlist.cy.js +4073 -0
- package/cypress/e2e/tagSpecific/mathoperators.cy.js +13851 -0
- package/cypress/e2e/tagSpecific/matrix.cy.js +8825 -0
- package/cypress/e2e/tagSpecific/matrixinput.cy.js +16277 -0
- package/cypress/e2e/tagSpecific/module.cy.js +1771 -0
- package/cypress/e2e/tagSpecific/number.cy.js +2221 -0
- package/cypress/e2e/tagSpecific/numberlist.cy.js +1285 -0
- package/cypress/e2e/tagSpecific/p.cy.js +72 -0
- package/cypress/e2e/tagSpecific/paginator.cy.js +2983 -0
- package/cypress/e2e/tagSpecific/parabola.cy.js +14331 -0
- package/cypress/e2e/tagSpecific/paragraphmarkup.cy.js +104 -0
- package/cypress/e2e/tagSpecific/periodicset.cy.js +1439 -0
- package/cypress/e2e/tagSpecific/piecewisefunction.cy.js +1055 -0
- package/cypress/e2e/tagSpecific/pluralize.cy.js +274 -0
- package/cypress/e2e/tagSpecific/point.cy.js +8895 -0
- package/cypress/e2e/tagSpecific/point2.cy.js +10259 -0
- package/cypress/e2e/tagSpecific/polygon.cy.js +5039 -0
- package/cypress/e2e/tagSpecific/polyline.cy.js +4704 -0
- package/cypress/e2e/tagSpecific/problem.cy.js +2768 -0
- package/cypress/e2e/tagSpecific/ray.cy.js +10770 -0
- package/cypress/e2e/tagSpecific/rectangle.cy.js +2143 -0
- package/cypress/e2e/tagSpecific/ref.cy.js +420 -0
- package/cypress/e2e/tagSpecific/regularPolygon.cy.js +1006 -0
- package/cypress/e2e/tagSpecific/regularPolygon2.cy.js +100 -0
- package/cypress/e2e/tagSpecific/regularPolygon3.cy.js +777 -0
- package/cypress/e2e/tagSpecific/samplerandomnumbers.cy.js +3619 -0
- package/cypress/e2e/tagSpecific/sectioning.cy.js +3530 -0
- package/cypress/e2e/tagSpecific/select.cy.js +5376 -0
- package/cypress/e2e/tagSpecific/selectfromsequence.cy.js +3846 -0
- package/cypress/e2e/tagSpecific/selectrandomnumbers.cy.js +2914 -0
- package/cypress/e2e/tagSpecific/sequence.cy.js +2093 -0
- package/cypress/e2e/tagSpecific/shuffle.cy.js +490 -0
- package/cypress/e2e/tagSpecific/sidebyside.cy.js +8057 -0
- package/cypress/e2e/tagSpecific/singlecharactercomponents.cy.js +72 -0
- package/cypress/e2e/tagSpecific/slider.cy.js +914 -0
- package/cypress/e2e/tagSpecific/solution.cy.js +109 -0
- package/cypress/e2e/tagSpecific/solveequations.cy.js +1026 -0
- package/cypress/e2e/tagSpecific/sort.cy.js +1685 -0
- package/cypress/e2e/tagSpecific/spreadsheet.cy.js +5971 -0
- package/cypress/e2e/tagSpecific/subsetofreals.cy.js +2725 -0
- package/cypress/e2e/tagSpecific/substitute.cy.js +2646 -0
- package/cypress/e2e/tagSpecific/tabular.cy.js +36 -0
- package/cypress/e2e/tagSpecific/text.cy.js +975 -0
- package/cypress/e2e/tagSpecific/textinput.cy.js +2177 -0
- package/cypress/e2e/tagSpecific/textlist.cy.js +369 -0
- package/cypress/e2e/tagSpecific/triangle.cy.js +1936 -0
- package/cypress/e2e/tagSpecific/triggerset.cy.js +2023 -0
- package/cypress/e2e/tagSpecific/updatevalue.cy.js +3288 -0
- package/cypress/e2e/tagSpecific/vector.cy.js +20183 -0
- package/cypress/e2e/tagSpecific/video.cy.js +612 -0
- package/cypress/e2e/tagSpecific/when.cy.js +202 -0
- package/cypress/e2e/variants/specifysinglevariant.cy.js +6726 -0
- package/cypress/e2e/variants/uniquevariants.cy.js +4846 -0
- package/cypress/fixtures/example.json +5 -0
- package/cypress/support/commands.js +32 -0
- package/cypress/support/e2e.js +31 -0
- package/cypress.config.js +18 -0
- package/docs/codeSnippet.jsx +11 -0
- package/docs/index.html +133 -0
- package/docs/index.jsx +138 -0
- package/docs/prism.css +3 -0
- package/index.html +14 -0
- package/index.js +21 -0
- package/media/answer_example.png +0 -0
- package/media/graph_example.png +0 -0
- package/media/graph_markup_example.png +0 -0
- package/package.json +83 -0
- package/public/favicon.ico +0 -0
- package/public/fonts/files/open-sans-v18-latin-700.woff +0 -0
- package/public/fonts/files/open-sans-v18-latin-700.woff2 +0 -0
- package/public/fonts/files/open-sans-v18-latin-700italic.woff +0 -0
- package/public/fonts/files/open-sans-v18-latin-700italic.woff2 +0 -0
- package/public/fonts/files/open-sans-v18-latin-italic.woff +0 -0
- package/public/fonts/files/open-sans-v18-latin-italic.woff2 +0 -0
- package/public/fonts/files/open-sans-v18-latin-light-italic.woff +0 -0
- package/public/fonts/files/open-sans-v18-latin-light-italic.woff2 +0 -0
- package/public/fonts/files/open-sans-v18-latin-light.woff +0 -0
- package/public/fonts/files/open-sans-v18-latin-light.woff2 +0 -0
- package/public/fonts/files/open-sans-v18-latin-regular.woff +0 -0
- package/public/fonts/files/open-sans-v18-latin-regular.woff2 +0 -0
- package/src/Core/ComponentTypes.js +426 -0
- package/src/Core/Core.js +11852 -0
- package/src/Core/CoreWorker.js +127 -0
- package/src/Core/Dependencies.js +8226 -0
- package/src/Core/Numerics.js +473 -0
- package/src/Core/ParameterStack.js +36 -0
- package/src/Core/ReadOnlyProxyHandler.js +41 -0
- package/src/Core/StateProxyHandler.js +88 -0
- package/src/Core/components/Aliases.js +67 -0
- package/src/Core/components/Angle.js +758 -0
- package/src/Core/components/AnimateFromSequence.js +922 -0
- package/src/Core/components/Answer.js +2087 -0
- package/src/Core/components/AsList.js +83 -0
- package/src/Core/components/AttractTo.js +245 -0
- package/src/Core/components/AttractToAngles.js +262 -0
- package/src/Core/components/AttractToConstraint.js +104 -0
- package/src/Core/components/AttractToGrid.js +315 -0
- package/src/Core/components/Award.js +906 -0
- package/src/Core/components/BestFitLine.js +318 -0
- package/src/Core/components/BezierControls.js +719 -0
- package/src/Core/components/BlockQuote.js +35 -0
- package/src/Core/components/Boolean.js +500 -0
- package/src/Core/components/BooleanInput.js +330 -0
- package/src/Core/components/BooleanList.js +396 -0
- package/src/Core/components/BooleanOperators.js +35 -0
- package/src/Core/components/BooleanOperatorsOfMath.js +148 -0
- package/src/Core/components/CallAction.js +261 -0
- package/src/Core/components/Caption.js +73 -0
- package/src/Core/components/Case.js +56 -0
- package/src/Core/components/Cell.js +439 -0
- package/src/Core/components/CellBlock.js +64 -0
- package/src/Core/components/Chart.js +795 -0
- package/src/Core/components/Choice.js +266 -0
- package/src/Core/components/ChoiceInput.js +1407 -0
- package/src/Core/components/Circle.js +2884 -0
- package/src/Core/components/CodeEditor.js +647 -0
- package/src/Core/components/CodeViewer.js +294 -0
- package/src/Core/components/CollaborateGroupSetup.js +46 -0
- package/src/Core/components/CollaborateGroups.js +119 -0
- package/src/Core/components/Collect.js +850 -0
- package/src/Core/components/Column.js +608 -0
- package/src/Core/components/ConditionalContent.js +468 -0
- package/src/Core/components/ConsiderAsResponses.js +49 -0
- package/src/Core/components/ConstrainTo.js +161 -0
- package/src/Core/components/ConstrainToAngles.js +244 -0
- package/src/Core/components/ConstrainToGraph.js +142 -0
- package/src/Core/components/ConstrainToGrid.js +175 -0
- package/src/Core/components/ConstraintUnion.js +119 -0
- package/src/Core/components/Constraints.js +497 -0
- package/src/Core/components/ContentBrowser.js +441 -0
- package/src/Core/components/ContentPicker.js +263 -0
- package/src/Core/components/ControlVectors.js +25 -0
- package/src/Core/components/Coords.js +63 -0
- package/src/Core/components/Copy.js +3412 -0
- package/src/Core/components/Curve.js +4130 -0
- package/src/Core/components/CustomAttribute.js +175 -0
- package/src/Core/components/DataFrame.js +357 -0
- package/src/Core/components/DiscreteSimulationResultList.js +342 -0
- package/src/Core/components/DiscreteSimulationResultPolyline.js +581 -0
- package/src/Core/components/Divisions.js +55 -0
- package/src/Core/components/Document.js +888 -0
- package/src/Core/components/Embed.js +65 -0
- package/src/Core/components/Endpoint.js +62 -0
- package/src/Core/components/Evaluate.js +321 -0
- package/src/Core/components/Extract.js +656 -0
- package/src/Core/components/Extrema.js +556 -0
- package/src/Core/components/Feedback.js +200 -0
- package/src/Core/components/FeedbackDefinitions.js +97 -0
- package/src/Core/components/Figure.js +148 -0
- package/src/Core/components/Footnote.js +73 -0
- package/src/Core/components/Function.js +5344 -0
- package/src/Core/components/FunctionIterates.js +306 -0
- package/src/Core/components/FunctionOperators.js +702 -0
- package/src/Core/components/Graph.js +1679 -0
- package/src/Core/components/Group.js +7 -0
- package/src/Core/components/HasSameFactoring.js +407 -0
- package/src/Core/components/Hint.js +241 -0
- package/src/Core/components/Image.js +524 -0
- package/src/Core/components/Indexing.js +79 -0
- package/src/Core/components/IntComma.js +64 -0
- package/src/Core/components/Integer.js +81 -0
- package/src/Core/components/Intersection.js +328 -0
- package/src/Core/components/Interval.js +29 -0
- package/src/Core/components/Label.js +492 -0
- package/src/Core/components/Latex.js +104 -0
- package/src/Core/components/Legend.js +329 -0
- package/src/Core/components/Line.js +2040 -0
- package/src/Core/components/LineSegment.js +882 -0
- package/src/Core/components/Lists.js +180 -0
- package/src/Core/components/Lorem.js +249 -0
- package/src/Core/components/MMeMen.js +377 -0
- package/src/Core/components/Map.js +873 -0
- package/src/Core/components/Markers.js +101 -0
- package/src/Core/components/MatchesPattern.js +339 -0
- package/src/Core/components/Math.js +2552 -0
- package/src/Core/components/MathInput.js +948 -0
- package/src/Core/components/MathList.js +828 -0
- package/src/Core/components/MathOperators.js +1286 -0
- package/src/Core/components/Matrix.js +497 -0
- package/src/Core/components/MatrixInput.js +3157 -0
- package/src/Core/components/MdMdnMrow.js +394 -0
- package/src/Core/components/Module.js +16 -0
- package/src/Core/components/Number.js +1031 -0
- package/src/Core/components/NumberList.js +550 -0
- package/src/Core/components/Option.js +24 -0
- package/src/Core/components/P.js +71 -0
- package/src/Core/components/Paginator.js +338 -0
- package/src/Core/components/Panel.js +126 -0
- package/src/Core/components/Parabola.js +1561 -0
- package/src/Core/components/ParagraphMarkup.js +59 -0
- package/src/Core/components/Pegboard.js +43 -0
- package/src/Core/components/PeriodicSet.js +291 -0
- package/src/Core/components/PiecewiseFunction.js +832 -0
- package/src/Core/components/Pluralize.js +198 -0
- package/src/Core/components/Point.js +1295 -0
- package/src/Core/components/Polygon.js +408 -0
- package/src/Core/components/Polyline.js +841 -0
- package/src/Core/components/RandomizedTextList.js +225 -0
- package/src/Core/components/Ray.js +1737 -0
- package/src/Core/components/Rectangle.js +1535 -0
- package/src/Core/components/Ref.js +350 -0
- package/src/Core/components/RegionBetweenCurveXAxis.js +124 -0
- package/src/Core/components/RegionHalfPlane.js +107 -0
- package/src/Core/components/RegularPolygon.js +2118 -0
- package/src/Core/components/RenderDoenetML.js +181 -0
- package/src/Core/components/Row.js +780 -0
- package/src/Core/components/SampleRandomNumbers.js +653 -0
- package/src/Core/components/Sectioning.js +303 -0
- package/src/Core/components/Select.js +947 -0
- package/src/Core/components/SelectFromSequence.js +1242 -0
- package/src/Core/components/SelectRandomNumbers.js +225 -0
- package/src/Core/components/Sequence.js +444 -0
- package/src/Core/components/Setup.js +53 -0
- package/src/Core/components/Shuffle.js +470 -0
- package/src/Core/components/SideBySide.js +2130 -0
- package/src/Core/components/SingleCharacterComponents.js +41 -0
- package/src/Core/components/Slider.js +819 -0
- package/src/Core/components/SolutionContainer.js +67 -0
- package/src/Core/components/Solutions.js +334 -0
- package/src/Core/components/SolveEquations.js +568 -0
- package/src/Core/components/Sort.js +398 -0
- package/src/Core/components/Sources.js +108 -0
- package/src/Core/components/Split.js +205 -0
- package/src/Core/components/Spreadsheet.js +1507 -0
- package/src/Core/components/StyleDefinitions.js +111 -0
- package/src/Core/components/SubsetOfReals.js +348 -0
- package/src/Core/components/SubsetOfRealsInput.js +1474 -0
- package/src/Core/components/Substitute.js +496 -0
- package/src/Core/components/SummaryStatistics.js +652 -0
- package/src/Core/components/Table.js +145 -0
- package/src/Core/components/Tabular.js +384 -0
- package/src/Core/components/Template.js +360 -0
- package/src/Core/components/Text.js +341 -0
- package/src/Core/components/TextInput.js +566 -0
- package/src/Core/components/TextList.js +442 -0
- package/src/Core/components/TextListFromString.js +137 -0
- package/src/Core/components/TextOperatorsOfMath.js +21 -0
- package/src/Core/components/Triangle.js +280 -0
- package/src/Core/components/TriggerSet.js +189 -0
- package/src/Core/components/TupleList.js +43 -0
- package/src/Core/components/UpdateValue.js +435 -0
- package/src/Core/components/VariantControl.js +36 -0
- package/src/Core/components/Vector.js +2478 -0
- package/src/Core/components/Verbatim.js +125 -0
- package/src/Core/components/Video.js +673 -0
- package/src/Core/components/When.js +198 -0
- package/src/Core/components/abstract/AngleListComponent.js +140 -0
- package/src/Core/components/abstract/BaseComponent.js +1496 -0
- package/src/Core/components/abstract/BlockComponent.js +5 -0
- package/src/Core/components/abstract/BooleanBaseOperator.js +88 -0
- package/src/Core/components/abstract/BooleanBaseOperatorOfMath.js +100 -0
- package/src/Core/components/abstract/BooleanBaseOperatorOneInput.js +44 -0
- package/src/Core/components/abstract/ComponentSize.js +789 -0
- package/src/Core/components/abstract/ComponentWithSelectableType.js +537 -0
- package/src/Core/components/abstract/CompositeComponent.js +142 -0
- package/src/Core/components/abstract/ConstraintComponent.js +19 -0
- package/src/Core/components/abstract/FunctionBaseOperator.js +680 -0
- package/src/Core/components/abstract/GraphicalComponent.js +56 -0
- package/src/Core/components/abstract/InlineComponent.js +5 -0
- package/src/Core/components/abstract/InlineRenderInlineChildren.js +63 -0
- package/src/Core/components/abstract/Input.js +192 -0
- package/src/Core/components/abstract/IntervalListComponent.js +218 -0
- package/src/Core/components/abstract/LineListComponent.js +114 -0
- package/src/Core/components/abstract/MathBaseOperator.js +631 -0
- package/src/Core/components/abstract/MathBaseOperatorOneInput.js +112 -0
- package/src/Core/components/abstract/PointListComponent.js +238 -0
- package/src/Core/components/abstract/SectioningComponent.js +1262 -0
- package/src/Core/components/abstract/SingleCharacterInline.js +23 -0
- package/src/Core/components/abstract/TextBaseOperatorOfMath.js +47 -0
- package/src/Core/components/abstract/TextOrInline.js +66 -0
- package/src/Core/components/abstract/VariableName.js +31 -0
- package/src/Core/components/abstract/VariableNameList.js +83 -0
- package/src/Core/components/abstract/VectorListComponent.js +235 -0
- package/src/Core/components/chemistry/Atom.js +910 -0
- package/src/Core/components/chemistry/ElectronConfiguration.js +36 -0
- package/src/Core/components/chemistry/Ion.js +684 -0
- package/src/Core/components/chemistry/IonicCompound.js +189 -0
- package/src/Core/components/chemistry/OrbitalDiagram.js +175 -0
- package/src/Core/components/chemistry/OrbitalDiagramInput.js +753 -0
- package/src/Core/components/chemistry/index.js +6 -0
- package/src/Core/components/commonsugar/breakstrings.js +627 -0
- package/src/Core/components/commonsugar/lists.js +177 -0
- package/src/Core/components/dynamicalSystems/CobwebPolyline.js +913 -0
- package/src/Core/components/dynamicalSystems/EquilibriumCurve.js +95 -0
- package/src/Core/components/dynamicalSystems/EquilibriumLine.js +93 -0
- package/src/Core/components/dynamicalSystems/EquilibriumPoint.js +93 -0
- package/src/Core/components/dynamicalSystems/ODESystem.js +943 -0
- package/src/Core/components/dynamicalSystems/index.js +5 -0
- package/src/Core/components/linearAlgebra/EigenDecomposition.js +294 -0
- package/src/Core/utils/array.js +30 -0
- package/src/Core/utils/booleanLogic.js +965 -0
- package/src/Core/utils/checkEquality.js +818 -0
- package/src/Core/utils/cid.js +29 -0
- package/src/Core/utils/componentInfoObjects.js +100 -0
- package/src/Core/utils/constraints.js +23 -0
- package/src/Core/utils/copy.js +572 -0
- package/src/Core/utils/deepFunctions.js +173 -0
- package/src/Core/utils/descendants.js +252 -0
- package/src/Core/utils/enumeration.js +234 -0
- package/src/Core/utils/feedback.js +84 -0
- package/src/Core/utils/function.js +1343 -0
- package/src/Core/utils/graphical.js +196 -0
- package/src/Core/utils/label.js +396 -0
- package/src/Core/utils/math.js +1056 -0
- package/src/Core/utils/naming.js +45 -0
- package/src/Core/utils/periodicSetEquality.js +403 -0
- package/src/Core/utils/randomNumbers.js +70 -0
- package/src/Core/utils/retrieveMedia.js +98 -0
- package/src/Core/utils/retrieveTextFile.js +140 -0
- package/src/Core/utils/returnAllPossibleVariants.js +73 -0
- package/src/Core/utils/rounding.js +316 -0
- package/src/Core/utils/sequence.js +754 -0
- package/src/Core/utils/serializedStateProcessing.js +4049 -0
- package/src/Core/utils/size.js +22 -0
- package/src/Core/utils/stateVariables.js +138 -0
- package/src/Core/utils/style.js +535 -0
- package/src/Core/utils/subset-of-reals.js +796 -0
- package/src/Core/utils/table.js +41 -0
- package/src/Core/utils/text.js +16 -0
- package/src/Core/utils/triggering.js +167 -0
- package/src/Core/utils/variants.js +477 -0
- package/src/DoenetML.css +308 -0
- package/src/DoenetML.jsx +201 -0
- package/src/Parser/doenet.grammar +90 -0
- package/src/Parser/doenet.js +33 -0
- package/src/Parser/doenet.terms.js +20 -0
- package/src/Parser/parser.js +266 -0
- package/src/Parser/tokens.js +129 -0
- package/src/Tools/CodeMirror.jsx +440 -0
- package/src/Tools/DarkmodeController.jsx +21 -0
- package/src/Tools/Footers/MathInputSelector.jsx +34 -0
- package/src/Tools/Footers/VirtualKeyboard.jsx +751 -0
- package/src/Tools/cypressTest/CypressTest.jsx +341 -0
- package/src/Tools/cypressTest/index.html +102 -0
- package/src/Tools/cypressTest/index.jsx +40 -0
- package/src/Viewer/ActivityViewer.jsx +1461 -0
- package/src/Viewer/PageViewer.jsx +1329 -0
- package/src/Viewer/renderers/alert.jsx +17 -0
- package/src/Viewer/renderers/angle.jsx +209 -0
- package/src/Viewer/renderers/answer.jsx +206 -0
- package/src/Viewer/renderers/asList.jsx +25 -0
- package/src/Viewer/renderers/blockQuote.jsx +41 -0
- package/src/Viewer/renderers/boolean.jsx +17 -0
- package/src/Viewer/renderers/booleanInput.css +105 -0
- package/src/Viewer/renderers/booleanInput.jsx +636 -0
- package/src/Viewer/renderers/button.jsx +369 -0
- package/src/Viewer/renderers/c.jsx +17 -0
- package/src/Viewer/renderers/callAction.jsx +18 -0
- package/src/Viewer/renderers/cell.jsx +59 -0
- package/src/Viewer/renderers/chart.jsx +83 -0
- package/src/Viewer/renderers/choiceInput.css +223 -0
- package/src/Viewer/renderers/choiceInput.jsx +535 -0
- package/src/Viewer/renderers/circle.jsx +990 -0
- package/src/Viewer/renderers/cobwebPolyline.jsx +442 -0
- package/src/Viewer/renderers/codeEditor.jsx +248 -0
- package/src/Viewer/renderers/codeViewer.jsx +105 -0
- package/src/Viewer/renderers/containerBlock.jsx +41 -0
- package/src/Viewer/renderers/containerInline.jsx +17 -0
- package/src/Viewer/renderers/contentBrowser.jsx +159 -0
- package/src/Viewer/renderers/contentPicker.jsx +160 -0
- package/src/Viewer/renderers/curve.jsx +1072 -0
- package/src/Viewer/renderers/ellipsis.jsx +17 -0
- package/src/Viewer/renderers/em.jsx +17 -0
- package/src/Viewer/renderers/embed.jsx +110 -0
- package/src/Viewer/renderers/feedback.jsx +74 -0
- package/src/Viewer/renderers/figure.jsx +131 -0
- package/src/Viewer/renderers/footnote.jsx +52 -0
- package/src/Viewer/renderers/graph.jsx +925 -0
- package/src/Viewer/renderers/hint.jsx +142 -0
- package/src/Viewer/renderers/image.jsx +581 -0
- package/src/Viewer/renderers/jsxgraph-distrib/jsxgraphcore.mjs +2 -0
- package/src/Viewer/renderers/jsxgraph-distrib/jsxgraphcore.mjs.map +1 -0
- package/src/Viewer/renderers/label.jsx +470 -0
- package/src/Viewer/renderers/legend.jsx +306 -0
- package/src/Viewer/renderers/line.jsx +511 -0
- package/src/Viewer/renderers/lineSegment.jsx +754 -0
- package/src/Viewer/renderers/list.jsx +111 -0
- package/src/Viewer/renderers/lq.jsx +12 -0
- package/src/Viewer/renderers/lsq.jsx +12 -0
- package/src/Viewer/renderers/math.jsx +582 -0
- package/src/Viewer/renderers/mathInput.css +10 -0
- package/src/Viewer/renderers/mathInput.jsx +425 -0
- package/src/Viewer/renderers/mathInputog.jsx +534 -0
- package/src/Viewer/renderers/mathList.jsx +39 -0
- package/src/Viewer/renderers/matrixInput.jsx +317 -0
- package/src/Viewer/renderers/mdash.jsx +12 -0
- package/src/Viewer/renderers/nbsp.jsx +12 -0
- package/src/Viewer/renderers/ndash.jsx +12 -0
- package/src/Viewer/renderers/number.jsx +454 -0
- package/src/Viewer/renderers/numberList.jsx +35 -0
- package/src/Viewer/renderers/orbitalDiagram.jsx +247 -0
- package/src/Viewer/renderers/orbitalDiagramInput.jsx +450 -0
- package/src/Viewer/renderers/p.jsx +38 -0
- package/src/Viewer/renderers/paginatorControls.jsx +41 -0
- package/src/Viewer/renderers/pegboard.jsx +239 -0
- package/src/Viewer/renderers/point.jsx +649 -0
- package/src/Viewer/renderers/polygon.jsx +612 -0
- package/src/Viewer/renderers/polyline.jsx +608 -0
- package/src/Viewer/renderers/pre.jsx +34 -0
- package/src/Viewer/renderers/q.jsx +17 -0
- package/src/Viewer/renderers/ray.jsx +410 -0
- package/src/Viewer/renderers/ref.jsx +149 -0
- package/src/Viewer/renderers/regionBetweenCurveXAxis.jsx +182 -0
- package/src/Viewer/renderers/renderDoenetML.jsx +56 -0
- package/src/Viewer/renderers/row.jsx +31 -0
- package/src/Viewer/renderers/rq.jsx +12 -0
- package/src/Viewer/renderers/rsq.jsx +12 -0
- package/src/Viewer/renderers/section.jsx +427 -0
- package/src/Viewer/renderers/sideBySide.jsx +80 -0
- package/src/Viewer/renderers/slider.jsx +800 -0
- package/src/Viewer/renderers/solution.jsx +134 -0
- package/src/Viewer/renderers/spreadsheet.jsx +83 -0
- package/src/Viewer/renderers/sq.jsx +17 -0
- package/src/Viewer/renderers/styles/global.css +14 -0
- package/src/Viewer/renderers/subsetOfRealsInput.jsx +392 -0
- package/src/Viewer/renderers/summaryStatistics.jsx +83 -0
- package/src/Viewer/renderers/table.jsx +78 -0
- package/src/Viewer/renderers/tabular.jsx +58 -0
- package/src/Viewer/renderers/tag.jsx +26 -0
- package/src/Viewer/renderers/text.jsx +439 -0
- package/src/Viewer/renderers/textInput.jsx +774 -0
- package/src/Viewer/renderers/textList.jsx +30 -0
- package/src/Viewer/renderers/triggerSet.jsx +52 -0
- package/src/Viewer/renderers/updateValue.jsx +30 -0
- package/src/Viewer/renderers/utils/css.js +13 -0
- package/src/Viewer/renderers/utils/graph.js +159 -0
- package/src/Viewer/renderers/utils/offGraphIndicators.js +91 -0
- package/src/Viewer/renderers/vector.jsx +678 -0
- package/src/Viewer/renderers/video.jsx +494 -0
- package/src/Viewer/useDoenetRenderer.jsx +128 -0
- package/src/main.jsx +16 -0
- package/src/media/fonts/files/open-sans-v18-latin-700.woff +0 -0
- package/src/media/fonts/files/open-sans-v18-latin-700.woff2 +0 -0
- package/src/media/fonts/files/open-sans-v18-latin-700italic.woff +0 -0
- package/src/media/fonts/files/open-sans-v18-latin-700italic.woff2 +0 -0
- package/src/media/fonts/files/open-sans-v18-latin-italic.woff +0 -0
- package/src/media/fonts/files/open-sans-v18-latin-italic.woff2 +0 -0
- package/src/media/fonts/files/open-sans-v18-latin-light-italic.woff +0 -0
- package/src/media/fonts/files/open-sans-v18-latin-light-italic.woff2 +0 -0
- package/src/media/fonts/files/open-sans-v18-latin-light.woff +0 -0
- package/src/media/fonts/files/open-sans-v18-latin-light.woff2 +0 -0
- package/src/media/fonts/files/open-sans-v18-latin-regular.woff +0 -0
- package/src/media/fonts/files/open-sans-v18-latin-regular.woff2 +0 -0
- package/src/test/testCode.doenet +26 -0
- package/src/test/testViewer.jsx +158 -0
- package/src/uiComponents/ActionButton.jsx +157 -0
- package/src/uiComponents/ActionButtonGroup.jsx +93 -0
- package/src/uiComponents/Button.jsx +160 -0
- package/src/uiComponents/ButtonGroup.jsx +56 -0
- package/src/uiComponents/ToggleButton.jsx +194 -0
- package/src/uiComponents/ToggleButtonGroup.jsx +77 -0
- package/src/utils/activityUtils.js +713 -0
- package/src/utils/array.js +17 -0
- package/src/utils/cid.js +34 -0
- package/src/utils/componentInfoObjects.js +89 -0
- package/src/utils/deepFunctions.js +165 -0
- package/src/utils/enumeration.js +226 -0
- package/src/utils/math.js +624 -0
- package/src/utils/naming.js +44 -0
- package/src/utils/retrieveTextFile.js +156 -0
- package/src/utils/returnAllPossibleVariants.js +81 -0
- package/src/utils/sequence.js +715 -0
- package/src/utils/serialize.js +29 -0
- package/src/utils/serializedStateProcessing.js +2587 -0
- package/src/utils/subset-of-reals.js +783 -0
- package/src/utils/url.js +19 -0
- package/vite.config.js +14 -0
|
@@ -0,0 +1,2478 @@
|
|
|
1
|
+
import GraphicalComponent from "./abstract/GraphicalComponent";
|
|
2
|
+
import me from "math-expressions";
|
|
3
|
+
import {
|
|
4
|
+
breakEmbeddedStringByCommas,
|
|
5
|
+
returnBreakStringsSugarFunction,
|
|
6
|
+
} from "./commonsugar/breakstrings";
|
|
7
|
+
import {
|
|
8
|
+
convertValueToMathExpression,
|
|
9
|
+
roundForDisplay,
|
|
10
|
+
vectorOperators,
|
|
11
|
+
} from "../utils/math";
|
|
12
|
+
import { returnTextStyleDescriptionDefinitions } from "../utils/style";
|
|
13
|
+
import {
|
|
14
|
+
returnRoundingAttributeComponentShadowing,
|
|
15
|
+
returnRoundingAttributes,
|
|
16
|
+
returnRoundingStateVariableDefinitions,
|
|
17
|
+
} from "../utils/rounding";
|
|
18
|
+
|
|
19
|
+
export default class Vector extends GraphicalComponent {
|
|
20
|
+
constructor(args) {
|
|
21
|
+
super(args);
|
|
22
|
+
|
|
23
|
+
Object.assign(this.actions, {
|
|
24
|
+
moveVector: this.moveVector.bind(this),
|
|
25
|
+
vectorClicked: this.vectorClicked.bind(this),
|
|
26
|
+
vectorFocused: this.vectorFocused.bind(this),
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
static componentType = "vector";
|
|
30
|
+
|
|
31
|
+
static primaryStateVariableForDefinition = "displacementShadow";
|
|
32
|
+
|
|
33
|
+
static createAttributesObject() {
|
|
34
|
+
let attributes = super.createAttributesObject();
|
|
35
|
+
|
|
36
|
+
attributes.draggable = {
|
|
37
|
+
createComponentOfType: "boolean",
|
|
38
|
+
createStateVariable: "draggable",
|
|
39
|
+
defaultValue: true,
|
|
40
|
+
public: true,
|
|
41
|
+
forRenderer: true,
|
|
42
|
+
};
|
|
43
|
+
attributes.headDraggable = {
|
|
44
|
+
createComponentOfType: "boolean",
|
|
45
|
+
};
|
|
46
|
+
attributes.tailDraggable = {
|
|
47
|
+
createComponentOfType: "boolean",
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
attributes.x = {
|
|
51
|
+
createComponentOfType: "math",
|
|
52
|
+
};
|
|
53
|
+
attributes.y = {
|
|
54
|
+
createComponentOfType: "math",
|
|
55
|
+
};
|
|
56
|
+
attributes.z = {
|
|
57
|
+
createComponentOfType: "math",
|
|
58
|
+
};
|
|
59
|
+
attributes.xs = {
|
|
60
|
+
createComponentOfType: "mathList",
|
|
61
|
+
};
|
|
62
|
+
attributes.displacement = {
|
|
63
|
+
createComponentOfType: "coords",
|
|
64
|
+
};
|
|
65
|
+
attributes.head = {
|
|
66
|
+
createComponentOfType: "point",
|
|
67
|
+
};
|
|
68
|
+
attributes.tail = {
|
|
69
|
+
createComponentOfType: "point",
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
Object.assign(attributes, returnRoundingAttributes());
|
|
73
|
+
|
|
74
|
+
attributes.displayWithAngleBrackets = {
|
|
75
|
+
createComponentOfType: "boolean",
|
|
76
|
+
createStateVariable: "displayWithAngleBrackets",
|
|
77
|
+
defaultValue: false,
|
|
78
|
+
public: true,
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
return attributes;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
static returnSugarInstructions() {
|
|
85
|
+
let sugarInstructions = super.returnSugarInstructions();
|
|
86
|
+
|
|
87
|
+
let breakIntoXsOrCoords = function ({
|
|
88
|
+
matchedChildren,
|
|
89
|
+
componentInfoObjects,
|
|
90
|
+
}) {
|
|
91
|
+
let componentIsSpecifiedType =
|
|
92
|
+
componentInfoObjects.componentIsSpecifiedType;
|
|
93
|
+
|
|
94
|
+
// Find potential component children, i.e., consecutive children that aren't constraints or labels
|
|
95
|
+
// Note: including constraints here in case we add constraints later to vectors
|
|
96
|
+
|
|
97
|
+
let componentChildren = [],
|
|
98
|
+
nonComponentChildrenBegin = [],
|
|
99
|
+
nonComponentChildrenEnd = [];
|
|
100
|
+
|
|
101
|
+
for (let child of matchedChildren) {
|
|
102
|
+
if (
|
|
103
|
+
componentIsSpecifiedType(child, "constraints") ||
|
|
104
|
+
componentIsSpecifiedType(child, "label")
|
|
105
|
+
) {
|
|
106
|
+
if (componentChildren.length > 0) {
|
|
107
|
+
nonComponentChildrenEnd.push(child);
|
|
108
|
+
} else {
|
|
109
|
+
nonComponentChildrenBegin.push(child);
|
|
110
|
+
}
|
|
111
|
+
} else if (nonComponentChildrenEnd.length > 0) {
|
|
112
|
+
nonComponentChildrenEnd.push(child);
|
|
113
|
+
} else {
|
|
114
|
+
componentChildren.push(child);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (componentChildren.length === 0) {
|
|
119
|
+
return { success: false };
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (componentChildren.length === 1) {
|
|
123
|
+
let child = componentChildren[0];
|
|
124
|
+
|
|
125
|
+
if (
|
|
126
|
+
componentIsSpecifiedType(child, "point") ||
|
|
127
|
+
componentIsSpecifiedType(child, "vector")
|
|
128
|
+
) {
|
|
129
|
+
// if have an isolated point or vector, don't use sugar
|
|
130
|
+
// and that child will picked up by the point or vector child group
|
|
131
|
+
return { success: false };
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
let nCompChildren = componentChildren.length;
|
|
136
|
+
|
|
137
|
+
// check if componentChildren represent a single expression inside parens
|
|
138
|
+
let firstChar, lastChar;
|
|
139
|
+
if (typeof componentChildren[0] === "string") {
|
|
140
|
+
componentChildren[0] = componentChildren[0].trimStart();
|
|
141
|
+
firstChar = componentChildren[0][0];
|
|
142
|
+
}
|
|
143
|
+
if (typeof componentChildren[nCompChildren - 1] === "string") {
|
|
144
|
+
componentChildren[nCompChildren - 1] =
|
|
145
|
+
componentChildren[nCompChildren - 1].trimEnd();
|
|
146
|
+
let lastChild = componentChildren[nCompChildren - 1];
|
|
147
|
+
lastChar = lastChild[lastChild.length - 1];
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (firstChar === "(" && lastChar === ")") {
|
|
151
|
+
// start and end with parens, check if can split by commas after removing these parens
|
|
152
|
+
let modifiedChildren = [...componentChildren];
|
|
153
|
+
modifiedChildren[0] = modifiedChildren[0].substring(1);
|
|
154
|
+
|
|
155
|
+
let lastChild = modifiedChildren[modifiedChildren.length - 1];
|
|
156
|
+
modifiedChildren[modifiedChildren.length - 1] = lastChild.substring(
|
|
157
|
+
0,
|
|
158
|
+
lastChild.length - 1,
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
let breakResult = breakEmbeddedStringByCommas({
|
|
162
|
+
childrenList: modifiedChildren,
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
if (breakResult.success) {
|
|
166
|
+
// wrap maths around each piece, wrap whole thing in mathList
|
|
167
|
+
// and use for xs attribute
|
|
168
|
+
return {
|
|
169
|
+
success: true,
|
|
170
|
+
newAttributes: {
|
|
171
|
+
xs: {
|
|
172
|
+
component: {
|
|
173
|
+
componentType: "mathList",
|
|
174
|
+
children: breakResult.pieces.map((x) => ({
|
|
175
|
+
componentType: "math",
|
|
176
|
+
children: x,
|
|
177
|
+
})),
|
|
178
|
+
skipSugar: true,
|
|
179
|
+
},
|
|
180
|
+
},
|
|
181
|
+
},
|
|
182
|
+
newChildren: [
|
|
183
|
+
...nonComponentChildrenBegin,
|
|
184
|
+
...nonComponentChildrenEnd,
|
|
185
|
+
],
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// if didn't succeed in breaking it into xs, then use the component children as a displacement
|
|
191
|
+
return {
|
|
192
|
+
success: true,
|
|
193
|
+
newAttributes: {
|
|
194
|
+
displacement: {
|
|
195
|
+
component: {
|
|
196
|
+
componentType: "coords",
|
|
197
|
+
children: componentChildren,
|
|
198
|
+
},
|
|
199
|
+
},
|
|
200
|
+
},
|
|
201
|
+
newChildren: [...nonComponentChildrenBegin, ...nonComponentChildrenEnd],
|
|
202
|
+
};
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
sugarInstructions.push({
|
|
206
|
+
replacementFunction: breakIntoXsOrCoords,
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
return sugarInstructions;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
static returnChildGroups() {
|
|
213
|
+
let childGroups = super.returnChildGroups();
|
|
214
|
+
|
|
215
|
+
childGroups.push(
|
|
216
|
+
...[
|
|
217
|
+
{
|
|
218
|
+
group: "pointsAndVectors",
|
|
219
|
+
componentTypes: ["point", "vector"],
|
|
220
|
+
},
|
|
221
|
+
],
|
|
222
|
+
);
|
|
223
|
+
|
|
224
|
+
return childGroups;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
static returnStateVariableDefinitions() {
|
|
228
|
+
let stateVariableDefinitions = super.returnStateVariableDefinitions();
|
|
229
|
+
|
|
230
|
+
Object.assign(
|
|
231
|
+
stateVariableDefinitions,
|
|
232
|
+
returnRoundingStateVariableDefinitions(),
|
|
233
|
+
);
|
|
234
|
+
|
|
235
|
+
let styleDescriptionDefinitions = returnTextStyleDescriptionDefinitions();
|
|
236
|
+
Object.assign(stateVariableDefinitions, styleDescriptionDefinitions);
|
|
237
|
+
|
|
238
|
+
stateVariableDefinitions.styleDescription = {
|
|
239
|
+
public: true,
|
|
240
|
+
shadowingInstructions: {
|
|
241
|
+
createComponentOfType: "text",
|
|
242
|
+
},
|
|
243
|
+
returnDependencies: () => ({
|
|
244
|
+
selectedStyle: {
|
|
245
|
+
dependencyType: "stateVariable",
|
|
246
|
+
variableName: "selectedStyle",
|
|
247
|
+
},
|
|
248
|
+
document: {
|
|
249
|
+
dependencyType: "ancestor",
|
|
250
|
+
componentType: "document",
|
|
251
|
+
variableNames: ["theme"],
|
|
252
|
+
},
|
|
253
|
+
}),
|
|
254
|
+
definition: function ({ dependencyValues }) {
|
|
255
|
+
let lineColorWord;
|
|
256
|
+
if (dependencyValues.document?.stateValues.theme === "dark") {
|
|
257
|
+
lineColorWord = dependencyValues.selectedStyle.lineColorWordDarkMode;
|
|
258
|
+
} else {
|
|
259
|
+
lineColorWord = dependencyValues.selectedStyle.lineColorWord;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
let styleDescription = dependencyValues.selectedStyle.lineWidthWord;
|
|
263
|
+
if (dependencyValues.selectedStyle.lineStyleWord) {
|
|
264
|
+
if (styleDescription) {
|
|
265
|
+
styleDescription += " ";
|
|
266
|
+
}
|
|
267
|
+
styleDescription += dependencyValues.selectedStyle.lineStyleWord;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
if (styleDescription) {
|
|
271
|
+
styleDescription += " ";
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
styleDescription += lineColorWord;
|
|
275
|
+
|
|
276
|
+
return { setValue: { styleDescription } };
|
|
277
|
+
},
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
stateVariableDefinitions.styleDescriptionWithNoun = {
|
|
281
|
+
public: true,
|
|
282
|
+
shadowingInstructions: {
|
|
283
|
+
createComponentOfType: "text",
|
|
284
|
+
},
|
|
285
|
+
returnDependencies: () => ({
|
|
286
|
+
styleDescription: {
|
|
287
|
+
dependencyType: "stateVariable",
|
|
288
|
+
variableName: "styleDescription",
|
|
289
|
+
},
|
|
290
|
+
}),
|
|
291
|
+
definition: function ({ dependencyValues }) {
|
|
292
|
+
let styleDescriptionWithNoun =
|
|
293
|
+
dependencyValues.styleDescription + " vector";
|
|
294
|
+
|
|
295
|
+
return { setValue: { styleDescriptionWithNoun } };
|
|
296
|
+
},
|
|
297
|
+
};
|
|
298
|
+
|
|
299
|
+
stateVariableDefinitions.tailDraggable = {
|
|
300
|
+
public: true,
|
|
301
|
+
shadowingInstructions: {
|
|
302
|
+
createComponentOfType: "boolean",
|
|
303
|
+
},
|
|
304
|
+
hasEssential: true,
|
|
305
|
+
forRenderer: true,
|
|
306
|
+
returnDependencies: () => ({
|
|
307
|
+
tailDraggableAttr: {
|
|
308
|
+
dependencyType: "attributeComponent",
|
|
309
|
+
attributeName: "tailDraggable",
|
|
310
|
+
variableNames: ["value"],
|
|
311
|
+
},
|
|
312
|
+
draggable: {
|
|
313
|
+
dependencyType: "stateVariable",
|
|
314
|
+
variableName: "draggable",
|
|
315
|
+
},
|
|
316
|
+
}),
|
|
317
|
+
definition({ dependencyValues }) {
|
|
318
|
+
if (dependencyValues.tailDraggableAttr) {
|
|
319
|
+
return {
|
|
320
|
+
setValue: {
|
|
321
|
+
tailDraggable:
|
|
322
|
+
dependencyValues.tailDraggableAttr.stateValues.value,
|
|
323
|
+
},
|
|
324
|
+
};
|
|
325
|
+
} else {
|
|
326
|
+
return {
|
|
327
|
+
useEssentialOrDefaultValue: {
|
|
328
|
+
tailDraggable: { defaultValue: dependencyValues.draggable },
|
|
329
|
+
},
|
|
330
|
+
};
|
|
331
|
+
}
|
|
332
|
+
},
|
|
333
|
+
};
|
|
334
|
+
|
|
335
|
+
stateVariableDefinitions.headDraggable = {
|
|
336
|
+
public: true,
|
|
337
|
+
shadowingInstructions: {
|
|
338
|
+
createComponentOfType: "boolean",
|
|
339
|
+
},
|
|
340
|
+
hasEssential: true,
|
|
341
|
+
forRenderer: true,
|
|
342
|
+
returnDependencies: () => ({
|
|
343
|
+
headDraggableAttr: {
|
|
344
|
+
dependencyType: "attributeComponent",
|
|
345
|
+
attributeName: "headDraggable",
|
|
346
|
+
variableNames: ["value"],
|
|
347
|
+
},
|
|
348
|
+
draggable: {
|
|
349
|
+
dependencyType: "stateVariable",
|
|
350
|
+
variableName: "draggable",
|
|
351
|
+
},
|
|
352
|
+
}),
|
|
353
|
+
definition({ dependencyValues }) {
|
|
354
|
+
if (dependencyValues.headDraggableAttr) {
|
|
355
|
+
return {
|
|
356
|
+
setValue: {
|
|
357
|
+
headDraggable:
|
|
358
|
+
dependencyValues.headDraggableAttr.stateValues.value,
|
|
359
|
+
},
|
|
360
|
+
};
|
|
361
|
+
} else {
|
|
362
|
+
return {
|
|
363
|
+
useEssentialOrDefaultValue: {
|
|
364
|
+
headDraggable: { defaultValue: dependencyValues.draggable },
|
|
365
|
+
},
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
},
|
|
369
|
+
};
|
|
370
|
+
|
|
371
|
+
// displacementShadow will be null unless vector was created
|
|
372
|
+
// via an adapter or copy prop or from serialized state with displacement value
|
|
373
|
+
// In case of adapter or copy prop,
|
|
374
|
+
// given the primaryStateVariableForDefinition static variable,
|
|
375
|
+
// the definition of displacementShadow will be changed to be the value
|
|
376
|
+
// that shadows the component adapted or copy
|
|
377
|
+
stateVariableDefinitions.displacementShadow = {
|
|
378
|
+
defaultValue: null,
|
|
379
|
+
isLocation: true,
|
|
380
|
+
hasEssential: true,
|
|
381
|
+
essentialVarName: "displacement",
|
|
382
|
+
set: convertValueToMathExpression,
|
|
383
|
+
returnDependencies: () => ({}),
|
|
384
|
+
definition: () => ({
|
|
385
|
+
useEssentialOrDefaultValue: {
|
|
386
|
+
displacementShadow: true,
|
|
387
|
+
},
|
|
388
|
+
}),
|
|
389
|
+
inverseDefinition: function ({ desiredStateVariableValues }) {
|
|
390
|
+
return {
|
|
391
|
+
success: true,
|
|
392
|
+
instructions: [
|
|
393
|
+
{
|
|
394
|
+
setEssentialValue: "displacementShadow",
|
|
395
|
+
value: convertValueToMathExpression(
|
|
396
|
+
desiredStateVariableValues.displacementShadow,
|
|
397
|
+
),
|
|
398
|
+
},
|
|
399
|
+
],
|
|
400
|
+
};
|
|
401
|
+
},
|
|
402
|
+
};
|
|
403
|
+
|
|
404
|
+
// headShadow will be null unless vector was created
|
|
405
|
+
// from serialized state with head value
|
|
406
|
+
stateVariableDefinitions.headShadow = {
|
|
407
|
+
defaultValue: null,
|
|
408
|
+
isLocation: true,
|
|
409
|
+
hasEssential: true,
|
|
410
|
+
essentialVarName: "head",
|
|
411
|
+
set: convertValueToMathExpression,
|
|
412
|
+
returnDependencies: () => ({}),
|
|
413
|
+
definition: () => ({
|
|
414
|
+
useEssentialOrDefaultValue: {
|
|
415
|
+
headShadow: true,
|
|
416
|
+
},
|
|
417
|
+
}),
|
|
418
|
+
inverseDefinition: function ({ desiredStateVariableValues }) {
|
|
419
|
+
return {
|
|
420
|
+
success: true,
|
|
421
|
+
instructions: [
|
|
422
|
+
{
|
|
423
|
+
setEssentialValue: "headShadow",
|
|
424
|
+
value: convertValueToMathExpression(
|
|
425
|
+
desiredStateVariableValues.headShadow,
|
|
426
|
+
),
|
|
427
|
+
},
|
|
428
|
+
],
|
|
429
|
+
};
|
|
430
|
+
},
|
|
431
|
+
};
|
|
432
|
+
|
|
433
|
+
// tailShadow will be null unless vector was created
|
|
434
|
+
// from serialized state with tail value
|
|
435
|
+
stateVariableDefinitions.tailShadow = {
|
|
436
|
+
defaultValue: null,
|
|
437
|
+
isLocation: true,
|
|
438
|
+
hasEssential: true,
|
|
439
|
+
essentialVarName: "tail",
|
|
440
|
+
set: convertValueToMathExpression,
|
|
441
|
+
returnDependencies: () => ({}),
|
|
442
|
+
definition: () => ({
|
|
443
|
+
useEssentialOrDefaultValue: {
|
|
444
|
+
tailShadow: true,
|
|
445
|
+
},
|
|
446
|
+
}),
|
|
447
|
+
inverseDefinition: function ({ desiredStateVariableValues }) {
|
|
448
|
+
return {
|
|
449
|
+
success: true,
|
|
450
|
+
instructions: [
|
|
451
|
+
{
|
|
452
|
+
setEssentialValue: "tailShadow",
|
|
453
|
+
value: convertValueToMathExpression(
|
|
454
|
+
desiredStateVariableValues.tailShadow,
|
|
455
|
+
),
|
|
456
|
+
},
|
|
457
|
+
],
|
|
458
|
+
};
|
|
459
|
+
},
|
|
460
|
+
};
|
|
461
|
+
|
|
462
|
+
stateVariableDefinitions.sourceOfDisplacement = {
|
|
463
|
+
returnDependencies: () => ({
|
|
464
|
+
xAttr: {
|
|
465
|
+
dependencyType: "attributeComponent",
|
|
466
|
+
attributeName: "x",
|
|
467
|
+
},
|
|
468
|
+
yAttr: {
|
|
469
|
+
dependencyType: "attributeComponent",
|
|
470
|
+
attributeName: "y",
|
|
471
|
+
},
|
|
472
|
+
zAttr: {
|
|
473
|
+
dependencyType: "attributeComponent",
|
|
474
|
+
attributeName: "z",
|
|
475
|
+
},
|
|
476
|
+
xsAttr: {
|
|
477
|
+
dependencyType: "attributeComponent",
|
|
478
|
+
attributeName: "xs",
|
|
479
|
+
},
|
|
480
|
+
displacementAttr: {
|
|
481
|
+
dependencyType: "attributeComponent",
|
|
482
|
+
attributeName: "displacement",
|
|
483
|
+
},
|
|
484
|
+
pointOrVectorChild: {
|
|
485
|
+
dependencyType: "child",
|
|
486
|
+
childGroups: ["pointsAndVectors"],
|
|
487
|
+
},
|
|
488
|
+
}),
|
|
489
|
+
definition({ dependencyValues }) {
|
|
490
|
+
let sourceOfDisplacement = null;
|
|
491
|
+
if (dependencyValues.pointOrVectorChild.length > 0) {
|
|
492
|
+
sourceOfDisplacement = "pointOrVectorChild";
|
|
493
|
+
} else if (dependencyValues.displacementAttr !== null) {
|
|
494
|
+
sourceOfDisplacement = "displacementAttr";
|
|
495
|
+
} else if (dependencyValues.xsAttr !== null) {
|
|
496
|
+
sourceOfDisplacement = "xsAttr";
|
|
497
|
+
} else if (
|
|
498
|
+
dependencyValues.xAttr !== null ||
|
|
499
|
+
dependencyValues.yAttr !== null ||
|
|
500
|
+
dependencyValues.zAttr !== null
|
|
501
|
+
) {
|
|
502
|
+
sourceOfDisplacement = "componentAttrs";
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
return {
|
|
506
|
+
setValue: { sourceOfDisplacement },
|
|
507
|
+
};
|
|
508
|
+
},
|
|
509
|
+
};
|
|
510
|
+
|
|
511
|
+
// if a copy shadow, the basedOnX definitions will be overwritten
|
|
512
|
+
// so we don't have to consider that case here
|
|
513
|
+
|
|
514
|
+
stateVariableDefinitions.basedOnHead = {
|
|
515
|
+
returnDependencies: () => ({
|
|
516
|
+
headAttr: {
|
|
517
|
+
dependencyType: "attributeComponent",
|
|
518
|
+
attributeName: "head",
|
|
519
|
+
},
|
|
520
|
+
headShadow: {
|
|
521
|
+
dependencyType: "stateVariable",
|
|
522
|
+
variableName: "headShadow",
|
|
523
|
+
},
|
|
524
|
+
tailAttr: {
|
|
525
|
+
dependencyType: "attributeComponent",
|
|
526
|
+
attributeName: "tail",
|
|
527
|
+
},
|
|
528
|
+
sourceOfDisplacement: {
|
|
529
|
+
dependencyType: "stateVariable",
|
|
530
|
+
variableName: "sourceOfDisplacement",
|
|
531
|
+
},
|
|
532
|
+
}),
|
|
533
|
+
definition: function ({ dependencyValues }) {
|
|
534
|
+
if (
|
|
535
|
+
dependencyValues.tailAttr !== null &&
|
|
536
|
+
dependencyValues.sourceOfDisplacement !== null
|
|
537
|
+
) {
|
|
538
|
+
if (dependencyValues.headAttr !== null) {
|
|
539
|
+
// if overprescribed by specifying head, tail, and displacement
|
|
540
|
+
// we ignore head
|
|
541
|
+
console.warn(
|
|
542
|
+
`Vector is prescribed by head, tail, and displacement. Ignoring specified head.`,
|
|
543
|
+
);
|
|
544
|
+
}
|
|
545
|
+
return {
|
|
546
|
+
setValue: { basedOnHead: false },
|
|
547
|
+
checkForActualChange: { basedOnHead: true },
|
|
548
|
+
};
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
if (dependencyValues.headAttr !== null) {
|
|
552
|
+
return {
|
|
553
|
+
setValue: { basedOnHead: true },
|
|
554
|
+
checkForActualChange: { basedOnHead: true },
|
|
555
|
+
};
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
return {
|
|
559
|
+
setValue: { basedOnHead: dependencyValues.headShadow !== null },
|
|
560
|
+
checkForActualChange: { basedOnHead: true },
|
|
561
|
+
};
|
|
562
|
+
},
|
|
563
|
+
};
|
|
564
|
+
|
|
565
|
+
stateVariableDefinitions.basedOnTail = {
|
|
566
|
+
returnDependencies: () => ({
|
|
567
|
+
tailAttr: {
|
|
568
|
+
dependencyType: "attributeComponent",
|
|
569
|
+
attributeName: "tail",
|
|
570
|
+
},
|
|
571
|
+
tailShadow: {
|
|
572
|
+
dependencyType: "stateVariable",
|
|
573
|
+
variableName: "tailShadow",
|
|
574
|
+
},
|
|
575
|
+
}),
|
|
576
|
+
definition: function ({ dependencyValues }) {
|
|
577
|
+
if (dependencyValues.tailAttr !== null) {
|
|
578
|
+
return {
|
|
579
|
+
setValue: { basedOnTail: true },
|
|
580
|
+
checkForActualChange: { basedOnTail: true },
|
|
581
|
+
};
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
return {
|
|
585
|
+
setValue: { basedOnTail: dependencyValues.tailShadow !== null },
|
|
586
|
+
checkForActualChange: { basedOnTail: true },
|
|
587
|
+
};
|
|
588
|
+
},
|
|
589
|
+
};
|
|
590
|
+
|
|
591
|
+
stateVariableDefinitions.basedOnDisplacement = {
|
|
592
|
+
returnDependencies: () => ({
|
|
593
|
+
sourceOfDisplacement: {
|
|
594
|
+
dependencyType: "stateVariable",
|
|
595
|
+
variableName: "sourceOfDisplacement",
|
|
596
|
+
},
|
|
597
|
+
displacementShadow: {
|
|
598
|
+
dependencyType: "stateVariable",
|
|
599
|
+
variableName: "displacementShadow",
|
|
600
|
+
},
|
|
601
|
+
}),
|
|
602
|
+
definition: function ({ dependencyValues }) {
|
|
603
|
+
if (dependencyValues.sourceOfDisplacement !== null) {
|
|
604
|
+
return {
|
|
605
|
+
setValue: { basedOnDisplacement: true },
|
|
606
|
+
checkForActualChange: { basedOnDisplacement: true },
|
|
607
|
+
};
|
|
608
|
+
}
|
|
609
|
+
return {
|
|
610
|
+
setValue: {
|
|
611
|
+
basedOnDisplacement: dependencyValues.displacementShadow !== null,
|
|
612
|
+
},
|
|
613
|
+
checkForActualChange: { basedOnDisplacement: true },
|
|
614
|
+
};
|
|
615
|
+
},
|
|
616
|
+
};
|
|
617
|
+
|
|
618
|
+
stateVariableDefinitions.numDimDisplacement = {
|
|
619
|
+
stateVariablesDeterminingDependencies: [
|
|
620
|
+
"basedOnDisplacement",
|
|
621
|
+
"basedOnHead",
|
|
622
|
+
"basedOnTail",
|
|
623
|
+
],
|
|
624
|
+
returnDependencies({ stateValues }) {
|
|
625
|
+
let dependencies = {
|
|
626
|
+
basedOnHead: {
|
|
627
|
+
dependencyType: "stateVariable",
|
|
628
|
+
variableName: "basedOnHead",
|
|
629
|
+
},
|
|
630
|
+
basedOnTail: {
|
|
631
|
+
dependencyType: "stateVariable",
|
|
632
|
+
variableName: "basedOnTail",
|
|
633
|
+
},
|
|
634
|
+
basedOnDisplacement: {
|
|
635
|
+
dependencyType: "stateVariable",
|
|
636
|
+
variableName: "basedOnDisplacement",
|
|
637
|
+
},
|
|
638
|
+
sourceOfDisplacement: {
|
|
639
|
+
dependencyType: "stateVariable",
|
|
640
|
+
variableName: "sourceOfDisplacement",
|
|
641
|
+
},
|
|
642
|
+
displacementShadow: {
|
|
643
|
+
dependencyType: "stateVariable",
|
|
644
|
+
variableName: "displacementShadow",
|
|
645
|
+
},
|
|
646
|
+
displacementAttr: {
|
|
647
|
+
dependencyType: "attributeComponent",
|
|
648
|
+
attributeName: "displacement",
|
|
649
|
+
variableNames: ["value"],
|
|
650
|
+
},
|
|
651
|
+
pointOrVectorChild: {
|
|
652
|
+
dependencyType: "child",
|
|
653
|
+
childGroups: ["pointsAndVectors"],
|
|
654
|
+
variableNames: ["numDimensions"],
|
|
655
|
+
},
|
|
656
|
+
xAttr: {
|
|
657
|
+
dependencyType: "attributeComponent",
|
|
658
|
+
attributeName: "x",
|
|
659
|
+
},
|
|
660
|
+
yAttr: {
|
|
661
|
+
dependencyType: "attributeComponent",
|
|
662
|
+
attributeName: "y",
|
|
663
|
+
},
|
|
664
|
+
zAttr: {
|
|
665
|
+
dependencyType: "attributeComponent",
|
|
666
|
+
attributeName: "z",
|
|
667
|
+
},
|
|
668
|
+
xsAttr: {
|
|
669
|
+
dependencyType: "attributeComponent",
|
|
670
|
+
attributeName: "xs",
|
|
671
|
+
variableNames: ["numComponents"],
|
|
672
|
+
},
|
|
673
|
+
};
|
|
674
|
+
|
|
675
|
+
if (!stateValues.basedOnDisplacement) {
|
|
676
|
+
if (stateValues.basedOnHead) {
|
|
677
|
+
dependencies.numDimHead = {
|
|
678
|
+
dependencyType: "stateVariable",
|
|
679
|
+
variableName: "numDimHead",
|
|
680
|
+
};
|
|
681
|
+
}
|
|
682
|
+
if (stateValues.basedOnTail) {
|
|
683
|
+
dependencies.numDimTail = {
|
|
684
|
+
dependencyType: "stateVariable",
|
|
685
|
+
variableName: "numDimTail",
|
|
686
|
+
};
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
return dependencies;
|
|
690
|
+
},
|
|
691
|
+
definition: function ({ dependencyValues }) {
|
|
692
|
+
let numDimDisplacement;
|
|
693
|
+
|
|
694
|
+
if (dependencyValues.basedOnDisplacement) {
|
|
695
|
+
switch (dependencyValues.sourceOfDisplacement) {
|
|
696
|
+
case "pointOrVectorChild":
|
|
697
|
+
numDimDisplacement =
|
|
698
|
+
dependencyValues.pointOrVectorChild[0].stateValues
|
|
699
|
+
.numDimensions;
|
|
700
|
+
break;
|
|
701
|
+
case "displacementAttr":
|
|
702
|
+
let displacementTree1 =
|
|
703
|
+
dependencyValues.displacementAttr.stateValues.value
|
|
704
|
+
.expand()
|
|
705
|
+
.simplify().tree;
|
|
706
|
+
if (
|
|
707
|
+
Array.isArray(displacementTree1) &&
|
|
708
|
+
vectorOperators.includes(displacementTree1[0])
|
|
709
|
+
) {
|
|
710
|
+
numDimDisplacement = displacementTree1.length - 1;
|
|
711
|
+
} else {
|
|
712
|
+
numDimDisplacement = 1;
|
|
713
|
+
}
|
|
714
|
+
break;
|
|
715
|
+
case "xsAttr":
|
|
716
|
+
numDimDisplacement =
|
|
717
|
+
dependencyValues.xsAttr.stateValues.numComponents;
|
|
718
|
+
break;
|
|
719
|
+
case "componentAttrs":
|
|
720
|
+
if (dependencyValues.zAttr !== null) {
|
|
721
|
+
numDimDisplacement = 3;
|
|
722
|
+
} else if (dependencyValues.yAttr !== null) {
|
|
723
|
+
numDimDisplacement = 2;
|
|
724
|
+
} else {
|
|
725
|
+
numDimDisplacement = 1;
|
|
726
|
+
}
|
|
727
|
+
break;
|
|
728
|
+
default:
|
|
729
|
+
// since based on displacement and no source of displacement
|
|
730
|
+
// we must have a displacement shadow
|
|
731
|
+
let displacementTree2 = dependencyValues.displacementShadow
|
|
732
|
+
.tuples_to_vectors()
|
|
733
|
+
.expand()
|
|
734
|
+
.simplify().tree;
|
|
735
|
+
if (
|
|
736
|
+
Array.isArray(displacementTree2) &&
|
|
737
|
+
vectorOperators.includes(displacementTree2[0])
|
|
738
|
+
) {
|
|
739
|
+
numDimDisplacement = displacementTree2.length - 1;
|
|
740
|
+
} else {
|
|
741
|
+
numDimDisplacement = 1;
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
} else {
|
|
745
|
+
if (dependencyValues.basedOnHead) {
|
|
746
|
+
if (dependencyValues.basedOnTail) {
|
|
747
|
+
if (dependencyValues.numDimHead === dependencyValues.numDimTail) {
|
|
748
|
+
numDimDisplacement = dependencyValues.numDimHead;
|
|
749
|
+
} else {
|
|
750
|
+
numDimDisplacement = NaN;
|
|
751
|
+
}
|
|
752
|
+
} else {
|
|
753
|
+
numDimDisplacement = dependencyValues.numDimHead;
|
|
754
|
+
}
|
|
755
|
+
} else if (dependencyValues.basedOnTail) {
|
|
756
|
+
numDimDisplacement = dependencyValues.numDimTail;
|
|
757
|
+
} else {
|
|
758
|
+
numDimDisplacement = 2;
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
return {
|
|
763
|
+
setValue: { numDimDisplacement },
|
|
764
|
+
checkForActualChange: { numDimDisplacement: true },
|
|
765
|
+
};
|
|
766
|
+
},
|
|
767
|
+
};
|
|
768
|
+
|
|
769
|
+
stateVariableDefinitions.numDimHead = {
|
|
770
|
+
stateVariablesDeterminingDependencies: [
|
|
771
|
+
"basedOnDisplacement",
|
|
772
|
+
"basedOnHead",
|
|
773
|
+
"basedOnTail",
|
|
774
|
+
],
|
|
775
|
+
returnDependencies({ stateValues }) {
|
|
776
|
+
let dependencies = {
|
|
777
|
+
basedOnHead: {
|
|
778
|
+
dependencyType: "stateVariable",
|
|
779
|
+
variableName: "basedOnHead",
|
|
780
|
+
},
|
|
781
|
+
basedOnTail: {
|
|
782
|
+
dependencyType: "stateVariable",
|
|
783
|
+
variableName: "basedOnTail",
|
|
784
|
+
},
|
|
785
|
+
basedOnDisplacement: {
|
|
786
|
+
dependencyType: "stateVariable",
|
|
787
|
+
variableName: "basedOnDisplacement",
|
|
788
|
+
},
|
|
789
|
+
headShadow: {
|
|
790
|
+
dependencyType: "stateVariable",
|
|
791
|
+
variableName: "headShadow",
|
|
792
|
+
},
|
|
793
|
+
headAttr: {
|
|
794
|
+
dependencyType: "attributeComponent",
|
|
795
|
+
attributeName: "head",
|
|
796
|
+
variableNames: ["numDimensions"],
|
|
797
|
+
},
|
|
798
|
+
};
|
|
799
|
+
|
|
800
|
+
if (!stateValues.basedOnHead) {
|
|
801
|
+
if (stateValues.basedOnTail) {
|
|
802
|
+
dependencies.numDimTail = {
|
|
803
|
+
dependencyType: "stateVariable",
|
|
804
|
+
variableName: "numDimTail",
|
|
805
|
+
};
|
|
806
|
+
}
|
|
807
|
+
if (stateValues.basedOnDisplacement) {
|
|
808
|
+
dependencies.numDimDisplacement = {
|
|
809
|
+
dependencyType: "stateVariable",
|
|
810
|
+
variableName: "numDimDisplacement",
|
|
811
|
+
};
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
return dependencies;
|
|
815
|
+
},
|
|
816
|
+
definition: function ({ dependencyValues }) {
|
|
817
|
+
let numDimHead;
|
|
818
|
+
|
|
819
|
+
if (dependencyValues.basedOnHead) {
|
|
820
|
+
if (dependencyValues.headAttr !== null) {
|
|
821
|
+
numDimHead = dependencyValues.headAttr.stateValues.numDimensions;
|
|
822
|
+
} else if (dependencyValues.headShadow) {
|
|
823
|
+
let headTree = dependencyValues.headShadow.tree;
|
|
824
|
+
if (
|
|
825
|
+
Array.isArray(headTree) &&
|
|
826
|
+
vectorOperators.includes(headTree[0])
|
|
827
|
+
) {
|
|
828
|
+
numDimHead = headTree.length - 1;
|
|
829
|
+
} else {
|
|
830
|
+
numDimHead = 2;
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
} else {
|
|
834
|
+
if (dependencyValues.basedOnDisplacement) {
|
|
835
|
+
if (dependencyValues.basedOnTail) {
|
|
836
|
+
if (
|
|
837
|
+
dependencyValues.numDimDisplacement ===
|
|
838
|
+
dependencyValues.numDimTail
|
|
839
|
+
) {
|
|
840
|
+
numDimHead = dependencyValues.numDimDisplacement;
|
|
841
|
+
} else {
|
|
842
|
+
numDimHead = NaN;
|
|
843
|
+
}
|
|
844
|
+
} else {
|
|
845
|
+
numDimHead = dependencyValues.numDimDisplacement;
|
|
846
|
+
}
|
|
847
|
+
} else if (dependencyValues.basedOnTail) {
|
|
848
|
+
numDimHead = dependencyValues.numDimTail;
|
|
849
|
+
} else {
|
|
850
|
+
numDimHead = 2;
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
return {
|
|
855
|
+
setValue: { numDimHead },
|
|
856
|
+
checkForActualChange: { numDimHead: true },
|
|
857
|
+
};
|
|
858
|
+
},
|
|
859
|
+
};
|
|
860
|
+
|
|
861
|
+
stateVariableDefinitions.numDimTail = {
|
|
862
|
+
stateVariablesDeterminingDependencies: [
|
|
863
|
+
"basedOnDisplacement",
|
|
864
|
+
"basedOnHead",
|
|
865
|
+
"basedOnTail",
|
|
866
|
+
],
|
|
867
|
+
returnDependencies({ stateValues }) {
|
|
868
|
+
let dependencies = {
|
|
869
|
+
basedOnHead: {
|
|
870
|
+
dependencyType: "stateVariable",
|
|
871
|
+
variableName: "basedOnHead",
|
|
872
|
+
},
|
|
873
|
+
basedOnTail: {
|
|
874
|
+
dependencyType: "stateVariable",
|
|
875
|
+
variableName: "basedOnTail",
|
|
876
|
+
},
|
|
877
|
+
basedOnDisplacement: {
|
|
878
|
+
dependencyType: "stateVariable",
|
|
879
|
+
variableName: "basedOnDisplacement",
|
|
880
|
+
},
|
|
881
|
+
tailShadow: {
|
|
882
|
+
dependencyType: "stateVariable",
|
|
883
|
+
variableName: "tailShadow",
|
|
884
|
+
},
|
|
885
|
+
tailAttr: {
|
|
886
|
+
dependencyType: "attributeComponent",
|
|
887
|
+
attributeName: "tail",
|
|
888
|
+
variableNames: ["numDimensions"],
|
|
889
|
+
},
|
|
890
|
+
};
|
|
891
|
+
|
|
892
|
+
if (!stateValues.basedOnTail) {
|
|
893
|
+
if (stateValues.basedOnHead) {
|
|
894
|
+
dependencies.numDimHead = {
|
|
895
|
+
dependencyType: "stateVariable",
|
|
896
|
+
variableName: "numDimHead",
|
|
897
|
+
};
|
|
898
|
+
}
|
|
899
|
+
if (stateValues.basedOnDisplacement) {
|
|
900
|
+
dependencies.numDimDisplacement = {
|
|
901
|
+
dependencyType: "stateVariable",
|
|
902
|
+
variableName: "numDimDisplacement",
|
|
903
|
+
};
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
return dependencies;
|
|
907
|
+
},
|
|
908
|
+
definition: function ({ dependencyValues }) {
|
|
909
|
+
let numDimTail;
|
|
910
|
+
|
|
911
|
+
if (dependencyValues.basedOnTail) {
|
|
912
|
+
if (dependencyValues.tailAttr !== null) {
|
|
913
|
+
numDimTail = dependencyValues.tailAttr.stateValues.numDimensions;
|
|
914
|
+
} else if (dependencyValues.tailShadow) {
|
|
915
|
+
let tailTree = dependencyValues.tailShadow.tree;
|
|
916
|
+
if (
|
|
917
|
+
Array.isArray(tailTree) &&
|
|
918
|
+
vectorOperators.includes(tailTree[0])
|
|
919
|
+
) {
|
|
920
|
+
numDimTail = tailTree.length - 1;
|
|
921
|
+
} else {
|
|
922
|
+
numDimTail = 2;
|
|
923
|
+
}
|
|
924
|
+
}
|
|
925
|
+
} else {
|
|
926
|
+
if (dependencyValues.basedOnDisplacement) {
|
|
927
|
+
if (dependencyValues.basedOnHead) {
|
|
928
|
+
if (
|
|
929
|
+
dependencyValues.numDimDisplacement ===
|
|
930
|
+
dependencyValues.numDimHead
|
|
931
|
+
) {
|
|
932
|
+
numDimTail = dependencyValues.numDimDisplacement;
|
|
933
|
+
} else {
|
|
934
|
+
numDimTail = NaN;
|
|
935
|
+
}
|
|
936
|
+
} else {
|
|
937
|
+
numDimTail = dependencyValues.numDimDisplacement;
|
|
938
|
+
}
|
|
939
|
+
} else if (dependencyValues.basedOnHead) {
|
|
940
|
+
numDimTail = dependencyValues.numDimHead;
|
|
941
|
+
} else {
|
|
942
|
+
numDimTail = 2;
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
|
|
946
|
+
return {
|
|
947
|
+
setValue: { numDimTail },
|
|
948
|
+
checkForActualChange: { numDimTail: true },
|
|
949
|
+
};
|
|
950
|
+
},
|
|
951
|
+
};
|
|
952
|
+
|
|
953
|
+
stateVariableDefinitions.numDimensions = {
|
|
954
|
+
public: true,
|
|
955
|
+
shadowingInstructions: {
|
|
956
|
+
createComponentOfType: "number",
|
|
957
|
+
},
|
|
958
|
+
returnDependencies: () => ({
|
|
959
|
+
basedOnHead: {
|
|
960
|
+
dependencyType: "stateVariable",
|
|
961
|
+
variableName: "basedOnHead",
|
|
962
|
+
},
|
|
963
|
+
basedOnTail: {
|
|
964
|
+
dependencyType: "stateVariable",
|
|
965
|
+
variableName: "basedOnTail",
|
|
966
|
+
},
|
|
967
|
+
basedOnDisplacement: {
|
|
968
|
+
dependencyType: "stateVariable",
|
|
969
|
+
variableName: "basedOnDisplacement",
|
|
970
|
+
},
|
|
971
|
+
numDimDisplacement: {
|
|
972
|
+
dependencyType: "stateVariable",
|
|
973
|
+
variableName: "numDimDisplacement",
|
|
974
|
+
},
|
|
975
|
+
numDimHead: {
|
|
976
|
+
dependencyType: "stateVariable",
|
|
977
|
+
variableName: "numDimHead",
|
|
978
|
+
},
|
|
979
|
+
numDimTail: {
|
|
980
|
+
dependencyType: "stateVariable",
|
|
981
|
+
variableName: "numDimTail",
|
|
982
|
+
},
|
|
983
|
+
}),
|
|
984
|
+
definition: function ({ dependencyValues }) {
|
|
985
|
+
// console.log(`numDimensions definition`)
|
|
986
|
+
// console.log(dependencyValues)
|
|
987
|
+
|
|
988
|
+
let numDimensions;
|
|
989
|
+
if (dependencyValues.basedOnDisplacement) {
|
|
990
|
+
if (dependencyValues.basedOnTail) {
|
|
991
|
+
// ignore head if have both displacement and tail
|
|
992
|
+
if (
|
|
993
|
+
dependencyValues.numDimDisplacement !==
|
|
994
|
+
dependencyValues.numDimTail
|
|
995
|
+
) {
|
|
996
|
+
console.warn(`numDimensions mismatch in vector`);
|
|
997
|
+
return { setValue: { numDimensions: NaN } };
|
|
998
|
+
}
|
|
999
|
+
} else if (dependencyValues.basedOnHead) {
|
|
1000
|
+
if (
|
|
1001
|
+
dependencyValues.numDimDisplacement !==
|
|
1002
|
+
dependencyValues.numDimHead
|
|
1003
|
+
) {
|
|
1004
|
+
console.warn(`numDimensions mismatch in vector`);
|
|
1005
|
+
return { setValue: { numDimensions: NaN } };
|
|
1006
|
+
}
|
|
1007
|
+
}
|
|
1008
|
+
numDimensions = dependencyValues.numDimDisplacement;
|
|
1009
|
+
} else if (dependencyValues.basedOnTail) {
|
|
1010
|
+
if (dependencyValues.basedOnHead) {
|
|
1011
|
+
if (dependencyValues.numDimTail !== dependencyValues.numDimHead) {
|
|
1012
|
+
console.warn(`numDimensions mismatch in vector`);
|
|
1013
|
+
return { setValue: { numDimensions: NaN } };
|
|
1014
|
+
}
|
|
1015
|
+
}
|
|
1016
|
+
numDimensions = dependencyValues.numDimTail;
|
|
1017
|
+
} else if (dependencyValues.basedOnHead) {
|
|
1018
|
+
numDimensions = dependencyValues.numDimHead;
|
|
1019
|
+
} else {
|
|
1020
|
+
numDimensions = 2;
|
|
1021
|
+
}
|
|
1022
|
+
|
|
1023
|
+
return {
|
|
1024
|
+
setValue: { numDimensions },
|
|
1025
|
+
checkForActualChange: { numDimensions: true },
|
|
1026
|
+
};
|
|
1027
|
+
},
|
|
1028
|
+
};
|
|
1029
|
+
|
|
1030
|
+
// allowed possibilities for specified properties
|
|
1031
|
+
// nothing (tail set to zero, displacement/xs set to (1,0s), head set to tail+displacement/xs)
|
|
1032
|
+
// head (tail set to zero, displacement/xs set to head-tail)
|
|
1033
|
+
// tail (displacement/xs set to (1,0s), head set to tail+displacement/xs)
|
|
1034
|
+
// displacement/xs (tail set to zero, head set to tail+displacement)
|
|
1035
|
+
// head and tail (displacement/xs set to head-tail)
|
|
1036
|
+
// head and displacement/xs (tail set to head-displacement)
|
|
1037
|
+
// tail and displacement/xs (head set to tail+displacement)
|
|
1038
|
+
// If head, tail, and displacment/xs supplied, ignore head
|
|
1039
|
+
|
|
1040
|
+
stateVariableDefinitions.displacement = {
|
|
1041
|
+
public: true,
|
|
1042
|
+
isLocation: true,
|
|
1043
|
+
shadowingInstructions: {
|
|
1044
|
+
createComponentOfType: "math",
|
|
1045
|
+
attributesToShadow: ["displayWithAngleBrackets"],
|
|
1046
|
+
addAttributeComponentsShadowingStateVariables:
|
|
1047
|
+
returnRoundingAttributeComponentShadowing(),
|
|
1048
|
+
returnWrappingComponents(prefix) {
|
|
1049
|
+
if (prefix === "x") {
|
|
1050
|
+
return [];
|
|
1051
|
+
} else {
|
|
1052
|
+
// entire array
|
|
1053
|
+
// wrap by both <vector> and <xs>
|
|
1054
|
+
return [
|
|
1055
|
+
["vector", { componentType: "mathList", isAttribute: "xs" }],
|
|
1056
|
+
];
|
|
1057
|
+
}
|
|
1058
|
+
},
|
|
1059
|
+
},
|
|
1060
|
+
isArray: true,
|
|
1061
|
+
entryPrefixes: ["x"],
|
|
1062
|
+
hasEssential: true,
|
|
1063
|
+
essentialVarName: "displacement2", // since "displacement" used for displacementShadow
|
|
1064
|
+
set: convertValueToMathExpression,
|
|
1065
|
+
stateVariablesDeterminingDependencies: [
|
|
1066
|
+
"basedOnDisplacement",
|
|
1067
|
+
"basedOnHead",
|
|
1068
|
+
"sourceOfDisplacement",
|
|
1069
|
+
],
|
|
1070
|
+
returnArraySizeDependencies: () => ({
|
|
1071
|
+
numDimDisplacement: {
|
|
1072
|
+
dependencyType: "stateVariable",
|
|
1073
|
+
variableName: "numDimDisplacement",
|
|
1074
|
+
},
|
|
1075
|
+
}),
|
|
1076
|
+
returnArraySize({ dependencyValues }) {
|
|
1077
|
+
return [dependencyValues.numDimDisplacement];
|
|
1078
|
+
},
|
|
1079
|
+
returnArrayDependenciesByKey({ arrayKeys, stateValues }) {
|
|
1080
|
+
let globalDependencies = {
|
|
1081
|
+
basedOnHead: {
|
|
1082
|
+
dependencyType: "stateVariable",
|
|
1083
|
+
variableName: "basedOnHead",
|
|
1084
|
+
},
|
|
1085
|
+
basedOnTail: {
|
|
1086
|
+
dependencyType: "stateVariable",
|
|
1087
|
+
variableName: "basedOnTail",
|
|
1088
|
+
},
|
|
1089
|
+
basedOnDisplacement: {
|
|
1090
|
+
dependencyType: "stateVariable",
|
|
1091
|
+
variableName: "basedOnDisplacement",
|
|
1092
|
+
},
|
|
1093
|
+
displacementShadow: {
|
|
1094
|
+
dependencyType: "stateVariable",
|
|
1095
|
+
variableName: "displacementShadow",
|
|
1096
|
+
},
|
|
1097
|
+
displacementAttr: {
|
|
1098
|
+
dependencyType: "attributeComponent",
|
|
1099
|
+
attributeName: "displacement",
|
|
1100
|
+
variableNames: ["value"],
|
|
1101
|
+
},
|
|
1102
|
+
sourceOfDisplacement: {
|
|
1103
|
+
dependencyType: "stateVariable",
|
|
1104
|
+
variableName: "sourceOfDisplacement",
|
|
1105
|
+
},
|
|
1106
|
+
};
|
|
1107
|
+
|
|
1108
|
+
let dependenciesByKey = {};
|
|
1109
|
+
|
|
1110
|
+
for (let arrayKey of arrayKeys) {
|
|
1111
|
+
let varEnding = Number(arrayKey) + 1;
|
|
1112
|
+
dependenciesByKey[arrayKey] = {
|
|
1113
|
+
xsAttr: {
|
|
1114
|
+
dependencyType: "attributeComponent",
|
|
1115
|
+
attributeName: "xs",
|
|
1116
|
+
variableNames: ["math" + varEnding],
|
|
1117
|
+
},
|
|
1118
|
+
pointOrVectorChild: {
|
|
1119
|
+
dependencyType: "child",
|
|
1120
|
+
childGroups: ["pointsAndVectors"],
|
|
1121
|
+
variableNames: ["x" + varEnding],
|
|
1122
|
+
},
|
|
1123
|
+
};
|
|
1124
|
+
if (arrayKey === "0") {
|
|
1125
|
+
dependenciesByKey[arrayKey].componentAttr = {
|
|
1126
|
+
dependencyType: "attributeComponent",
|
|
1127
|
+
attributeName: "x",
|
|
1128
|
+
variableNames: ["value"],
|
|
1129
|
+
};
|
|
1130
|
+
} else if (arrayKey === "1") {
|
|
1131
|
+
dependenciesByKey[arrayKey].componentAttr = {
|
|
1132
|
+
dependencyType: "attributeComponent",
|
|
1133
|
+
attributeName: "y",
|
|
1134
|
+
variableNames: ["value"],
|
|
1135
|
+
};
|
|
1136
|
+
} else if (arrayKey === "2") {
|
|
1137
|
+
dependenciesByKey[arrayKey].componentAttr = {
|
|
1138
|
+
dependencyType: "attributeComponent",
|
|
1139
|
+
attributeName: "z",
|
|
1140
|
+
variableNames: ["value"],
|
|
1141
|
+
};
|
|
1142
|
+
}
|
|
1143
|
+
|
|
1144
|
+
if (!stateValues.basedOnDisplacement && stateValues.basedOnHead) {
|
|
1145
|
+
// if not based on displacement and based on head,
|
|
1146
|
+
// will always use head and tail values
|
|
1147
|
+
// even if not based on tail,
|
|
1148
|
+
// as tail will be made essential (with default of zero)
|
|
1149
|
+
dependenciesByKey[arrayKey].tailX = {
|
|
1150
|
+
dependencyType: "stateVariable",
|
|
1151
|
+
variableName: "tailX" + varEnding,
|
|
1152
|
+
};
|
|
1153
|
+
dependenciesByKey[arrayKey].headX = {
|
|
1154
|
+
dependencyType: "stateVariable",
|
|
1155
|
+
variableName: "headX" + varEnding,
|
|
1156
|
+
};
|
|
1157
|
+
}
|
|
1158
|
+
}
|
|
1159
|
+
|
|
1160
|
+
return { globalDependencies, dependenciesByKey };
|
|
1161
|
+
},
|
|
1162
|
+
arrayDefinitionByKey: function ({
|
|
1163
|
+
globalDependencyValues,
|
|
1164
|
+
dependencyValuesByKey,
|
|
1165
|
+
arrayKeys,
|
|
1166
|
+
}) {
|
|
1167
|
+
// console.log('array definition of vector displacement', componentName)
|
|
1168
|
+
// console.log(globalDependencyValues, dependencyValuesByKey, arrayKeys)
|
|
1169
|
+
|
|
1170
|
+
let displacement = {};
|
|
1171
|
+
let essentialDisplacement = {};
|
|
1172
|
+
|
|
1173
|
+
let prescribedDisplacement;
|
|
1174
|
+
if (globalDependencyValues.basedOnDisplacement) {
|
|
1175
|
+
if (
|
|
1176
|
+
globalDependencyValues.sourceOfDisplacement === "displacementAttr"
|
|
1177
|
+
) {
|
|
1178
|
+
prescribedDisplacement =
|
|
1179
|
+
globalDependencyValues.displacementAttr.stateValues.value;
|
|
1180
|
+
} else if (globalDependencyValues.sourceOfDisplacement === null) {
|
|
1181
|
+
prescribedDisplacement =
|
|
1182
|
+
globalDependencyValues.displacementShadow.tuples_to_vectors();
|
|
1183
|
+
}
|
|
1184
|
+
}
|
|
1185
|
+
|
|
1186
|
+
if (prescribedDisplacement) {
|
|
1187
|
+
prescribedDisplacement = prescribedDisplacement.expand().simplify();
|
|
1188
|
+
let displacementTree = prescribedDisplacement.tree;
|
|
1189
|
+
if (
|
|
1190
|
+
Array.isArray(displacementTree) &&
|
|
1191
|
+
vectorOperators.includes(displacementTree[0])
|
|
1192
|
+
) {
|
|
1193
|
+
for (let arrayKey of arrayKeys) {
|
|
1194
|
+
let ind = Number(arrayKey);
|
|
1195
|
+
if (ind >= 0 || ind < displacementTree.length - 1) {
|
|
1196
|
+
if (displacementTree[ind + 1] === undefined) {
|
|
1197
|
+
displacement[arrayKey] = me.fromAst("\uff3f");
|
|
1198
|
+
} else {
|
|
1199
|
+
displacement[arrayKey] =
|
|
1200
|
+
prescribedDisplacement.get_component(ind);
|
|
1201
|
+
}
|
|
1202
|
+
}
|
|
1203
|
+
}
|
|
1204
|
+
} else {
|
|
1205
|
+
if (arrayKeys.includes("0")) {
|
|
1206
|
+
displacement[0] = prescribedDisplacement;
|
|
1207
|
+
}
|
|
1208
|
+
}
|
|
1209
|
+
} else {
|
|
1210
|
+
for (let arrayKey of arrayKeys) {
|
|
1211
|
+
let varEnding = Number(arrayKey) + 1;
|
|
1212
|
+
|
|
1213
|
+
if (globalDependencyValues.basedOnDisplacement) {
|
|
1214
|
+
switch (globalDependencyValues.sourceOfDisplacement) {
|
|
1215
|
+
case "pointOrVectorChild":
|
|
1216
|
+
displacement[arrayKey] =
|
|
1217
|
+
dependencyValuesByKey[
|
|
1218
|
+
arrayKey
|
|
1219
|
+
].pointOrVectorChild[0].stateValues["x" + varEnding];
|
|
1220
|
+
break;
|
|
1221
|
+
case "xsAttr":
|
|
1222
|
+
displacement[arrayKey] =
|
|
1223
|
+
dependencyValuesByKey[arrayKey].xsAttr.stateValues[
|
|
1224
|
+
"math" + varEnding
|
|
1225
|
+
].simplify();
|
|
1226
|
+
break;
|
|
1227
|
+
case "componentAttrs":
|
|
1228
|
+
let componentAttr =
|
|
1229
|
+
dependencyValuesByKey[arrayKey].componentAttr;
|
|
1230
|
+
if (componentAttr === null) {
|
|
1231
|
+
// based on component attributes, but don't have
|
|
1232
|
+
// this particular one specified
|
|
1233
|
+
essentialDisplacement[arrayKey] = {
|
|
1234
|
+
defaultValue: me.fromAst(0),
|
|
1235
|
+
};
|
|
1236
|
+
} else {
|
|
1237
|
+
displacement[arrayKey] =
|
|
1238
|
+
componentAttr.stateValues.value.simplify();
|
|
1239
|
+
}
|
|
1240
|
+
break;
|
|
1241
|
+
}
|
|
1242
|
+
} else if (globalDependencyValues.basedOnHead) {
|
|
1243
|
+
// basedOnDisplacement is false and based on head
|
|
1244
|
+
// calculate displacement from head and tail
|
|
1245
|
+
displacement[arrayKey] = dependencyValuesByKey[arrayKey].headX
|
|
1246
|
+
.subtract(dependencyValuesByKey[arrayKey].tailX)
|
|
1247
|
+
.simplify();
|
|
1248
|
+
} else {
|
|
1249
|
+
// not based on displacement or head, use essential value
|
|
1250
|
+
essentialDisplacement[arrayKey] = {
|
|
1251
|
+
defaultValue: me.fromAst(arrayKey === "0" ? 1 : 0),
|
|
1252
|
+
};
|
|
1253
|
+
}
|
|
1254
|
+
}
|
|
1255
|
+
}
|
|
1256
|
+
|
|
1257
|
+
let result = {};
|
|
1258
|
+
|
|
1259
|
+
if (Object.keys(displacement).length > 0) {
|
|
1260
|
+
result.setValue = { displacement };
|
|
1261
|
+
}
|
|
1262
|
+
if (Object.keys(essentialDisplacement).length > 0) {
|
|
1263
|
+
result.useEssentialOrDefaultValue = {
|
|
1264
|
+
displacement: essentialDisplacement,
|
|
1265
|
+
};
|
|
1266
|
+
}
|
|
1267
|
+
|
|
1268
|
+
return result;
|
|
1269
|
+
},
|
|
1270
|
+
inverseArrayDefinitionByKey({
|
|
1271
|
+
desiredStateVariableValues,
|
|
1272
|
+
globalDependencyValues,
|
|
1273
|
+
dependencyValuesByKey,
|
|
1274
|
+
dependencyNamesByKey,
|
|
1275
|
+
arraySize,
|
|
1276
|
+
}) {
|
|
1277
|
+
// console.log(`inverse array definition of displacement`)
|
|
1278
|
+
// console.log(JSON.parse(JSON.stringify(desiredStateVariableValues)))
|
|
1279
|
+
// console.log(JSON.parse(JSON.stringify(globalDependencyValues)))
|
|
1280
|
+
// console.log(JSON.parse(JSON.stringify(dependencyValuesByKey)))
|
|
1281
|
+
|
|
1282
|
+
let instructions = [];
|
|
1283
|
+
|
|
1284
|
+
if (globalDependencyValues.basedOnDisplacement) {
|
|
1285
|
+
if (
|
|
1286
|
+
globalDependencyValues.sourceOfDisplacement === "displacementAttr"
|
|
1287
|
+
) {
|
|
1288
|
+
if (arraySize[0] > 1) {
|
|
1289
|
+
let desiredDisplacement = ["vector"];
|
|
1290
|
+
for (let arrayKey in desiredStateVariableValues.displacement) {
|
|
1291
|
+
desiredDisplacement[Number(arrayKey) + 1] =
|
|
1292
|
+
desiredStateVariableValues.displacement[arrayKey].tree;
|
|
1293
|
+
}
|
|
1294
|
+
desiredDisplacement.length = arraySize[0] + 1;
|
|
1295
|
+
instructions.push({
|
|
1296
|
+
setDependency: "displacementAttr",
|
|
1297
|
+
desiredValue: me.fromAst(desiredDisplacement),
|
|
1298
|
+
variableIndex: 0,
|
|
1299
|
+
});
|
|
1300
|
+
} else if (
|
|
1301
|
+
arraySize[0] === 1 &&
|
|
1302
|
+
"0" in desiredStateVariableValues.displacement
|
|
1303
|
+
) {
|
|
1304
|
+
instructions.push({
|
|
1305
|
+
setDependency: "displacementAttr",
|
|
1306
|
+
desiredValue: desiredStateVariableValues.displacement[0],
|
|
1307
|
+
variableIndex: 0,
|
|
1308
|
+
});
|
|
1309
|
+
}
|
|
1310
|
+
return {
|
|
1311
|
+
success: true,
|
|
1312
|
+
instructions,
|
|
1313
|
+
};
|
|
1314
|
+
} else if (globalDependencyValues.sourceOfDisplacement === null) {
|
|
1315
|
+
if (arraySize[0] > 1) {
|
|
1316
|
+
let desiredDisplacement = ["vector"];
|
|
1317
|
+
for (let arrayKey in desiredStateVariableValues.displacement) {
|
|
1318
|
+
desiredDisplacement[Number(arrayKey) + 1] =
|
|
1319
|
+
desiredStateVariableValues.displacement[arrayKey].tree;
|
|
1320
|
+
}
|
|
1321
|
+
desiredDisplacement.length = arraySize[0] + 1;
|
|
1322
|
+
instructions.push({
|
|
1323
|
+
setDependency: "displacementShadow",
|
|
1324
|
+
desiredValue: me.fromAst(desiredDisplacement),
|
|
1325
|
+
});
|
|
1326
|
+
} else if (
|
|
1327
|
+
arraySize[0] === 1 &&
|
|
1328
|
+
"0" in desiredStateVariableValues.displacement
|
|
1329
|
+
) {
|
|
1330
|
+
instructions.push({
|
|
1331
|
+
setDependency: "displacementShadow",
|
|
1332
|
+
desiredValue: desiredStateVariableValues.displacement[0],
|
|
1333
|
+
});
|
|
1334
|
+
}
|
|
1335
|
+
return {
|
|
1336
|
+
success: true,
|
|
1337
|
+
instructions,
|
|
1338
|
+
};
|
|
1339
|
+
}
|
|
1340
|
+
}
|
|
1341
|
+
|
|
1342
|
+
for (let arrayKey in desiredStateVariableValues.displacement) {
|
|
1343
|
+
if (globalDependencyValues.basedOnDisplacement) {
|
|
1344
|
+
switch (globalDependencyValues.sourceOfDisplacement) {
|
|
1345
|
+
case "pointOrVectorChild":
|
|
1346
|
+
instructions.push({
|
|
1347
|
+
setDependency:
|
|
1348
|
+
dependencyNamesByKey[arrayKey].pointOrVectorChild,
|
|
1349
|
+
desiredValue:
|
|
1350
|
+
desiredStateVariableValues.displacement[arrayKey],
|
|
1351
|
+
childIndex: 0,
|
|
1352
|
+
variableIndex: 0,
|
|
1353
|
+
});
|
|
1354
|
+
break;
|
|
1355
|
+
case "xsAttr":
|
|
1356
|
+
instructions.push({
|
|
1357
|
+
setDependency: dependencyNamesByKey[arrayKey].xsAttr,
|
|
1358
|
+
desiredValue:
|
|
1359
|
+
desiredStateVariableValues.displacement[arrayKey],
|
|
1360
|
+
variableIndex: 0,
|
|
1361
|
+
});
|
|
1362
|
+
break;
|
|
1363
|
+
case "componentAttrs":
|
|
1364
|
+
let componentAttr =
|
|
1365
|
+
dependencyValuesByKey[arrayKey].componentAttr;
|
|
1366
|
+
if (componentAttr === null) {
|
|
1367
|
+
// based on component attributes, but don't have
|
|
1368
|
+
// this particular one specified
|
|
1369
|
+
instructions.push({
|
|
1370
|
+
setEssentialValue: "displacement",
|
|
1371
|
+
value: {
|
|
1372
|
+
[arrayKey]: convertValueToMathExpression(
|
|
1373
|
+
desiredStateVariableValues.displacement[arrayKey],
|
|
1374
|
+
),
|
|
1375
|
+
},
|
|
1376
|
+
});
|
|
1377
|
+
} else {
|
|
1378
|
+
instructions.push({
|
|
1379
|
+
setDependency: dependencyNamesByKey[arrayKey].componentAttr,
|
|
1380
|
+
desiredValue:
|
|
1381
|
+
desiredStateVariableValues.displacement[arrayKey],
|
|
1382
|
+
variableIndex: 0,
|
|
1383
|
+
});
|
|
1384
|
+
}
|
|
1385
|
+
break;
|
|
1386
|
+
}
|
|
1387
|
+
} else if (globalDependencyValues.basedOnHead) {
|
|
1388
|
+
// basedOnDisplacement is false and based on head
|
|
1389
|
+
// set head to be sum of tail and desired displacement
|
|
1390
|
+
instructions.push({
|
|
1391
|
+
setDependency: dependencyNamesByKey[arrayKey].headX,
|
|
1392
|
+
desiredValue: dependencyValuesByKey[arrayKey].tailX
|
|
1393
|
+
.add(desiredStateVariableValues.displacement[arrayKey])
|
|
1394
|
+
.simplify(),
|
|
1395
|
+
});
|
|
1396
|
+
} else {
|
|
1397
|
+
// not based on displacement or head
|
|
1398
|
+
// set essential value
|
|
1399
|
+
|
|
1400
|
+
instructions.push({
|
|
1401
|
+
setEssentialValue: "displacement",
|
|
1402
|
+
value: {
|
|
1403
|
+
[arrayKey]: convertValueToMathExpression(
|
|
1404
|
+
desiredStateVariableValues.displacement[arrayKey],
|
|
1405
|
+
),
|
|
1406
|
+
},
|
|
1407
|
+
});
|
|
1408
|
+
}
|
|
1409
|
+
}
|
|
1410
|
+
|
|
1411
|
+
return {
|
|
1412
|
+
success: true,
|
|
1413
|
+
instructions,
|
|
1414
|
+
};
|
|
1415
|
+
},
|
|
1416
|
+
};
|
|
1417
|
+
|
|
1418
|
+
stateVariableDefinitions.x = {
|
|
1419
|
+
isAlias: true,
|
|
1420
|
+
targetVariableName: "x1",
|
|
1421
|
+
};
|
|
1422
|
+
|
|
1423
|
+
stateVariableDefinitions.y = {
|
|
1424
|
+
isAlias: true,
|
|
1425
|
+
targetVariableName: "x2",
|
|
1426
|
+
};
|
|
1427
|
+
|
|
1428
|
+
stateVariableDefinitions.z = {
|
|
1429
|
+
isAlias: true,
|
|
1430
|
+
targetVariableName: "x3",
|
|
1431
|
+
};
|
|
1432
|
+
|
|
1433
|
+
stateVariableDefinitions.head = {
|
|
1434
|
+
public: true,
|
|
1435
|
+
isLocation: true,
|
|
1436
|
+
shadowingInstructions: {
|
|
1437
|
+
createComponentOfType: "math",
|
|
1438
|
+
addAttributeComponentsShadowingStateVariables:
|
|
1439
|
+
returnRoundingAttributeComponentShadowing(),
|
|
1440
|
+
returnWrappingComponents(prefix) {
|
|
1441
|
+
if (prefix === "headX") {
|
|
1442
|
+
return [];
|
|
1443
|
+
} else {
|
|
1444
|
+
// entire array
|
|
1445
|
+
// wrap by both <point> and <xs>
|
|
1446
|
+
return [
|
|
1447
|
+
["point", { componentType: "mathList", isAttribute: "xs" }],
|
|
1448
|
+
];
|
|
1449
|
+
}
|
|
1450
|
+
},
|
|
1451
|
+
},
|
|
1452
|
+
isArray: true,
|
|
1453
|
+
entryPrefixes: ["headX"],
|
|
1454
|
+
set: convertValueToMathExpression,
|
|
1455
|
+
stateVariablesDeterminingDependencies: ["basedOnHead"],
|
|
1456
|
+
returnArraySizeDependencies: () => ({
|
|
1457
|
+
numDimHead: {
|
|
1458
|
+
dependencyType: "stateVariable",
|
|
1459
|
+
variableName: "numDimHead",
|
|
1460
|
+
},
|
|
1461
|
+
}),
|
|
1462
|
+
returnArraySize({ dependencyValues }) {
|
|
1463
|
+
return [dependencyValues.numDimHead];
|
|
1464
|
+
},
|
|
1465
|
+
returnArrayDependenciesByKey({ arrayKeys, stateValues }) {
|
|
1466
|
+
let globalDependencies = {
|
|
1467
|
+
basedOnDisplacement: {
|
|
1468
|
+
dependencyType: "stateVariable",
|
|
1469
|
+
variableName: "basedOnDisplacement",
|
|
1470
|
+
},
|
|
1471
|
+
basedOnTail: {
|
|
1472
|
+
dependencyType: "stateVariable",
|
|
1473
|
+
variableName: "basedOnTail",
|
|
1474
|
+
},
|
|
1475
|
+
basedOnHead: {
|
|
1476
|
+
dependencyType: "stateVariable",
|
|
1477
|
+
variableName: "basedOnHead",
|
|
1478
|
+
},
|
|
1479
|
+
headShadow: {
|
|
1480
|
+
dependencyType: "stateVariable",
|
|
1481
|
+
variableName: "headShadow",
|
|
1482
|
+
},
|
|
1483
|
+
};
|
|
1484
|
+
|
|
1485
|
+
let dependenciesByKey = {};
|
|
1486
|
+
|
|
1487
|
+
for (let arrayKey of arrayKeys) {
|
|
1488
|
+
let varEnding = Number(arrayKey) + 1;
|
|
1489
|
+
dependenciesByKey[arrayKey] = {
|
|
1490
|
+
headAttr: {
|
|
1491
|
+
dependencyType: "attributeComponent",
|
|
1492
|
+
attributeName: "head",
|
|
1493
|
+
variableNames: ["x" + varEnding],
|
|
1494
|
+
},
|
|
1495
|
+
};
|
|
1496
|
+
|
|
1497
|
+
if (!stateValues.basedOnHead) {
|
|
1498
|
+
// if not based on head, will always use tail and displacement value
|
|
1499
|
+
// as, even if not based on tail or displacment,
|
|
1500
|
+
// they will be made essential
|
|
1501
|
+
dependenciesByKey[arrayKey].tailX = {
|
|
1502
|
+
dependencyType: "stateVariable",
|
|
1503
|
+
variableName: "tailX" + varEnding,
|
|
1504
|
+
};
|
|
1505
|
+
dependenciesByKey[arrayKey].x = {
|
|
1506
|
+
dependencyType: "stateVariable",
|
|
1507
|
+
variableName: "x" + varEnding,
|
|
1508
|
+
};
|
|
1509
|
+
}
|
|
1510
|
+
}
|
|
1511
|
+
|
|
1512
|
+
return { globalDependencies, dependenciesByKey };
|
|
1513
|
+
},
|
|
1514
|
+
arrayDefinitionByKey: function ({
|
|
1515
|
+
globalDependencyValues,
|
|
1516
|
+
dependencyValuesByKey,
|
|
1517
|
+
arrayKeys,
|
|
1518
|
+
}) {
|
|
1519
|
+
// console.log('array definition of vector head')
|
|
1520
|
+
// console.log(globalDependencyValues, dependencyValuesByKey, arrayKeys)
|
|
1521
|
+
|
|
1522
|
+
let head = {};
|
|
1523
|
+
|
|
1524
|
+
for (let arrayKey of arrayKeys) {
|
|
1525
|
+
let varEnding = Number(arrayKey) + 1;
|
|
1526
|
+
|
|
1527
|
+
if (globalDependencyValues.basedOnHead) {
|
|
1528
|
+
if (dependencyValuesByKey[arrayKey].headAttr !== null) {
|
|
1529
|
+
head[arrayKey] =
|
|
1530
|
+
dependencyValuesByKey[arrayKey].headAttr.stateValues[
|
|
1531
|
+
"x" + varEnding
|
|
1532
|
+
];
|
|
1533
|
+
} else if (globalDependencyValues.headShadow !== null) {
|
|
1534
|
+
head[arrayKey] = globalDependencyValues.headShadow.get_component(
|
|
1535
|
+
Number(arrayKey),
|
|
1536
|
+
);
|
|
1537
|
+
}
|
|
1538
|
+
} else {
|
|
1539
|
+
// basedOnHead is false
|
|
1540
|
+
|
|
1541
|
+
// displacement and tail: add to create head
|
|
1542
|
+
// it doesn't matter if based on tail or displacement
|
|
1543
|
+
// as will use their essential values
|
|
1544
|
+
|
|
1545
|
+
head[arrayKey] = dependencyValuesByKey[arrayKey].tailX
|
|
1546
|
+
.add(dependencyValuesByKey[arrayKey].x)
|
|
1547
|
+
.simplify();
|
|
1548
|
+
}
|
|
1549
|
+
}
|
|
1550
|
+
|
|
1551
|
+
return { setValue: { head } };
|
|
1552
|
+
},
|
|
1553
|
+
|
|
1554
|
+
inverseArrayDefinitionByKey({
|
|
1555
|
+
desiredStateVariableValues,
|
|
1556
|
+
globalDependencyValues,
|
|
1557
|
+
dependencyValuesByKey,
|
|
1558
|
+
dependencyNamesByKey,
|
|
1559
|
+
arraySize,
|
|
1560
|
+
}) {
|
|
1561
|
+
// console.log(`inverse array definition of head`, desiredStateVariableValues,
|
|
1562
|
+
// globalDependencyValues, dependencyValuesByKey
|
|
1563
|
+
// )
|
|
1564
|
+
|
|
1565
|
+
let instructions = [];
|
|
1566
|
+
|
|
1567
|
+
let updateHeadShadow = false;
|
|
1568
|
+
|
|
1569
|
+
for (let arrayKey in desiredStateVariableValues.head) {
|
|
1570
|
+
if (globalDependencyValues.basedOnHead) {
|
|
1571
|
+
if (
|
|
1572
|
+
dependencyValuesByKey[arrayKey].headAttr &&
|
|
1573
|
+
dependencyValuesByKey[arrayKey].headAttr !== null
|
|
1574
|
+
) {
|
|
1575
|
+
instructions.push({
|
|
1576
|
+
setDependency: dependencyNamesByKey[arrayKey].headAttr,
|
|
1577
|
+
desiredValue: desiredStateVariableValues.head[arrayKey],
|
|
1578
|
+
variableIndex: 0,
|
|
1579
|
+
});
|
|
1580
|
+
} else if (globalDependencyValues.headShadow !== null) {
|
|
1581
|
+
updateHeadShadow = true;
|
|
1582
|
+
}
|
|
1583
|
+
} else {
|
|
1584
|
+
// not based on head
|
|
1585
|
+
|
|
1586
|
+
// based on displacement and tail (or their essential values):
|
|
1587
|
+
// set displacement to be desired head - tail
|
|
1588
|
+
|
|
1589
|
+
instructions.push({
|
|
1590
|
+
setDependency: dependencyNamesByKey[arrayKey].x,
|
|
1591
|
+
desiredValue: desiredStateVariableValues.head[arrayKey]
|
|
1592
|
+
.subtract(dependencyValuesByKey[arrayKey].tailX)
|
|
1593
|
+
.simplify(),
|
|
1594
|
+
});
|
|
1595
|
+
}
|
|
1596
|
+
}
|
|
1597
|
+
|
|
1598
|
+
if (updateHeadShadow) {
|
|
1599
|
+
if (arraySize[0] > 1) {
|
|
1600
|
+
let desiredHead = ["vector"];
|
|
1601
|
+
for (let arrayKey in desiredStateVariableValues.head) {
|
|
1602
|
+
desiredHead[Number(arrayKey) + 1] =
|
|
1603
|
+
desiredStateVariableValues.head[arrayKey].tree;
|
|
1604
|
+
}
|
|
1605
|
+
desiredHead.length = arraySize[0] + 1;
|
|
1606
|
+
instructions.push({
|
|
1607
|
+
setDependency: "headShadow",
|
|
1608
|
+
desiredValue: me.fromAst(desiredHead),
|
|
1609
|
+
});
|
|
1610
|
+
} else if (
|
|
1611
|
+
arraySize[0] === 1 &&
|
|
1612
|
+
"0" in desiredStateVariableValues.head
|
|
1613
|
+
) {
|
|
1614
|
+
instructions.push({
|
|
1615
|
+
setDependency: "headShadow",
|
|
1616
|
+
desiredValue: desiredStateVariableValues.head[0],
|
|
1617
|
+
});
|
|
1618
|
+
}
|
|
1619
|
+
}
|
|
1620
|
+
|
|
1621
|
+
return {
|
|
1622
|
+
success: true,
|
|
1623
|
+
instructions,
|
|
1624
|
+
};
|
|
1625
|
+
},
|
|
1626
|
+
};
|
|
1627
|
+
|
|
1628
|
+
stateVariableDefinitions.tail = {
|
|
1629
|
+
public: true,
|
|
1630
|
+
isLocation: true,
|
|
1631
|
+
shadowingInstructions: {
|
|
1632
|
+
createComponentOfType: "math",
|
|
1633
|
+
addAttributeComponentsShadowingStateVariables:
|
|
1634
|
+
returnRoundingAttributeComponentShadowing(),
|
|
1635
|
+
returnWrappingComponents(prefix) {
|
|
1636
|
+
if (prefix === "tailX") {
|
|
1637
|
+
return [];
|
|
1638
|
+
} else {
|
|
1639
|
+
// entire array
|
|
1640
|
+
// wrap by both <point> and <xs>
|
|
1641
|
+
return [
|
|
1642
|
+
["point", { componentType: "mathList", isAttribute: "xs" }],
|
|
1643
|
+
];
|
|
1644
|
+
}
|
|
1645
|
+
},
|
|
1646
|
+
},
|
|
1647
|
+
isArray: true,
|
|
1648
|
+
entryPrefixes: ["tailX"],
|
|
1649
|
+
hasEssential: true,
|
|
1650
|
+
defaultValueByArrayKey: () => me.fromAst(0),
|
|
1651
|
+
essentialVarName: "tail2", // since tailShadow uses "tail"
|
|
1652
|
+
set: convertValueToMathExpression,
|
|
1653
|
+
stateVariablesDeterminingDependencies: [
|
|
1654
|
+
"basedOnTail",
|
|
1655
|
+
"basedOnHead",
|
|
1656
|
+
"basedOnDisplacement",
|
|
1657
|
+
],
|
|
1658
|
+
returnArraySizeDependencies: () => ({
|
|
1659
|
+
numDimTail: {
|
|
1660
|
+
dependencyType: "stateVariable",
|
|
1661
|
+
variableName: "numDimTail",
|
|
1662
|
+
},
|
|
1663
|
+
}),
|
|
1664
|
+
returnArraySize({ dependencyValues }) {
|
|
1665
|
+
return [dependencyValues.numDimTail];
|
|
1666
|
+
},
|
|
1667
|
+
returnArrayDependenciesByKey({ arrayKeys, stateValues }) {
|
|
1668
|
+
let globalDependencies = {
|
|
1669
|
+
basedOnDisplacement: {
|
|
1670
|
+
dependencyType: "stateVariable",
|
|
1671
|
+
variableName: "basedOnDisplacement",
|
|
1672
|
+
},
|
|
1673
|
+
basedOnHead: {
|
|
1674
|
+
dependencyType: "stateVariable",
|
|
1675
|
+
variableName: "basedOnHead",
|
|
1676
|
+
},
|
|
1677
|
+
tailShadow: {
|
|
1678
|
+
dependencyType: "stateVariable",
|
|
1679
|
+
variableName: "tailShadow",
|
|
1680
|
+
},
|
|
1681
|
+
};
|
|
1682
|
+
|
|
1683
|
+
let dependenciesByKey = {};
|
|
1684
|
+
|
|
1685
|
+
for (let arrayKey of arrayKeys) {
|
|
1686
|
+
let varEnding = Number(arrayKey) + 1;
|
|
1687
|
+
|
|
1688
|
+
dependenciesByKey[arrayKey] = {
|
|
1689
|
+
tailAttr: {
|
|
1690
|
+
dependencyType: "attributeComponent",
|
|
1691
|
+
attributeName: "tail",
|
|
1692
|
+
variableNames: ["x" + varEnding],
|
|
1693
|
+
},
|
|
1694
|
+
};
|
|
1695
|
+
|
|
1696
|
+
if (!stateValues.basedOnTail) {
|
|
1697
|
+
if (stateValues.basedOnHead && stateValues.basedOnDisplacement) {
|
|
1698
|
+
dependenciesByKey[arrayKey].headX = {
|
|
1699
|
+
dependencyType: "stateVariable",
|
|
1700
|
+
variableName: "headX" + varEnding,
|
|
1701
|
+
};
|
|
1702
|
+
dependenciesByKey[arrayKey].x = {
|
|
1703
|
+
dependencyType: "stateVariable",
|
|
1704
|
+
variableName: "x" + varEnding,
|
|
1705
|
+
};
|
|
1706
|
+
}
|
|
1707
|
+
}
|
|
1708
|
+
}
|
|
1709
|
+
|
|
1710
|
+
return { globalDependencies, dependenciesByKey };
|
|
1711
|
+
},
|
|
1712
|
+
arrayDefinitionByKey: function ({
|
|
1713
|
+
globalDependencyValues,
|
|
1714
|
+
dependencyValuesByKey,
|
|
1715
|
+
arrayKeys,
|
|
1716
|
+
}) {
|
|
1717
|
+
// console.log('array definition of vector tail');
|
|
1718
|
+
// console.log(JSON.parse(JSON.stringify(globalDependencyValues)))
|
|
1719
|
+
// console.log(JSON.parse(JSON.stringify(dependencyValuesByKey)))
|
|
1720
|
+
// console.log(JSON.parse(JSON.stringify(arrayKeys)))
|
|
1721
|
+
|
|
1722
|
+
let tail = {};
|
|
1723
|
+
let essentialTail = {};
|
|
1724
|
+
|
|
1725
|
+
for (let arrayKey of arrayKeys) {
|
|
1726
|
+
let varEnding = Number(arrayKey) + 1;
|
|
1727
|
+
|
|
1728
|
+
if (dependencyValuesByKey[arrayKey].tailAttr !== null) {
|
|
1729
|
+
tail[arrayKey] =
|
|
1730
|
+
dependencyValuesByKey[arrayKey].tailAttr.stateValues[
|
|
1731
|
+
"x" + varEnding
|
|
1732
|
+
];
|
|
1733
|
+
} else if (globalDependencyValues.tailShadow !== null) {
|
|
1734
|
+
tail[arrayKey] = globalDependencyValues.tailShadow.get_component(
|
|
1735
|
+
Number(arrayKey),
|
|
1736
|
+
);
|
|
1737
|
+
} else {
|
|
1738
|
+
// if made it to here, basedOnTail is false
|
|
1739
|
+
|
|
1740
|
+
if (
|
|
1741
|
+
globalDependencyValues.basedOnHead &&
|
|
1742
|
+
globalDependencyValues.basedOnDisplacement
|
|
1743
|
+
) {
|
|
1744
|
+
// based on head and displacement,
|
|
1745
|
+
// subtract displacement from head to get tail
|
|
1746
|
+
tail[arrayKey] = dependencyValuesByKey[arrayKey].headX
|
|
1747
|
+
.subtract(dependencyValuesByKey[arrayKey].x)
|
|
1748
|
+
.simplify();
|
|
1749
|
+
} else {
|
|
1750
|
+
// tail defaults to zero
|
|
1751
|
+
// (but it will use the resulting essential value after that
|
|
1752
|
+
// so any changes will be saved)
|
|
1753
|
+
|
|
1754
|
+
essentialTail[arrayKey] = true;
|
|
1755
|
+
}
|
|
1756
|
+
}
|
|
1757
|
+
}
|
|
1758
|
+
|
|
1759
|
+
let result = {};
|
|
1760
|
+
|
|
1761
|
+
if (Object.keys(tail).length > 0) {
|
|
1762
|
+
result.setValue = { tail };
|
|
1763
|
+
}
|
|
1764
|
+
if (Object.keys(essentialTail).length > 0) {
|
|
1765
|
+
result.useEssentialOrDefaultValue = { tail: essentialTail };
|
|
1766
|
+
}
|
|
1767
|
+
|
|
1768
|
+
return result;
|
|
1769
|
+
},
|
|
1770
|
+
|
|
1771
|
+
inverseArrayDefinitionByKey({
|
|
1772
|
+
desiredStateVariableValues,
|
|
1773
|
+
globalDependencyValues,
|
|
1774
|
+
dependencyValuesByKey,
|
|
1775
|
+
dependencyNamesByKey,
|
|
1776
|
+
arraySize,
|
|
1777
|
+
}) {
|
|
1778
|
+
// console.log(`inverse array definition of tail`, desiredStateVariableValues,
|
|
1779
|
+
// globalDependencyValues, dependencyValuesByKey
|
|
1780
|
+
// )
|
|
1781
|
+
|
|
1782
|
+
let instructions = [];
|
|
1783
|
+
|
|
1784
|
+
let updateTailShadow = false;
|
|
1785
|
+
|
|
1786
|
+
for (let arrayKey in desiredStateVariableValues.tail) {
|
|
1787
|
+
if (
|
|
1788
|
+
dependencyValuesByKey[arrayKey].tailAttr &&
|
|
1789
|
+
dependencyValuesByKey[arrayKey].tailAttr !== null
|
|
1790
|
+
) {
|
|
1791
|
+
instructions.push({
|
|
1792
|
+
setDependency: dependencyNamesByKey[arrayKey].tailAttr,
|
|
1793
|
+
desiredValue: desiredStateVariableValues.tail[arrayKey],
|
|
1794
|
+
variableIndex: 0,
|
|
1795
|
+
});
|
|
1796
|
+
} else if (globalDependencyValues.tailShadow !== null) {
|
|
1797
|
+
updateTailShadow = true;
|
|
1798
|
+
} else {
|
|
1799
|
+
// not based on tail
|
|
1800
|
+
|
|
1801
|
+
if (
|
|
1802
|
+
globalDependencyValues.basedOnHead &&
|
|
1803
|
+
globalDependencyValues.basedOnDisplacement
|
|
1804
|
+
) {
|
|
1805
|
+
// set displacement to be difference between head and desired tail
|
|
1806
|
+
|
|
1807
|
+
instructions.push({
|
|
1808
|
+
setDependency: dependencyNamesByKey[arrayKey].x,
|
|
1809
|
+
desiredValue: dependencyValuesByKey[arrayKey].headX
|
|
1810
|
+
.subtract(desiredStateVariableValues.tail[arrayKey])
|
|
1811
|
+
.simplify(),
|
|
1812
|
+
});
|
|
1813
|
+
} else {
|
|
1814
|
+
// if not based on both head and displacement,
|
|
1815
|
+
// then tail should have become
|
|
1816
|
+
// an essential state variable
|
|
1817
|
+
// set the value of the variable directly
|
|
1818
|
+
|
|
1819
|
+
instructions.push({
|
|
1820
|
+
setEssentialValue: "tail",
|
|
1821
|
+
value: {
|
|
1822
|
+
[arrayKey]: convertValueToMathExpression(
|
|
1823
|
+
desiredStateVariableValues.tail[arrayKey],
|
|
1824
|
+
),
|
|
1825
|
+
},
|
|
1826
|
+
});
|
|
1827
|
+
}
|
|
1828
|
+
}
|
|
1829
|
+
}
|
|
1830
|
+
|
|
1831
|
+
if (updateTailShadow) {
|
|
1832
|
+
if (arraySize[0] > 1) {
|
|
1833
|
+
let desiredTail = ["vector"];
|
|
1834
|
+
for (let arrayKey in desiredStateVariableValues.tail) {
|
|
1835
|
+
desiredTail[Number(arrayKey) + 1] =
|
|
1836
|
+
desiredStateVariableValues.tail[arrayKey].tree;
|
|
1837
|
+
}
|
|
1838
|
+
desiredTail.length = arraySize[0] + 1;
|
|
1839
|
+
instructions.push({
|
|
1840
|
+
setDependency: "tailShadow",
|
|
1841
|
+
desiredValue: me.fromAst(desiredTail),
|
|
1842
|
+
});
|
|
1843
|
+
} else if (
|
|
1844
|
+
arraySize[0] === 1 &&
|
|
1845
|
+
"0" in desiredStateVariableValues.tail
|
|
1846
|
+
) {
|
|
1847
|
+
instructions.push({
|
|
1848
|
+
setDependency: "tailShadow",
|
|
1849
|
+
desiredValue: desiredStateVariableValues.tail[0],
|
|
1850
|
+
});
|
|
1851
|
+
}
|
|
1852
|
+
}
|
|
1853
|
+
|
|
1854
|
+
return {
|
|
1855
|
+
success: true,
|
|
1856
|
+
instructions,
|
|
1857
|
+
};
|
|
1858
|
+
},
|
|
1859
|
+
};
|
|
1860
|
+
|
|
1861
|
+
stateVariableDefinitions.magnitude = {
|
|
1862
|
+
public: true,
|
|
1863
|
+
isLocation: true,
|
|
1864
|
+
shadowingInstructions: {
|
|
1865
|
+
createComponentOfType: "math",
|
|
1866
|
+
addAttributeComponentsShadowingStateVariables:
|
|
1867
|
+
returnRoundingAttributeComponentShadowing(),
|
|
1868
|
+
},
|
|
1869
|
+
returnDependencies: () => ({
|
|
1870
|
+
numDimensions: {
|
|
1871
|
+
dependencyType: "stateVariable",
|
|
1872
|
+
variableName: "numDimensions",
|
|
1873
|
+
},
|
|
1874
|
+
displacement: {
|
|
1875
|
+
dependencyType: "stateVariable",
|
|
1876
|
+
variableName: "displacement",
|
|
1877
|
+
},
|
|
1878
|
+
}),
|
|
1879
|
+
definition({ dependencyValues }) {
|
|
1880
|
+
let magnitude2 = 0;
|
|
1881
|
+
let all_numeric = true;
|
|
1882
|
+
for (let dim = 0; dim < dependencyValues.numDimensions; dim++) {
|
|
1883
|
+
let disp = dependencyValues.displacement[dim].evaluate_to_constant();
|
|
1884
|
+
if (!Number.isFinite(disp)) {
|
|
1885
|
+
all_numeric = false;
|
|
1886
|
+
break;
|
|
1887
|
+
}
|
|
1888
|
+
magnitude2 += disp * disp;
|
|
1889
|
+
}
|
|
1890
|
+
|
|
1891
|
+
if (all_numeric) {
|
|
1892
|
+
return { setValue: { magnitude: me.fromAst(Math.sqrt(magnitude2)) } };
|
|
1893
|
+
}
|
|
1894
|
+
|
|
1895
|
+
magnitude2 = ["+"];
|
|
1896
|
+
for (let dim = 0; dim < dependencyValues.numDimensions; dim++) {
|
|
1897
|
+
magnitude2.push(["^", dependencyValues.displacement[dim], 2]);
|
|
1898
|
+
}
|
|
1899
|
+
|
|
1900
|
+
return {
|
|
1901
|
+
setValue: {
|
|
1902
|
+
magnitude: me.fromAst(["apply", "sqrt", magnitude2]),
|
|
1903
|
+
},
|
|
1904
|
+
};
|
|
1905
|
+
},
|
|
1906
|
+
inverseDefinition({ desiredStateVariableValues, dependencyValues }) {
|
|
1907
|
+
let dir = [];
|
|
1908
|
+
let dir_length2 = 0;
|
|
1909
|
+
let all_numeric = true;
|
|
1910
|
+
for (let dim = 0; dim < dependencyValues.numDimensions; dim++) {
|
|
1911
|
+
let disp = dependencyValues.displacement[dim].evaluate_to_constant();
|
|
1912
|
+
if (!Number.isFinite(disp)) {
|
|
1913
|
+
all_numeric = false;
|
|
1914
|
+
break;
|
|
1915
|
+
}
|
|
1916
|
+
dir.push(disp);
|
|
1917
|
+
dir_length2 += disp * disp;
|
|
1918
|
+
}
|
|
1919
|
+
|
|
1920
|
+
if (!all_numeric) {
|
|
1921
|
+
return { success: false };
|
|
1922
|
+
}
|
|
1923
|
+
|
|
1924
|
+
// make dir be unit length
|
|
1925
|
+
let dir_length = Math.sqrt(dir_length2);
|
|
1926
|
+
dir = dir.map((x) => x / dir_length);
|
|
1927
|
+
|
|
1928
|
+
let desiredMagnitude =
|
|
1929
|
+
desiredStateVariableValues.magnitude.evaluate_to_constant();
|
|
1930
|
+
|
|
1931
|
+
if (!Number.isFinite(desiredMagnitude) || desiredMagnitude < 0) {
|
|
1932
|
+
return { success: false };
|
|
1933
|
+
}
|
|
1934
|
+
|
|
1935
|
+
let desiredDisplacement = [];
|
|
1936
|
+
|
|
1937
|
+
for (let dim = 0; dim < dependencyValues.numDimensions; dim++) {
|
|
1938
|
+
desiredDisplacement.push(me.fromAst(dir[dim] * desiredMagnitude));
|
|
1939
|
+
}
|
|
1940
|
+
|
|
1941
|
+
return {
|
|
1942
|
+
success: true,
|
|
1943
|
+
instructions: [
|
|
1944
|
+
{
|
|
1945
|
+
setDependency: "displacement",
|
|
1946
|
+
desiredValue: desiredDisplacement,
|
|
1947
|
+
},
|
|
1948
|
+
],
|
|
1949
|
+
};
|
|
1950
|
+
},
|
|
1951
|
+
};
|
|
1952
|
+
|
|
1953
|
+
stateVariableDefinitions.numericalEndpoints = {
|
|
1954
|
+
forRenderer: true,
|
|
1955
|
+
returnDependencies: () => ({
|
|
1956
|
+
head: {
|
|
1957
|
+
dependencyType: "stateVariable",
|
|
1958
|
+
variableName: "head",
|
|
1959
|
+
},
|
|
1960
|
+
tail: {
|
|
1961
|
+
dependencyType: "stateVariable",
|
|
1962
|
+
variableName: "tail",
|
|
1963
|
+
},
|
|
1964
|
+
numDimensions: {
|
|
1965
|
+
dependencyType: "stateVariable",
|
|
1966
|
+
variableName: "numDimensions",
|
|
1967
|
+
},
|
|
1968
|
+
}),
|
|
1969
|
+
definition: function ({ dependencyValues }) {
|
|
1970
|
+
let numericalHead, numericalTail;
|
|
1971
|
+
if (dependencyValues.numDimensions === 1) {
|
|
1972
|
+
numericalHead = dependencyValues.head[0].evaluate_to_constant();
|
|
1973
|
+
numericalTail = dependencyValues.tail[0].evaluate_to_constant();
|
|
1974
|
+
} else {
|
|
1975
|
+
numericalHead = [];
|
|
1976
|
+
numericalTail = [];
|
|
1977
|
+
|
|
1978
|
+
for (let i = 0; i < dependencyValues.numDimensions; i++) {
|
|
1979
|
+
let head = dependencyValues.head[i].evaluate_to_constant();
|
|
1980
|
+
numericalHead.push(head);
|
|
1981
|
+
|
|
1982
|
+
let tail = dependencyValues.tail[i].evaluate_to_constant();
|
|
1983
|
+
numericalTail.push(tail);
|
|
1984
|
+
}
|
|
1985
|
+
}
|
|
1986
|
+
|
|
1987
|
+
return {
|
|
1988
|
+
setValue: { numericalEndpoints: [numericalTail, numericalHead] },
|
|
1989
|
+
};
|
|
1990
|
+
},
|
|
1991
|
+
};
|
|
1992
|
+
|
|
1993
|
+
stateVariableDefinitions.displacementCoords = {
|
|
1994
|
+
isLocation: true,
|
|
1995
|
+
returnDependencies: () => ({
|
|
1996
|
+
displacement: {
|
|
1997
|
+
dependencyType: "stateVariable",
|
|
1998
|
+
variableName: "displacement",
|
|
1999
|
+
},
|
|
2000
|
+
displayWithAngleBrackets: {
|
|
2001
|
+
dependencyType: "stateVariable",
|
|
2002
|
+
variableName: "displayWithAngleBrackets",
|
|
2003
|
+
},
|
|
2004
|
+
}),
|
|
2005
|
+
definition({ dependencyValues }) {
|
|
2006
|
+
let coordsAst = [];
|
|
2007
|
+
for (let v of dependencyValues.displacement) {
|
|
2008
|
+
if (v) {
|
|
2009
|
+
coordsAst.push(v.tree);
|
|
2010
|
+
} else {
|
|
2011
|
+
coordsAst.push("\uff3f");
|
|
2012
|
+
}
|
|
2013
|
+
}
|
|
2014
|
+
if (coordsAst.length > 1) {
|
|
2015
|
+
let operator = dependencyValues.displayWithAngleBrackets
|
|
2016
|
+
? "altvector"
|
|
2017
|
+
: "vector";
|
|
2018
|
+
coordsAst = [operator, ...coordsAst];
|
|
2019
|
+
} else if (coordsAst.length === 1) {
|
|
2020
|
+
coordsAst = coordsAst[0];
|
|
2021
|
+
} else {
|
|
2022
|
+
coordsAst = "\uff3f";
|
|
2023
|
+
}
|
|
2024
|
+
|
|
2025
|
+
return { setValue: { displacementCoords: me.fromAst(coordsAst) } };
|
|
2026
|
+
},
|
|
2027
|
+
inverseDefinition({ desiredStateVariableValues }) {
|
|
2028
|
+
let coordsAst = desiredStateVariableValues.displacementCoords.tree;
|
|
2029
|
+
let newDisplacement;
|
|
2030
|
+
|
|
2031
|
+
if (
|
|
2032
|
+
Array.isArray(coordsAst) &&
|
|
2033
|
+
vectorOperators.includes(coordsAst[0])
|
|
2034
|
+
) {
|
|
2035
|
+
newDisplacement = coordsAst.slice(1).map((x) => me.fromAst(x));
|
|
2036
|
+
} else {
|
|
2037
|
+
newDisplacement = [desiredStateVariableValues.displacementCoords];
|
|
2038
|
+
}
|
|
2039
|
+
|
|
2040
|
+
return {
|
|
2041
|
+
success: true,
|
|
2042
|
+
instructions: [
|
|
2043
|
+
{
|
|
2044
|
+
setDependency: "displacement",
|
|
2045
|
+
desiredValue: newDisplacement,
|
|
2046
|
+
},
|
|
2047
|
+
],
|
|
2048
|
+
};
|
|
2049
|
+
},
|
|
2050
|
+
};
|
|
2051
|
+
|
|
2052
|
+
stateVariableDefinitions.latex = {
|
|
2053
|
+
forRenderer: true,
|
|
2054
|
+
public: true,
|
|
2055
|
+
shadowingInstructions: {
|
|
2056
|
+
createComponentOfType: "latex",
|
|
2057
|
+
},
|
|
2058
|
+
returnDependencies: () => ({
|
|
2059
|
+
displacementCoords: {
|
|
2060
|
+
dependencyType: "stateVariable",
|
|
2061
|
+
variableName: "displacementCoords",
|
|
2062
|
+
},
|
|
2063
|
+
displayDigits: {
|
|
2064
|
+
dependencyType: "stateVariable",
|
|
2065
|
+
variableName: "displayDigits",
|
|
2066
|
+
},
|
|
2067
|
+
displayDecimals: {
|
|
2068
|
+
dependencyType: "stateVariable",
|
|
2069
|
+
variableName: "displayDecimals",
|
|
2070
|
+
},
|
|
2071
|
+
displaySmallAsZero: {
|
|
2072
|
+
dependencyType: "stateVariable",
|
|
2073
|
+
variableName: "displaySmallAsZero",
|
|
2074
|
+
},
|
|
2075
|
+
padZeros: {
|
|
2076
|
+
dependencyType: "stateVariable",
|
|
2077
|
+
variableName: "padZeros",
|
|
2078
|
+
},
|
|
2079
|
+
}),
|
|
2080
|
+
definition: function ({ dependencyValues }) {
|
|
2081
|
+
let params = {};
|
|
2082
|
+
if (dependencyValues.padZeros) {
|
|
2083
|
+
if (Number.isFinite(dependencyValues.displayDecimals)) {
|
|
2084
|
+
params.padToDecimals = dependencyValues.displayDecimals;
|
|
2085
|
+
}
|
|
2086
|
+
if (dependencyValues.displayDigits >= 1) {
|
|
2087
|
+
params.padToDigits = dependencyValues.displayDigits;
|
|
2088
|
+
}
|
|
2089
|
+
}
|
|
2090
|
+
let latex = roundForDisplay({
|
|
2091
|
+
value: dependencyValues.displacementCoords,
|
|
2092
|
+
dependencyValues,
|
|
2093
|
+
}).toLatex(params);
|
|
2094
|
+
|
|
2095
|
+
return { setValue: { latex } };
|
|
2096
|
+
},
|
|
2097
|
+
};
|
|
2098
|
+
|
|
2099
|
+
stateVariableDefinitions.nearestPoint = {
|
|
2100
|
+
returnDependencies: () => ({
|
|
2101
|
+
numDimensions: {
|
|
2102
|
+
dependencyType: "stateVariable",
|
|
2103
|
+
variableName: "numDimensions",
|
|
2104
|
+
},
|
|
2105
|
+
numericalEndpoints: {
|
|
2106
|
+
dependencyType: "stateVariable",
|
|
2107
|
+
variableName: "numericalEndpoints",
|
|
2108
|
+
},
|
|
2109
|
+
}),
|
|
2110
|
+
definition({ dependencyValues }) {
|
|
2111
|
+
let A1 = dependencyValues.numericalEndpoints[0]?.[0];
|
|
2112
|
+
let A2 = dependencyValues.numericalEndpoints[0]?.[1];
|
|
2113
|
+
let B1 = dependencyValues.numericalEndpoints[1]?.[0];
|
|
2114
|
+
let B2 = dependencyValues.numericalEndpoints[1]?.[1];
|
|
2115
|
+
|
|
2116
|
+
let haveConstants =
|
|
2117
|
+
Number.isFinite(A1) &&
|
|
2118
|
+
Number.isFinite(A2) &&
|
|
2119
|
+
Number.isFinite(B1) &&
|
|
2120
|
+
Number.isFinite(B2);
|
|
2121
|
+
|
|
2122
|
+
// only implement for
|
|
2123
|
+
// - 2D
|
|
2124
|
+
// - constant endpoints and
|
|
2125
|
+
// - non-degenerate parameters
|
|
2126
|
+
let skip =
|
|
2127
|
+
dependencyValues.numDimensions !== 2 ||
|
|
2128
|
+
!haveConstants ||
|
|
2129
|
+
(B1 === A1 && B2 === A2);
|
|
2130
|
+
|
|
2131
|
+
return {
|
|
2132
|
+
setValue: {
|
|
2133
|
+
nearestPoint: function ({ variables, scales }) {
|
|
2134
|
+
if (skip) {
|
|
2135
|
+
return {};
|
|
2136
|
+
}
|
|
2137
|
+
|
|
2138
|
+
let xscale = scales[0];
|
|
2139
|
+
let yscale = scales[1];
|
|
2140
|
+
|
|
2141
|
+
let BA1 = (B1 - A1) / xscale;
|
|
2142
|
+
let BA2 = (B2 - A2) / yscale;
|
|
2143
|
+
let denom = BA1 * BA1 + BA2 * BA2;
|
|
2144
|
+
|
|
2145
|
+
let t =
|
|
2146
|
+
(((variables.x1 - A1) / xscale) * BA1 +
|
|
2147
|
+
((variables.x2 - A2) / yscale) * BA2) /
|
|
2148
|
+
denom;
|
|
2149
|
+
|
|
2150
|
+
let result = {};
|
|
2151
|
+
|
|
2152
|
+
if (t <= 0) {
|
|
2153
|
+
result = { x1: A1, x2: A2 };
|
|
2154
|
+
} else if (t >= 1) {
|
|
2155
|
+
result = { x1: B1, x2: B2 };
|
|
2156
|
+
} else {
|
|
2157
|
+
result = {
|
|
2158
|
+
x1: A1 + t * BA1 * xscale,
|
|
2159
|
+
x2: A2 + t * BA2 * yscale,
|
|
2160
|
+
};
|
|
2161
|
+
}
|
|
2162
|
+
|
|
2163
|
+
if (variables.x3 !== undefined) {
|
|
2164
|
+
result.x3 = 0;
|
|
2165
|
+
}
|
|
2166
|
+
|
|
2167
|
+
return result;
|
|
2168
|
+
},
|
|
2169
|
+
},
|
|
2170
|
+
};
|
|
2171
|
+
},
|
|
2172
|
+
};
|
|
2173
|
+
|
|
2174
|
+
return stateVariableDefinitions;
|
|
2175
|
+
}
|
|
2176
|
+
|
|
2177
|
+
static adapters = [
|
|
2178
|
+
{
|
|
2179
|
+
stateVariable: "displacementCoords",
|
|
2180
|
+
componentType: "coords",
|
|
2181
|
+
stateVariablesToShadow: Object.keys(
|
|
2182
|
+
returnRoundingStateVariableDefinitions(),
|
|
2183
|
+
),
|
|
2184
|
+
},
|
|
2185
|
+
{
|
|
2186
|
+
stateVariable: "displacementCoords",
|
|
2187
|
+
componentType: "point",
|
|
2188
|
+
stateVariablesToShadow: Object.keys(
|
|
2189
|
+
returnRoundingStateVariableDefinitions(),
|
|
2190
|
+
),
|
|
2191
|
+
},
|
|
2192
|
+
];
|
|
2193
|
+
|
|
2194
|
+
async moveVector({
|
|
2195
|
+
tailcoords,
|
|
2196
|
+
headcoords,
|
|
2197
|
+
transient,
|
|
2198
|
+
skippable,
|
|
2199
|
+
sourceDetails,
|
|
2200
|
+
actionId,
|
|
2201
|
+
sourceInformation = {},
|
|
2202
|
+
skipRendererUpdate = false,
|
|
2203
|
+
}) {
|
|
2204
|
+
if (tailcoords !== undefined) {
|
|
2205
|
+
if (headcoords !== undefined) {
|
|
2206
|
+
// dragged entire vector
|
|
2207
|
+
if (!(await this.stateValues.draggable)) {
|
|
2208
|
+
return await this.coreFunctions.resolveAction({ actionId });
|
|
2209
|
+
}
|
|
2210
|
+
} else {
|
|
2211
|
+
// dragged just tail
|
|
2212
|
+
if (!(await this.stateValues.tailDraggable)) {
|
|
2213
|
+
return await this.coreFunctions.resolveAction({ actionId });
|
|
2214
|
+
}
|
|
2215
|
+
}
|
|
2216
|
+
} else {
|
|
2217
|
+
// dragged just head
|
|
2218
|
+
if (!(await this.stateValues.headDraggable)) {
|
|
2219
|
+
return await this.coreFunctions.resolveAction({ actionId });
|
|
2220
|
+
}
|
|
2221
|
+
}
|
|
2222
|
+
|
|
2223
|
+
let updateInstructions = [];
|
|
2224
|
+
|
|
2225
|
+
if (tailcoords !== undefined) {
|
|
2226
|
+
// if based on both head and displacement
|
|
2227
|
+
// then set displacement as head - tail
|
|
2228
|
+
if (
|
|
2229
|
+
(await this.stateValues.basedOnHead) &&
|
|
2230
|
+
(await this.stateValues.basedOnDisplacement)
|
|
2231
|
+
) {
|
|
2232
|
+
let displacement;
|
|
2233
|
+
if (headcoords === undefined) {
|
|
2234
|
+
// use current value of head
|
|
2235
|
+
// if head isn't supposed to change
|
|
2236
|
+
let numericalEndpoints = await this.stateValues.numericalEndpoints;
|
|
2237
|
+
displacement = tailcoords.map((x, i) => numericalEndpoints[1][i] - x);
|
|
2238
|
+
} else {
|
|
2239
|
+
displacement = tailcoords.map((x, i) => headcoords[i] - x);
|
|
2240
|
+
}
|
|
2241
|
+
|
|
2242
|
+
updateInstructions.push({
|
|
2243
|
+
updateType: "updateValue",
|
|
2244
|
+
componentName: this.componentName,
|
|
2245
|
+
stateVariable: "displacement",
|
|
2246
|
+
value: displacement.map((x) => me.fromAst(x)),
|
|
2247
|
+
sourceDetails,
|
|
2248
|
+
});
|
|
2249
|
+
} else {
|
|
2250
|
+
// set tail directly
|
|
2251
|
+
updateInstructions.push({
|
|
2252
|
+
updateType: "updateValue",
|
|
2253
|
+
componentName: this.componentName,
|
|
2254
|
+
stateVariable: "tail",
|
|
2255
|
+
value: tailcoords.map((x) => me.fromAst(x)),
|
|
2256
|
+
sourceDetails,
|
|
2257
|
+
});
|
|
2258
|
+
}
|
|
2259
|
+
|
|
2260
|
+
if (headcoords === undefined) {
|
|
2261
|
+
// if set tail but not head, the idea is that head shouldn't move
|
|
2262
|
+
// however, head would move if not based on head
|
|
2263
|
+
// so give instructions to change displacement to keep head fixed
|
|
2264
|
+
if (!(await this.stateValues.basedOnHead)) {
|
|
2265
|
+
let numericalEndpoints = await this.stateValues.numericalEndpoints;
|
|
2266
|
+
let displacement = tailcoords.map(
|
|
2267
|
+
(x, i) => numericalEndpoints[1][i] - x,
|
|
2268
|
+
);
|
|
2269
|
+
updateInstructions.push({
|
|
2270
|
+
updateType: "updateValue",
|
|
2271
|
+
componentName: this.componentName,
|
|
2272
|
+
stateVariable: "displacement",
|
|
2273
|
+
value: displacement.map((x) => me.fromAst(x)),
|
|
2274
|
+
sourceDetails,
|
|
2275
|
+
});
|
|
2276
|
+
}
|
|
2277
|
+
}
|
|
2278
|
+
}
|
|
2279
|
+
|
|
2280
|
+
if (headcoords !== undefined) {
|
|
2281
|
+
// for head, we'll set it directly if based on head
|
|
2282
|
+
if (await this.stateValues.basedOnHead) {
|
|
2283
|
+
updateInstructions.push({
|
|
2284
|
+
updateType: "updateValue",
|
|
2285
|
+
componentName: this.componentName,
|
|
2286
|
+
stateVariable: "head",
|
|
2287
|
+
value: headcoords.map((x) => me.fromAst(x)),
|
|
2288
|
+
sourceDetails,
|
|
2289
|
+
});
|
|
2290
|
+
} else {
|
|
2291
|
+
// if not based on head
|
|
2292
|
+
// then update displacement instead of head
|
|
2293
|
+
|
|
2294
|
+
if (tailcoords == undefined) {
|
|
2295
|
+
tailcoords = (await this.stateValues.numericalEndpoints)[0];
|
|
2296
|
+
}
|
|
2297
|
+
let displacement = tailcoords.map((x, i) => headcoords[i] - x);
|
|
2298
|
+
updateInstructions.push({
|
|
2299
|
+
updateType: "updateValue",
|
|
2300
|
+
componentName: this.componentName,
|
|
2301
|
+
stateVariable: "displacement",
|
|
2302
|
+
value: displacement.map((x) => me.fromAst(x)),
|
|
2303
|
+
sourceDetails,
|
|
2304
|
+
});
|
|
2305
|
+
}
|
|
2306
|
+
|
|
2307
|
+
if (tailcoords === undefined) {
|
|
2308
|
+
// if set head but not tail, the idea is that tail shouldn't move
|
|
2309
|
+
// however, tail would move if based on displacement and head
|
|
2310
|
+
// so give instructions to change displacement to keep tail fixed
|
|
2311
|
+
if (
|
|
2312
|
+
(await this.stateValues.basedOnHead) &&
|
|
2313
|
+
(await this.stateValues.basedOnDisplacement)
|
|
2314
|
+
) {
|
|
2315
|
+
let numericalEndpoints = await this.stateValues.numericalEndpoints;
|
|
2316
|
+
let displacement = headcoords.map(
|
|
2317
|
+
(x, i) => x - numericalEndpoints[0][i],
|
|
2318
|
+
);
|
|
2319
|
+
updateInstructions.push({
|
|
2320
|
+
updateType: "updateValue",
|
|
2321
|
+
componentName: this.componentName,
|
|
2322
|
+
stateVariable: "displacement",
|
|
2323
|
+
value: displacement.map((x) => me.fromAst(x)),
|
|
2324
|
+
sourceDetails,
|
|
2325
|
+
});
|
|
2326
|
+
}
|
|
2327
|
+
}
|
|
2328
|
+
}
|
|
2329
|
+
|
|
2330
|
+
// Note: we set skipRendererUpdate to true
|
|
2331
|
+
// so that we can make further adjustments before the renderers are updated
|
|
2332
|
+
if (transient) {
|
|
2333
|
+
await this.coreFunctions.performUpdate({
|
|
2334
|
+
updateInstructions,
|
|
2335
|
+
transient,
|
|
2336
|
+
skippable,
|
|
2337
|
+
actionId,
|
|
2338
|
+
sourceInformation,
|
|
2339
|
+
skipRendererUpdate: true,
|
|
2340
|
+
});
|
|
2341
|
+
} else {
|
|
2342
|
+
await this.coreFunctions.performUpdate({
|
|
2343
|
+
updateInstructions,
|
|
2344
|
+
actionId,
|
|
2345
|
+
sourceInformation,
|
|
2346
|
+
skipRendererUpdate: true,
|
|
2347
|
+
event: {
|
|
2348
|
+
verb: "interacted",
|
|
2349
|
+
object: {
|
|
2350
|
+
componentName: this.componentName,
|
|
2351
|
+
componentType: this.componentType,
|
|
2352
|
+
},
|
|
2353
|
+
result: {
|
|
2354
|
+
head: headcoords,
|
|
2355
|
+
tail: tailcoords,
|
|
2356
|
+
},
|
|
2357
|
+
},
|
|
2358
|
+
});
|
|
2359
|
+
}
|
|
2360
|
+
|
|
2361
|
+
// we attempt to keep the vector displacement fixed
|
|
2362
|
+
// even if one of the points defining it is constrained
|
|
2363
|
+
|
|
2364
|
+
// if dragged the whole vector that is based on tail and head,
|
|
2365
|
+
// address case where only one point is constrained
|
|
2366
|
+
// to make vector just translate in this case
|
|
2367
|
+
if (
|
|
2368
|
+
tailcoords !== undefined &&
|
|
2369
|
+
headcoords !== undefined &&
|
|
2370
|
+
(await this.stateValues.basedOnTail) &&
|
|
2371
|
+
(await this.stateValues.basedOnHead)
|
|
2372
|
+
) {
|
|
2373
|
+
let numericalPoints = [tailcoords, headcoords];
|
|
2374
|
+
let resultingNumericalPoints = await this.stateValues.numericalEndpoints;
|
|
2375
|
+
|
|
2376
|
+
let pointsChanged = [];
|
|
2377
|
+
let numPointsChanged = 0;
|
|
2378
|
+
|
|
2379
|
+
for (let [ind, pt] of numericalPoints.entries()) {
|
|
2380
|
+
if (!pt.every((v, i) => v === resultingNumericalPoints[ind][i])) {
|
|
2381
|
+
pointsChanged.push(ind);
|
|
2382
|
+
numPointsChanged++;
|
|
2383
|
+
}
|
|
2384
|
+
}
|
|
2385
|
+
|
|
2386
|
+
if (numPointsChanged === 1) {
|
|
2387
|
+
// one point was altered from the requested location.
|
|
2388
|
+
|
|
2389
|
+
let changedInd = pointsChanged[0];
|
|
2390
|
+
|
|
2391
|
+
let orig1 = numericalPoints[changedInd];
|
|
2392
|
+
let changed1 = resultingNumericalPoints[changedInd];
|
|
2393
|
+
let changevec1 = orig1.map((v, i) => v - changed1[i]);
|
|
2394
|
+
|
|
2395
|
+
let newNumericalPoints = [];
|
|
2396
|
+
|
|
2397
|
+
for (let i = 0; i < 2; i++) {
|
|
2398
|
+
if (i === changedInd) {
|
|
2399
|
+
newNumericalPoints.push(resultingNumericalPoints[i]);
|
|
2400
|
+
} else {
|
|
2401
|
+
newNumericalPoints.push(
|
|
2402
|
+
numericalPoints[i].map((v, j) => v - changevec1[j]),
|
|
2403
|
+
);
|
|
2404
|
+
}
|
|
2405
|
+
}
|
|
2406
|
+
|
|
2407
|
+
let newInstructions = [
|
|
2408
|
+
{
|
|
2409
|
+
updateType: "updateValue",
|
|
2410
|
+
componentName: this.componentName,
|
|
2411
|
+
stateVariable: "tail",
|
|
2412
|
+
value: newNumericalPoints[0].map((x) => me.fromAst(x)),
|
|
2413
|
+
},
|
|
2414
|
+
{
|
|
2415
|
+
updateType: "updateValue",
|
|
2416
|
+
componentName: this.componentName,
|
|
2417
|
+
stateVariable: "head",
|
|
2418
|
+
value: newNumericalPoints[1].map((x) => me.fromAst(x)),
|
|
2419
|
+
},
|
|
2420
|
+
];
|
|
2421
|
+
|
|
2422
|
+
return await this.coreFunctions.performUpdate({
|
|
2423
|
+
updateInstructions: newInstructions,
|
|
2424
|
+
transient,
|
|
2425
|
+
actionId,
|
|
2426
|
+
sourceInformation,
|
|
2427
|
+
skipRendererUpdate,
|
|
2428
|
+
});
|
|
2429
|
+
}
|
|
2430
|
+
}
|
|
2431
|
+
|
|
2432
|
+
// if no modifications were made, still need to update renderers
|
|
2433
|
+
// as original update was performed with skipping renderer update
|
|
2434
|
+
return await this.coreFunctions.updateRenderers({
|
|
2435
|
+
actionId,
|
|
2436
|
+
sourceInformation,
|
|
2437
|
+
skipRendererUpdate,
|
|
2438
|
+
});
|
|
2439
|
+
}
|
|
2440
|
+
|
|
2441
|
+
async vectorClicked({
|
|
2442
|
+
actionId,
|
|
2443
|
+
name,
|
|
2444
|
+
sourceInformation = {},
|
|
2445
|
+
skipRendererUpdate = false,
|
|
2446
|
+
}) {
|
|
2447
|
+
if (!(await this.stateValues.fixed)) {
|
|
2448
|
+
await this.coreFunctions.triggerChainedActions({
|
|
2449
|
+
triggeringAction: "click",
|
|
2450
|
+
componentName: name, // use name rather than this.componentName to get original name if adapted
|
|
2451
|
+
actionId,
|
|
2452
|
+
sourceInformation,
|
|
2453
|
+
skipRendererUpdate,
|
|
2454
|
+
});
|
|
2455
|
+
}
|
|
2456
|
+
|
|
2457
|
+
this.coreFunctions.resolveAction({ actionId });
|
|
2458
|
+
}
|
|
2459
|
+
|
|
2460
|
+
async vectorFocused({
|
|
2461
|
+
actionId,
|
|
2462
|
+
name,
|
|
2463
|
+
sourceInformation = {},
|
|
2464
|
+
skipRendererUpdate = false,
|
|
2465
|
+
}) {
|
|
2466
|
+
if (!(await this.stateValues.fixed)) {
|
|
2467
|
+
await this.coreFunctions.triggerChainedActions({
|
|
2468
|
+
triggeringAction: "focus",
|
|
2469
|
+
componentName: name, // use name rather than this.componentName to get original name if adapted
|
|
2470
|
+
actionId,
|
|
2471
|
+
sourceInformation,
|
|
2472
|
+
skipRendererUpdate,
|
|
2473
|
+
});
|
|
2474
|
+
}
|
|
2475
|
+
|
|
2476
|
+
this.coreFunctions.resolveAction({ actionId });
|
|
2477
|
+
}
|
|
2478
|
+
}
|