@eclipse-glsp/protocol
Version:
The protocol definition for client-server communication in GLSP
82 lines (81 loc) • 3.61 kB
JavaScript
"use strict";
/********************************************************************************
* Copyright (c) 2024 EclipseSource and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the Eclipse
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
* with the GNU Classpath Exception which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/
Object.defineProperty(exports, "__esModule", { value: true });
exports.Movement = void 0;
const sprotty_geometry_point_1 = require("../sprotty-geometry-point");
const geometry_vector_1 = require("./geometry-vector");
const type_util_1 = require("./type-util");
/**
* A collection of utility functions for working with movements.
*/
var Movement;
(function (Movement) {
/**
* The zero movement. It has from and to set to the origin and the vector set to zero.
*/
Movement.ZERO = Object.freeze({
from: sprotty_geometry_point_1.Point.ORIGIN,
to: sprotty_geometry_point_1.Point.ORIGIN,
vector: geometry_vector_1.Vector.ZERO,
direction: []
});
/**
* A type guard that checks if the given object is a movement.
* @param obj the object to check
* @returns true if the object is a movement, false otherwise
*/
function is(obj) {
return (type_util_1.AnyObject.is(obj) &&
(0, type_util_1.hasObjectProp)(obj, 'from') &&
sprotty_geometry_point_1.Point.is(obj.from) &&
(0, type_util_1.hasObjectProp)(obj, 'to') &&
sprotty_geometry_point_1.Point.is(obj.to) &&
(0, type_util_1.hasObjectProp)(obj, 'vector') &&
geometry_vector_1.Vector.is(obj.to) &&
(0, type_util_1.hasObjectProp)(obj, 'direction'));
}
Movement.is = is;
/**
* Checks if the given movement is stationary, i.e. the starting point and end point are equal and the vector is zero.
* @param movement the movement to check
* @returns true if the movement is stationary, false otherwise
*/
function isStationary(movement) {
return geometry_vector_1.Vector.isZero(movement.vector);
}
Movement.isStationary = isStationary;
/**
* Checks if the given movement is zero, i.e., all values are zero.
* @param movement the movement to check
* @returns true if the movement is zero, false otherwise
*/
function isZero(movement) {
return Movement.equals(movement, Movement.ZERO);
}
Movement.isZero = isZero;
/**
* Checks if two movements are equal. Two movements are equal if their starting points, end points, and vectors are equal.
* @param left the left movement
* @param right the right movement
* @returns true if the movements are equal, false otherwise
*/
function equals(left, right) {
return sprotty_geometry_point_1.Point.equals(left.from, right.from) && sprotty_geometry_point_1.Point.equals(left.to, right.to) && geometry_vector_1.Vector.equals(left.vector, right.vector);
}
Movement.equals = equals;
})(Movement || (exports.Movement = Movement = {}));
//# sourceMappingURL=geometry-movement.js.map