mathigon / euclid.js

2D Euclidean geometry classes, utilities, and drawing tools

Home Page:https://mathigon.io/euclid

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Extending Rectangle

nishirken opened this issue · comments

Hello, some functionality can be added to the Rectangle class:

/**
Restricts the rectangle within another larger rectangle.
{x: -50, y: -50, w: 100, y: 100} restrictWithin {x: 0: y: 0, w: 500, h: 500} -> {x: 0, y: 0, w: 100, y: 100}
*/
restrictWithin(rect: Rectangle): Rectangle;

This also can be added to Circle and Ellipse classes. The method can be overloaded:

restrictWithin(rect: Rectangle): Rectangle;
restrictWithin(rect: Circle): Rectangle;
restrictWithin(rect: Ellipse): Rectangle;