PMKS-Web / PMKSWeb

An educational web-based tool designed for comprehensive 2D linkage analysis developed at WPI (Worcester Polytechnic Institute)
https://pmksplus.com
3 stars 2 forks source link

Links that are not attached to joints should give error message instead of allowing saving #9

Closed KohmeiK closed 1 year ago

KohmeiK commented 1 year ago

Edit link and change to the rotatable shape (2nd one) Image Rotate link Image Click save - now this animates without being connected Image

Old version: Image Clicking save gives an error: Image

KohmeiK commented 1 year ago

@AlexG1031 This seems like a large issue. None of the SVG functions (checkForceEndpointInLink(), checkJointsInLink(), checkValidLink() [PMKSConverison/../Links.ts line 294] are in the new repo. So doing this check and printing out the error might involve copying and re-creating a lot of those SVG functions. I suggest redoing the SVG stuff with a library (https://svgjs.dev/docs/3.0/) at some point in the future, and don't allow shape changing for the first version we push to the live site. What do you think?

AlexG1031 commented 1 year ago

@Kohmei358 For this particular bug, this should be a pretty easy thing to fix. None of those functions within PMKSConversion is necessary since they all use the same logic.

Attached is the logic from PMKSConversion that is used to check whether a point is inside SVG or not. This is copied from PMKSConversion, SVGFuncs, starting I believe 1446. We would just need to copy this code and put it within PMKSWeb (with slight adjustments made) and that should work.

pointInsideSVGPath(point: Coord, svg: SVGGeometryElement): Boolean { // isPointInFill is not supported on firefox mobile, check first if (svg.isPointInFill) { const fakeGrid = document.createElementNS('http://www.w3.org/2000/svg', 'svg'); const svgp = fakeGrid.createSVGPoint(); svgp.x = point.x; svgp.y = point.y; const isin = svg.isPointInFill(svgp); return isin; } else { return psip.isInside([point.x, point.y], svg.getAttribute('d')); } }

If this is still a problem after Friday or if you want me to do this, I can do so.

Just one thing, going through PMKSConversion is kinda difficult. I may have to explain to you how things are structured and how to run the code, but I can go through it for you and help pick out parts of the code that would help fix certain issues.

Do let me know if you have any questions and always happy to go over the code with you in person or zoom.