@mathigon/euclid
Advanced tools
Comparing version 1.1.4 to 1.1.5
@@ -8,3 +8,7 @@ import { Point } from './point'; | ||
yMax: number; | ||
constructor(xMin: number, xMax: number, yMin: number, yMax: number); | ||
/** | ||
* Use the `errorHandling` option to decide how to deal with cases where the | ||
* min and max values are in the wrong order. | ||
*/ | ||
constructor(xMin: number, xMax: number, yMin: number, yMax: number, errorHandling?: 'swap' | 'center'); | ||
contains(p: Point): boolean; | ||
@@ -11,0 +15,0 @@ containsX(p: Point): boolean; |
@@ -1652,2 +1652,5 @@ "use strict"; | ||
} | ||
get bounds() { | ||
return new Bounds(this.p.x, this.p.x + this.w, this.p.y, this.p.y + this.h); | ||
} | ||
collision(r) { | ||
@@ -1707,3 +1710,3 @@ return this.p.x < r.p.x + r.w && this.p.x + this.w > r.p.x && this.p.y < r.p.y + r.h && this.p.y + this.h > r.p.y; | ||
var Bounds = class { | ||
constructor(xMin, xMax, yMin, yMax) { | ||
constructor(xMin, xMax, yMin, yMax, errorHandling) { | ||
this.xMin = xMin; | ||
@@ -1713,2 +1716,13 @@ this.xMax = xMax; | ||
this.yMax = yMax; | ||
if (errorHandling === "swap") { | ||
if (this.dx < 0) | ||
[this.xMin, this.xMax] = [xMax, xMin]; | ||
if (this.dy < 0) | ||
[this.yMin, this.yMax] = [yMax, yMin]; | ||
} else if (errorHandling === "center") { | ||
if (this.dx < 0) | ||
this.xMin = this.xMax = (xMin + xMax) / 2; | ||
if (this.dy < 0) | ||
this.yMin = this.yMax = (yMin + yMax) / 2; | ||
} | ||
} | ||
@@ -1715,0 +1729,0 @@ contains(p) { |
@@ -1587,2 +1587,5 @@ // src/angle.ts | ||
} | ||
get bounds() { | ||
return new Bounds(this.p.x, this.p.x + this.w, this.p.y, this.p.y + this.h); | ||
} | ||
collision(r) { | ||
@@ -1642,3 +1645,3 @@ return this.p.x < r.p.x + r.w && this.p.x + this.w > r.p.x && this.p.y < r.p.y + r.h && this.p.y + this.h > r.p.y; | ||
var Bounds = class { | ||
constructor(xMin, xMax, yMin, yMax) { | ||
constructor(xMin, xMax, yMin, yMax, errorHandling) { | ||
this.xMin = xMin; | ||
@@ -1648,2 +1651,13 @@ this.xMax = xMax; | ||
this.yMax = yMax; | ||
if (errorHandling === "swap") { | ||
if (this.dx < 0) | ||
[this.xMin, this.xMax] = [xMax, xMin]; | ||
if (this.dy < 0) | ||
[this.yMin, this.yMax] = [yMax, yMin]; | ||
} else if (errorHandling === "center") { | ||
if (this.dx < 0) | ||
this.xMin = this.xMax = (xMin + xMax) / 2; | ||
if (this.dy < 0) | ||
this.yMin = this.yMax = (yMin + yMax) / 2; | ||
} | ||
} | ||
@@ -1650,0 +1664,0 @@ contains(p) { |
@@ -0,1 +1,2 @@ | ||
import { Bounds } from './bounds'; | ||
import { Line } from './line'; | ||
@@ -24,2 +25,3 @@ import { Point } from './point'; | ||
get polygon(): Polygon; | ||
get bounds(): Bounds; | ||
collision(r: Rectangle): boolean; | ||
@@ -26,0 +28,0 @@ padding(top: number, right: number, bottom: number, left: number): Rectangle; |
{ | ||
"name": "@mathigon/euclid", | ||
"version": "1.1.4", | ||
"version": "1.1.5", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "homepage": "https://mathigon.io/euclid", |
@@ -14,4 +14,15 @@ // ============================================================================= | ||
/** | ||
* Use the `errorHandling` option to decide how to deal with cases where the | ||
* min and max values are in the wrong order. | ||
*/ | ||
constructor(public xMin: number, public xMax: number, public yMin: number, | ||
public yMax: number) { | ||
public yMax: number, errorHandling?: 'swap'|'center') { | ||
if (errorHandling === 'swap') { | ||
if (this.dx < 0) [this.xMin, this.xMax] = [xMax, xMin]; | ||
if (this.dy < 0) [this.yMin, this.yMax] = [yMax, yMin]; | ||
} else if (errorHandling === 'center') { | ||
if (this.dx < 0) this.xMin = this.xMax = (xMin + xMax) / 2; | ||
if (this.dy < 0) this.yMin = this.yMax = (yMin + yMax) / 2; | ||
} | ||
} | ||
@@ -18,0 +29,0 @@ |
@@ -8,2 +8,3 @@ // ============================================================================= | ||
import {isBetween, nearlyEquals} from '@mathigon/fermat'; | ||
import {Bounds} from './bounds'; | ||
import {Line} from './line'; | ||
@@ -72,2 +73,6 @@ import {ORIGIN, Point} from './point'; | ||
get bounds() { | ||
return new Bounds(this.p.x, this.p.x + this.w, this.p.y, this.p.y + this.h); | ||
} | ||
collision(r: Rectangle) { | ||
@@ -74,0 +79,0 @@ return (this.p.x < r.p.x + r.w && this.p.x + this.w > r.p.x && |
Sorry, the diff of this file is not supported yet
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
526794
7127