How to use the @projectstorm/geometry.Rectangle function in @projectstorm/geometry

To help you get started, we’ve selected a few @projectstorm/geometry examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github projectstorm / react-diagrams / packages / react-diagrams-core / src / DiagramEngine.ts View on Github external
getPortCoords(port: PortModel, element?: HTMLDivElement): Rectangle {
		if (!this.canvas) {
			throw new Error('Canvas needs to be set first');
		}
		if (!element) {
			element = this.getNodePortElement(port);
		}
		const sourceRect = element.getBoundingClientRect();
		const point = this.getRelativeMousePoint({
			clientX: sourceRect.left,
			clientY: sourceRect.top
		});
		const zoom = this.model.getZoomLevel() / 100.0;
		return new Rectangle(point.x, point.y, sourceRect.width / zoom, sourceRect.height / zoom);
	}
github projectstorm / react-diagrams / packages / react-canvas-core / src / states / SelectionBoxState.ts View on Github external
fireMouseMoved(event: AbstractDisplacementStateEvent) {
		this.layer.setBox(this.getBoxDimensions(event));

		const relative = this.engine.getRelativeMousePoint({
			clientX: this.initialX,
			clientY: this.initialY
		});
		if (event.virtualDisplacementX < 0) {
			relative.x -= Math.abs(event.virtualDisplacementX);
		}
		if (event.virtualDisplacementY < 0) {
			relative.y -= Math.abs(event.virtualDisplacementY);
		}
		const rect = new Rectangle(relative, Math.abs(event.virtualDisplacementX), Math.abs(event.virtualDisplacementY));

		for (let model of this.engine.getModel().getSelectionEntities()) {
			if (((model as unknown) as ModelGeometryInterface).getBoundingBox) {
				const bounds = ((model as unknown) as ModelGeometryInterface).getBoundingBox();
				if (rect.containsPoint(bounds.getTopLeft()) && rect.containsPoint(bounds.getBottomRight())) {
					model.setSelected(true);
				} else {
					model.setSelected(false);
				}
			}
		}

		this.engine.repaintCanvas();
	}
}