Giter Site home page Giter Site logo

mathigon / fermat.js Goto Github PK

View Code? Open in Web Editor NEW
103.0 103.0 16.0 1.36 MB

Mathematics and statistics library for TypeScript.

Home Page: http://mathigon.io/fermat

License: MIT License

TypeScript 94.96% JavaScript 5.04%
math mathematics statistics typescript

fermat.js's People

Contributors

dependabot[bot] avatar iapain avatar joshestein avatar mend-for-github-com[bot] avatar phildeorsey avatar pjhenning avatar plegner avatar renovate-bot avatar renovate[bot] avatar sebpearce avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fermat.js's Issues

intersections() appears hanging forever when calculating intersection of polygon and line

I have a polygon that has approximated shape of ellipsis and a line that has one point inside that ellipsis.
Trying to find intersection of polygon and line.
Somehow the intersections() call never returns or hangs.

I'm using the same procedure to calculate intersection of other ( likely less points ) polygon and a line successfully.
Could it be that implementation can't handle polygons with too many points ?
API documentation doesn't state any known limitation though.

Using @mathigon/fermat 0.5.2.
Code fails when running in Chrome "Version 84.0.4147.125 (Offizieller Build) (64-Bit)".

const polygonPoints = [
  new Point(-349, 219),
  new Point(-350.2913409939623, 227.6824088833465),
  new Point(-354.1261272331978, 236.10100716628344),
  new Point(-360.38784067832273, 244),
  new Point(-368.88622233488684, 251.13938048432698),
  new Point(-379.36305317664414, 257.3022221559489),
  new Point(-391.5, 262.30127018922195),
  new Point(-404.92828781731816, 265.98463103929544),
  new Point(-419.2399048983109, 268.2403876506104),
  new Point(-434, 269),
  new Point(-448.7600951016891, 268.2403876506104),
  new Point(-463.07171218268184, 265.98463103929544),
  new Point(-476.5, 262.30127018922195),
  new Point(-488.63694682335586, 257.3022221559489),
  new Point(-499.1137776651131, 251.13938048432698),
  new Point(-507.61215932167727, 244),
  new Point(-513.8738727668022, 236.10100716628344),
  new Point(-517.7086590060377, 227.68240888334654),
  new Point(-519, 219),
  new Point(-517.7086590060377, 210.3175911166535),
  new Point(-513.8738727668023, 201.89899283371656),
  new Point(-507.61215932167727, 194),
  new Point(-499.11377766511316, 186.86061951567302),
  new Point(-488.63694682335586, 180.6977778440511),
  new Point(-476.50000000000006, 175.69872981077808),
  new Point(-463.0717121826819, 172.0153689607046),
  new Point(-448.7600951016891, 169.7596123493896),
  new Point(-434, 169),
  new Point(-419.23990489831095, 169.75961234938958),
  new Point(-404.9282878173182, 172.01536896070456),
  new Point(-391.5, 175.69872981077808),
  new Point(-379.36305317664414, 180.6977778440511),
  new Point(-368.8862223348869, 186.86061951567302),
  new Point(-360.38784067832273, 193.99999999999997),
  new Point(-354.1261272331978, 201.89899283371653),
];
const line = new Line(new Point(-434, 219), new Point(-229.5, 385.123));
console.info('polygon', polygonPoints.length);
const shape = new Polygon(...polygonPoints);

// the following call never seems to return
let intersection = intersections(line, shape) || [];
console.info('intersections', intersection.length);

Matrix.inverse is not correct in this case

import { Matrix } from "@mathigon/fermat";

var k = [[6.38342822594358e-17, 1.0424928665161133, -0.04249291867017746], [-1.0424928665161133, 0, 1], [0, 0, 1]];
var ik = Matrix.inverse(k);
console.log(Matrix.product(k, ik));
// expect [[1, 0, 0], [0, 1, 0], [0, 0, 1]]
// got [[0.9999999999999999, 0, 0], [2.0849857330322266, 1, -0.04249286651611328], [0, 0, 1]]

image

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

Error type: undefined. Note: this is a nested preset so please contact the preset author if you are unable to fix it yourself.

Feature request: improve bundle

Hello,

currently the "module" field of the package.json points to your "index.ts" file. This break e.g. creat-react-app. It would be better if you would provide two bundled version, one for cjs and one for esm. Then you could set the "main" field to your index.cjs.js file and your "module" field to "index.esm.js" ... in addition to that a "types" field pointing to typescript declarations.

Would you accept a pull request for those changes?

Besides that, this is a fantastic library btw ๐Ÿ˜‰

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Awaiting Schedule

These updates are awaiting their schedule. Click on a checkbox to get an update now.

  • Update actions/checkout action to v4
  • Update actions/setup-node action to v4

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/codeql.yml
  • actions/checkout v3
  • github/codeql-action v2
  • github/codeql-action v2
.github/workflows/test.yml
  • actions/checkout v3
  • actions/setup-node v3
  • bahmutov/npm-install v1
npm
package.json
  • @mathigon/core 1.1.13
  • @types/tape 5.6.1
  • @typescript-eslint/eslint-plugin 6.7.4
  • @typescript-eslint/parser 6.7.4
  • esbuild 0.19.4
  • eslint 8.50.0
  • eslint-plugin-import 2.28.1
  • tape 5.7.0
  • ts-node 10.9.1
  • tslib 2.6.2
  • typescript 5.2.2
  • node >=16

seeded random numbers?

I love the Random helpers in this library, but I'm looking to use them for generative art, and I need a way to create seeded random numbers for consitent, repeatable outputs.

I was wondering if you'd be open to having an extra optional argument added to the functions. For example:

// from...
function bernoulli(p = 0.5) {}

// to...
function bernoulli(p = 0.5, random = Math.random) {}

So for example in p5.js you could do:

let r = Random.bernoulli(0.5, p.random)

Alternatively, the existing random helpers could be refactored to be a class that can be instantiated as well as used as static methods. So you could do:

let random = new Random(p.random)
let r = random.bernoulli()

Which might be nicer.

This would also make it easy to use libraries like seedrandom or seed-random too.

roundTo is probably wrong

Calling roundTo(103.35, 0.1) gives 103.30000000000001 where it should give 103.4.

Original function:

/** Round a number `n` to the nearest multiple of `increment`. */
export function roundTo(n: number, increment = 1) {
  return Math.round(n / increment) * increment;
}

This function looks to work properly:

function roundTo(n: number, increment = 1) {
  const v1 = Math.round(n / increment ) * increment 
  const v2 = Math.round(n / increment + 1e-10) * increment 
  const v3 = Math.round(n / increment - 1e-10) * increment 
  return Math.abs(v1 - v2) > increment / 10 ? v2 : v3
}

No way to create a Vector from an array of number.

The current implementation of the Vector constructor makes it so that it's only possible to create a vector with individual numbers and not an array of numbers. It would be nice if it was possible to do something like that :

const numbers = [1, 2, 3];
const vector = new Vector(numbers);

PS: Is there a reason why every opperation like Vector.difference() returns number[] and not a Vector ?

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Awaiting Schedule

These updates are awaiting their schedule. Click on a checkbox to get an update now.

  • Update dependency tslib to v2.6.2
  • Update Test and Build (@typescript-eslint/eslint-plugin, @typescript-eslint/parser, esbuild, eslint, eslint-plugin-import)

Detected dependencies

github-actions
.github/workflows/codeql.yml
  • actions/checkout v3
  • github/codeql-action v2
  • github/codeql-action v2
.github/workflows/test.yml
  • actions/checkout v3
  • actions/setup-node v3
  • bahmutov/npm-install v1
npm
package.json
  • @mathigon/core 1.1.10
  • @types/tape 5.6.0
  • @typescript-eslint/eslint-plugin 6.2.1
  • @typescript-eslint/parser 6.2.1
  • esbuild 0.18.17
  • eslint 8.46.0
  • eslint-plugin-import 2.28.0
  • tape 5.6.6
  • ts-node 10.9.1
  • tslib 2.6.1
  • typescript 5.1.6
  • node >=14

  • Check this box to trigger a request for Renovate to run again on this repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.