@mathigon/euclid
Advanced tools
Comparing version 1.1.12 to 1.1.13
@@ -11,2 +11,3 @@ import { Circle } from './circle'; | ||
readonly type: string; | ||
readonly ['constructor']: new (c: Point, start: Point, angle: number) => this; | ||
constructor(c: Point, start: Point, angle: number); | ||
@@ -13,0 +14,0 @@ get circle(): Circle; |
@@ -12,3 +12,5 @@ import { Rectangle } from './rectangle'; | ||
box?: Rectangle; | ||
cornerRadius?: number; | ||
} | ||
export declare function drawRoundedRect(rect: Rectangle, tl: number, tr?: number, br?: number, bl?: number): string; | ||
export declare function drawSVG(obj: GeoElement, options?: SVGDrawingOptions): string; |
@@ -34,3 +34,3 @@ import { Line } from './line'; | ||
at(t: number): Point; | ||
offset(p: Point): number; | ||
offset(_p: Point): number; | ||
contains(p: Point): boolean; | ||
@@ -37,0 +37,0 @@ transform(_m: TransformMatrix): this; |
@@ -9,2 +9,3 @@ import { Point } from './point'; | ||
flag?: number; | ||
readonly ['constructor']: new (p1: Point, p2: Point) => this; | ||
constructor(p1: Point, p2: Point); | ||
@@ -50,5 +51,5 @@ get length(): number; | ||
reflect(l: Line): this; | ||
scale(sx: number, sy?: number): any; | ||
shift(x: number, y?: number): any; | ||
translate(p: SimplePoint): any; | ||
scale(sx: number, sy?: number): this; | ||
shift(x: number, y?: number): this; | ||
translate(p: SimplePoint): this; | ||
equals(other: Line, tolerance?: number): boolean; | ||
@@ -55,0 +56,0 @@ toString(): string; |
@@ -57,5 +57,5 @@ import { Bounds } from './bounds'; | ||
translate(p: SimplePoint): Point; | ||
equals(other: any, precision?: number): boolean; | ||
equals(other: GeoElement | SimplePoint, precision?: number): boolean; | ||
toString(): string; | ||
} | ||
export declare const ORIGIN: Point; |
@@ -9,2 +9,3 @@ import { Circle } from './circle'; | ||
readonly points: Point[]; | ||
readonly ['constructor']: new (...points: Point[]) => this; | ||
constructor(...points: Point[]); | ||
@@ -11,0 +12,0 @@ get circumference(): number; |
@@ -19,2 +19,3 @@ import { Bounds } from './bounds'; | ||
get area(): number; | ||
get signedArea(): number; | ||
/** @returns {Segment[]} */ | ||
@@ -29,2 +30,3 @@ get edges(): import("./line").Segment[]; | ||
padding(top: number, right: number, bottom: number, left: number): Rectangle; | ||
get unsigned(): Rectangle; | ||
contains(p: Point, tolerance?: number): boolean; | ||
@@ -31,0 +33,0 @@ project(p: SimplePoint): Point; |
{ | ||
"name": "@mathigon/euclid", | ||
"version": "1.1.12", | ||
"version": "1.1.13", | ||
"license": "MIT", | ||
@@ -16,3 +16,3 @@ "homepage": "https://mathigon.io/euclid", | ||
"engines": { | ||
"node": ">=14" | ||
"node": ">=16" | ||
}, | ||
@@ -36,17 +36,17 @@ "main": "dist/index.cjs.js", | ||
"dependencies": { | ||
"@mathigon/core": "1.1.10", | ||
"@mathigon/fermat": "1.1.9" | ||
"@mathigon/core": "1.1.11", | ||
"@mathigon/fermat": "1.1.10" | ||
}, | ||
"devDependencies": { | ||
"@types/tape": "5.6.0", | ||
"@typescript-eslint/eslint-plugin": "5.60.1", | ||
"@typescript-eslint/parser": "5.60.1", | ||
"esbuild": "0.18.11", | ||
"eslint": "8.44.0", | ||
"eslint-plugin-import": "2.27.5", | ||
"tape": "5.6.3", | ||
"@typescript-eslint/eslint-plugin": "6.4.0", | ||
"@typescript-eslint/parser": "6.4.0", | ||
"esbuild": "0.18.17", | ||
"eslint": "8.47.0", | ||
"eslint-plugin-import": "2.28.0", | ||
"tape": "5.6.6", | ||
"ts-node": "10.9.1", | ||
"tslib": "2.6.0", | ||
"tslib": "2.6.2", | ||
"typescript": "5.1.6" | ||
} | ||
} |
@@ -18,5 +18,5 @@ // ============================================================================= | ||
readonly type: string = 'arc'; | ||
readonly ['constructor']!: new (c: Point, start: Point, angle: number) => this; | ||
constructor(readonly c: Point, readonly start: Point, | ||
readonly angle: number) { | ||
constructor(readonly c: Point, readonly start: Point, readonly angle: number) { | ||
} | ||
@@ -41,3 +41,3 @@ | ||
contract(p: number): this { | ||
return new (<any> this.constructor)(this.c, this.at(p / 2), this.angle * (1 - p)); | ||
return new this.constructor(this.c, this.at(p / 2), this.angle * (1 - p)); | ||
} | ||
@@ -47,3 +47,3 @@ | ||
if (this.angle <= Math.PI) return this; | ||
return new (<any> this.constructor)(this.c, this.end, TWO_PI - this.angle); | ||
return new this.constructor(this.c, this.end, TWO_PI - this.angle); | ||
} | ||
@@ -53,3 +53,3 @@ | ||
if (this.angle >= Math.PI) return this; | ||
return new (<any> this.constructor)(this.c, this.end, TWO_PI - this.angle); | ||
return new this.constructor(this.c, this.end, TWO_PI - this.angle); | ||
} | ||
@@ -90,3 +90,3 @@ | ||
transform(m: TransformMatrix): this { | ||
return new (<any> this.constructor)(this.c.transform(m), | ||
return new this.constructor(this.c.transform(m), | ||
this.start.transform(m), this.angle); | ||
@@ -98,3 +98,3 @@ } | ||
if (nearlyEquals(a, 0)) return this; | ||
return new (<any> this.constructor)(this.c.rotate(a, c), | ||
return new this.constructor(this.c.rotate(a, c), | ||
this.start.rotate(a, c), this.angle); | ||
@@ -104,3 +104,3 @@ } | ||
reflect(l: Line): this { | ||
return new (<any> this.constructor)(this.c.reflect(l), | ||
return new this.constructor(this.c.reflect(l), | ||
this.start.reflect(l), this.angle); | ||
@@ -110,3 +110,3 @@ } | ||
scale(sx: number, sy = sx): this { | ||
return new (<any> this.constructor)(this.c.scale(sx, sy), | ||
return new this.constructor(this.c.scale(sx, sy), | ||
this.start.scale(sx, sy), this.angle); | ||
@@ -116,3 +116,3 @@ } | ||
shift(x: number, y = x): this { | ||
return new (<any> this.constructor)(this.c.shift(x, y), | ||
return new this.constructor(this.c.shift(x, y), | ||
this.start.shift(x, y), this.angle); | ||
@@ -119,0 +119,0 @@ } |
@@ -119,2 +119,4 @@ // ============================================================================= | ||
class LinkedList<T> { | ||
// TODO Better types without any | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
root: any = {root: true, next: undefined}; | ||
@@ -434,2 +436,5 @@ | ||
const secondMatch = {index: 0, matchesHead: false, matchesPt1: false}; | ||
// TODO Better types without any | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
let nextMatch: any = firstMatch; | ||
@@ -436,0 +441,0 @@ |
@@ -22,8 +22,9 @@ // ============================================================================= | ||
export interface SVGDrawingOptions { | ||
round?: boolean; | ||
size?: number; | ||
fill?: string; | ||
mark?: LineMark; | ||
arrows?: LineArrow; | ||
box?: Rectangle; | ||
round?: boolean; // For angles (round vs square right angles) | ||
size?: number; // For angles | ||
fill?: string; // For angles (stroke arc vs fill sector) | ||
mark?: LineMark; // For lines, rays, segments and arcs | ||
arrows?: LineArrow; // For segments and arcs | ||
box?: Rectangle; // For lines and rays (bounding box) | ||
cornerRadius?: number; // For rectangles and polygons | ||
} | ||
@@ -109,3 +110,9 @@ | ||
// top-left, top-right, btm-right, btm-left corner radius | ||
export function drawRoundedRect(rect: Rectangle, tl: number, tr = tl, br = tl, bl = tr) { | ||
const {p, w, h} = rect; | ||
return `M${p.x} ${p.y + tl}a${tl} ${tl} 0 0 1 ${tl} ${-tl}h${w - tl - tr}a${tr} ${tr} 0 0 1 ${tr} ${tr}v${h - tr - br}a${br} ${br} 0 0 1 ${-br} ${br}h${-w + bl + br}a${bl} ${bl} 0 0 1 ${-bl} ${-bl}Z`; | ||
} | ||
// ----------------------------------------------------------------------------- | ||
@@ -173,2 +180,3 @@ // Draw Function | ||
if (isPolygon(obj)) { | ||
// TODO Implement `options.cornerRadius` | ||
return `${drawPath(...obj.points)}Z`; | ||
@@ -178,3 +186,6 @@ } | ||
if (isRectangle(obj)) { | ||
return `${drawPath(...obj.polygon.points)}Z`; | ||
if (!options.cornerRadius) return `${drawPath(...obj.polygon.points)}Z`; | ||
const rect = obj.unsigned; | ||
const radius = Math.min(options.cornerRadius, rect.w / 2, rect.h / 2); | ||
return drawRoundedRect(rect, radius); | ||
} | ||
@@ -181,0 +192,0 @@ |
@@ -130,3 +130,3 @@ // ============================================================================= | ||
offset(p: Point) { | ||
offset(_p: Point) { | ||
// TODO Implement | ||
@@ -133,0 +133,0 @@ return 0.5; |
@@ -17,2 +17,3 @@ // ============================================================================= | ||
flag?: number; | ||
readonly ['constructor']!: new (p1: Point, p2: Point) => this; | ||
@@ -131,3 +132,3 @@ constructor(readonly p1: Point, readonly p2: Point) {} | ||
transform(m: TransformMatrix): this { | ||
return new (<any> this.constructor)(this.p1.transform(m), this.p2.transform(m)); | ||
return new this.constructor(this.p1.transform(m), this.p2.transform(m)); | ||
} | ||
@@ -138,15 +139,15 @@ | ||
if (nearlyEquals(a, 0)) return this; | ||
return new (<any> this.constructor)(this.p1.rotate(a, c), this.p2.rotate(a, c)); | ||
return new this.constructor(this.p1.rotate(a, c), this.p2.rotate(a, c)); | ||
} | ||
reflect(l: Line): this { | ||
return new (<any> this.constructor)(this.p1.reflect(l), this.p2.reflect(l)); | ||
return new this.constructor(this.p1.reflect(l), this.p2.reflect(l)); | ||
} | ||
scale(sx: number, sy = sx) { | ||
return new (<any> this.constructor)(this.p1.scale(sx, sy), this.p2.scale(sx, sy)); | ||
return new this.constructor(this.p1.scale(sx, sy), this.p2.scale(sx, sy)); | ||
} | ||
shift(x: number, y = x) { | ||
return new (<any> this.constructor)(this.p1.shift(x, y), this.p2.shift(x, y)); | ||
return new this.constructor(this.p1.shift(x, y), this.p2.shift(x, y)); | ||
} | ||
@@ -153,0 +154,0 @@ |
@@ -11,2 +11,3 @@ // ============================================================================= | ||
import {Line} from './line'; | ||
import {isPoint} from './types'; | ||
import {GeoElement, rad, SimplePoint, TransformMatrix} from './utilities'; | ||
@@ -214,5 +215,4 @@ | ||
equals(other: any, precision?: number) { | ||
// TODO Fix type signature for `other` | ||
return Point.equals(this, other, precision); | ||
equals(other: GeoElement|SimplePoint, precision?: number) { | ||
return Point.equals(this, other as SimplePoint, precision); | ||
} | ||
@@ -219,0 +219,0 @@ |
@@ -21,2 +21,3 @@ // ============================================================================= | ||
readonly points: Point[]; | ||
readonly ['constructor']!: new (...points: Point[]) => this; | ||
@@ -88,3 +89,3 @@ constructor(...points: Point[]) { | ||
const points = [...this.points].reverse(); | ||
return new (<any> this.constructor)(...points); | ||
return new this.constructor(...points); | ||
} | ||
@@ -234,3 +235,3 @@ | ||
transform(m: TransformMatrix): this { | ||
return new (<any> this.constructor)(...this.points.map(p => p.transform(m))); | ||
return new this.constructor(...this.points.map(p => p.transform(m))); | ||
} | ||
@@ -242,3 +243,3 @@ | ||
const points = this.points.map(p => p.rotate(a, center)); | ||
return new (<any> this.constructor)(...points); | ||
return new this.constructor(...points); | ||
} | ||
@@ -248,3 +249,3 @@ | ||
const points = this.points.map(p => p.reflect(line)); | ||
return new (<any> this.constructor)(...points); | ||
return new this.constructor(...points); | ||
} | ||
@@ -254,3 +255,3 @@ | ||
const points = this.points.map(p => p.scale(sx, sy)); | ||
return new (<any> this.constructor)(...points); | ||
return new this.constructor(...points); | ||
} | ||
@@ -260,3 +261,3 @@ | ||
const points = this.points.map(p => p.shift(x, y)); | ||
return new (<any> this.constructor)(...points); | ||
return new this.constructor(...points); | ||
} | ||
@@ -263,0 +264,0 @@ |
@@ -51,5 +51,9 @@ // ============================================================================= | ||
get area() { | ||
return Math.abs(this.w * this.h); | ||
return Math.abs(this.signedArea); | ||
} | ||
get signedArea() { | ||
return this.w * this.h; | ||
} | ||
/** @returns {Segment[]} */ | ||
@@ -86,2 +90,8 @@ get edges() { | ||
get unsigned(): Rectangle { | ||
if (this.w > 0 && this.h > 0) return this; | ||
const p = this.p.shift(this.w < 0 ? this.w : 0, this.h < 0 ? this.h : 0); | ||
return new Rectangle(p, Math.abs(this.w), Math.abs(this.h)); | ||
} | ||
// --------------------------------------------------------------------------- | ||
@@ -88,0 +98,0 @@ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
561688
7516
+ Added@mathigon/core@1.1.11(transitive)
+ Added@mathigon/fermat@1.1.10(transitive)
- Removed@mathigon/core@1.1.10(transitive)
- Removed@mathigon/fermat@1.1.9(transitive)
Updated@mathigon/core@1.1.11
Updated@mathigon/fermat@1.1.10