mathigon / fermat.js Goto Github PK
View Code? Open in Web Editor NEWMathematics and statistics library for TypeScript.
Home Page: http://mathigon.io/fermat
License: MIT License
Mathematics and statistics library for TypeScript.
Home Page: http://mathigon.io/fermat
License: MIT License
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);
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]]
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.
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 ๐
Great library!
One small thing I noticed, "manhatten" distance is spelled wrong, should be "manhattan".
https://github.com/Mathigon/fermat.js/blob/master/src/geometry.js
This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.
These updates are awaiting their schedule. Click on a checkbox to get an update now.
These updates have all been created already. Click a checkbox below to force a retry/rebase of any.
@types/tape
, esbuild
, eslint
, eslint-plugin-import
, tape
)@typescript-eslint/eslint-plugin
, @typescript-eslint/parser
).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
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
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.
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
}
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
?
This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.
These updates are awaiting their schedule. Click on a checkbox to get an update now.
@typescript-eslint/eslint-plugin
, @typescript-eslint/parser
, esbuild
, eslint
, eslint-plugin-import
).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
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.