-
Notifications
You must be signed in to change notification settings - Fork 279
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Structural formula example #734
Conversation
Codecov Report
@@ Coverage Diff @@
## main #734 +/- ##
==========================================
- Coverage 67.78% 67.39% -0.39%
==========================================
Files 45 45
Lines 7375 7444 +69
Branches 1398 1416 +18
==========================================
+ Hits 4999 5017 +18
- Misses 2367 2418 +51
Partials 9 9
Continue to review full report at Codecov.
|
@samestep I restored this branch because it's linked to from Twitter. 😬 |
@keenancrane Oh! 😮 Sorry about that, I was being too aggressive in deleting branches today; I won't do that from now on. |
Description
This PR adds a new example of structural formula diagrams, used to illustrate molecular structures and chemical reaction equations. Some example output can be found here.
It also implements a variety of changes needed to support these diagrams. In particular:
acos
) and arcsin (asin
) functions to the autodiff engine, and exposes them via corresponding Style functions.sgn
(which gives the sign of a scalar value),toRadians
(which converts an angle from degrees to radians), andtoDegrees
(which converts an angle from degrees to radians).cross2D
function to Style, which computes the cross product of two 2D vectors.atan2(y,x)
in the autodiff engine. Previously this function evaluated the productx*y
rather than the 2-argument arc tangent. It also incorrectly swapped the derivatives with respect tox
andy
. The new implementation was briefly tested by displaying and optimizing the angles of a triangle (which now works as expected).angleBetween(u,v)
andangleFrom(u,v)
. The former computes the unsigned angle betweenu
andv
; the latter computes the signed angle fromu
tov
.contains(Rectangle,Circle)
. Previously, this constraint used a circle as a proxy for the rectangle, leading to unexpected and undesirable behavior (e.g., shapes not actually being constrained to the rectangle interior). The new implementation has been tested and validated on a large number of examples (molecular diagrams, with many circles that must remain inside the canvas rectangle).stroke-linecap
in Style. In particular,Line
andArrow
shapes now have a fieldstrokeLineCap:
which can be set tobutt
,round
, orsquare
. This feature has been tested and validated in thestructural-formula/psuedo-3d.sty
style.Finally, this PR includes a file
DevLog.md
which documents the process of developing this domain, and various conceptual & technical hurdles encountered along the way. This metadata may be useful for future expert studies, etc.Related issue/PR: # (issue/PR)
NA
Implementation strategy and design decisions
The only real "design decision" was how to implement the
contains(Rectangle,Circle)
constraint. I didn't do anything unconventional—here's the comment fromConstraints.ts
that spells out the new constraint implementation:Examples with steps to reproduce them
This PR includes:
structural-formula
)structural-formula.sty
,pseudo-3d.sty
,pseudo-3d-reaction.sty
)/molecules
and/reactions
)For convenience, these examples can be run using the
run
script in the root directory. Edit this file to try out different combinations of molecules and styles. Note that reactions must use thepseudo-3d-reaction.sty
style, and likewise, individual molecules will not play well withpseudo-3d-reaction.sty
(which expects molecules to be grouped into reactants and products).Checklist
yarn test
yarn docs
and there were no errors when generating the HTML siteOpen questions
NA
Questions that require more discussion or to be addressed in future development:
NA