FlorisSteenkamp / MAT

Medial Axis Transform - Library
119 stars 23 forks source link

getCornerAtEnd(curve) - export/public? #28

Closed matmill5 closed 2 years ago

matmill5 commented 2 years ago

Floris, how can I access the curve's cornerAtEnd? I see the function on the Curve's class definition, but I am unable to access it.

Trying something like this:

export const paintCorners = (scaledSvgPathString: string) => {
  const paths = getPathsFromStr(scaledSvgPathString);

  paths.forEach((loop) => {
    loopFromBeziers(loop).curves.forEach((curve) => {
      console.log(getCornerAtEnd(curve));
      // Or.. ??
      // console.log(curve.getCornerAtEnd();
    });
  });
};

Please advise? I would prefer to use your getCornerAtEnd() implementation instead of writing a duplicate.

FlorisSteenkamp commented 2 years ago

Hi Matthew.

It would've been getCornerAtEnd(curve) (it has changed at some point) but you're correct; since the package.json has the entry "type": "module" only the exports in index.js are exported.

This is supposedly by design 😄 to hide 'implementation details', e.g. the function you're trying to access isn't part of the 'exposed API'. However, I've always found completely blocking access from implementation detail type functions very annoying and wrong (in my opinion). Sure, hide it, but still provide a backdoor if you really need it. Wait... let me check something. Ok, if you're using one of the combinations below you're in luck since then you can import it as follows: (Note you cannot import it directly from flo-mat since that's just how module exports work in package.json)

For Node|JavaScript OR Browser|TypeScript (using e.g. Webpack):

import { findMats } from 'flo-mat';  // optional
import { getCornerAtEnd } from './node_modules/flo-mat/node/curve.js';

For Node|TypeScript (using e.g. Webpack):

import { findMats, getPathsFromStr, toScaleAxis } from 'flo-mat';
import { getCornerAtEnd } from 'flo-mat/node/curve.js';

(Without Webpack tsc seems to be complaining about special characters - I haven't looked into it)

For Browser|JavaScript:

// I haven't found a solution (if someone is struggling with this please open
// an issue and I might export nearly all internals which is probably a bad idea
// OR just change to TypeScript if possible OR something else.

Could you check if one of those 'import workarounds' fit your needs?

matmill5 commented 2 years ago

Hey Floris, sorry for the delayed response, I took a different route, but I will also try this; thank you.