mirror of
https://git.leinelab.org/Mal/mr-crocs-adventures.git
synced 2025-09-11 02:57:36 +02:00
Gravity and ground height.
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import GeometryPoint from "./GeometryPoint.js";
|
||||
import GeometryStroke from "./GeometryStroke.js";
|
||||
import GeometryPointCollection from "./GeometryPointCollection.js";
|
||||
import GeometryLine from "./GeometryLine.js";
|
||||
|
||||
export default class GeometryRect
|
||||
{
|
||||
@@ -26,12 +25,17 @@ export default class GeometryRect
|
||||
*/
|
||||
isContainingPoint(geometryPoint)
|
||||
{
|
||||
let containsHorizontally = geometryPoint.x >= this.position.x && geometryPoint.x <= this.position.x + this.width;
|
||||
let containsVertically = geometryPoint.y >= this.position.y && geometryPoint.y <= this.position.y + this.height;
|
||||
let containsHorizontally = geometryPoint.x >= this.position.x && geometryPoint.x < this.position.x + this.width;
|
||||
let containsVertically = geometryPoint.y >= this.position.y && geometryPoint.y < this.position.y + this.height;
|
||||
|
||||
return containsHorizontally && containsVertically;
|
||||
}
|
||||
|
||||
isEqual(rect)
|
||||
{
|
||||
return rect.x === this.x && rect.y === this.y && rect.width === this.width && rect.height === this.height;
|
||||
}
|
||||
|
||||
hasIntersectionWithRect(rect)
|
||||
{
|
||||
return this.getBorderIntersectonsWithRect(rect).getLength() > 0;
|
||||
@@ -170,8 +174,8 @@ export default class GeometryRect
|
||||
|
||||
collection.addGeometryPoint(this.position);
|
||||
collection.addGeometryPoint(new GeometryPoint(this.position.x + this.width, this.position.y));
|
||||
collection.addGeometryPoint(new GeometryPoint(this.position.x, this.position.y + this.height));
|
||||
collection.addGeometryPoint(new GeometryPoint(this.position.x + this.width, this.position.y + this.height));
|
||||
collection.addGeometryPoint(new GeometryPoint(this.position.x, this.position.y + this.height - 1));
|
||||
collection.addGeometryPoint(new GeometryPoint(this.position.x + this.width, this.position.y + this.height - 1));
|
||||
|
||||
return collection;
|
||||
}
|
||||
|
||||
133
js/geometry/GeometryRectCollection.js
Normal file
133
js/geometry/GeometryRectCollection.js
Normal file
@@ -0,0 +1,133 @@
|
||||
export default class GeometryRectCollection
|
||||
{
|
||||
constructor()
|
||||
{
|
||||
this.rects = [];
|
||||
}
|
||||
|
||||
isContainingRect(rect)
|
||||
{
|
||||
for (let r = 0; r < this.rects.length; r++) {
|
||||
if (rect.isEqual(this.rects[r])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
getUniqueWidth()
|
||||
{
|
||||
if (this.getLength() === 0) {
|
||||
return null;
|
||||
} else if (this.getLength() === 1) {
|
||||
return this.rects[0];
|
||||
}
|
||||
|
||||
let widths = [this.rects[0].width];
|
||||
|
||||
for (let r = 0; r < this.getLength(); r++) {
|
||||
if (widths.indexOf(this.rects[r].width) !== -1) {
|
||||
return this.rects[r];
|
||||
}
|
||||
|
||||
widths.push(rect.width);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
getUniqueHeight()
|
||||
{
|
||||
if (this.getLength() === 0) {
|
||||
return null;
|
||||
} else if (this.getLength() === 1) {
|
||||
return this.rects[0].height;
|
||||
}
|
||||
|
||||
let heights = [this.rects[0].height];
|
||||
|
||||
for (let r = 0; r < this.getLength(); r++) {
|
||||
if (heights.indexOf(rect.height) !== -1) {
|
||||
return rect.height;
|
||||
}
|
||||
|
||||
heights.push(rect.height);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
addRect(rect)
|
||||
{
|
||||
if (!this.isContainingRect(rect)) {
|
||||
this.rects.push(rect);
|
||||
}
|
||||
}
|
||||
|
||||
getLength()
|
||||
{
|
||||
return this.rects.length;
|
||||
}
|
||||
|
||||
getEqualWidths()
|
||||
{
|
||||
if (this.getLength() === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
let width = this.rects[0].width;
|
||||
|
||||
for (let r = 1; r < this.getLength(); r++) {
|
||||
if (this.rects[r].width === width) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
hasEqualWidths()
|
||||
{
|
||||
if (this.getLength() === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let width = this.rects[0].width;
|
||||
|
||||
for (let r = 1; r < this.getLength(); r++) {
|
||||
if (this.rects[r].width !== width) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
hasEqualHeights()
|
||||
{
|
||||
if (this.getLength() === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let height = this.rects[0].height;
|
||||
|
||||
for (let r = 1; r < this.getLength(); r++) {
|
||||
if (this.rects[r].height !== height) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
forEach(callback)
|
||||
{
|
||||
this.rects.forEach(callback);
|
||||
}
|
||||
|
||||
getRect(index)
|
||||
{
|
||||
return this.rects[index];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user