mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
* PLT-5380 Moved link preview image to top right corner of preview area for smaller images, larger and wide images are still shown below the text. Also added logic to hide image area if image loading fails. * Updating link previews css
21 lines
915 B
JavaScript
21 lines
915 B
JavaScript
export function getDistanceBW2Points(point1, point2, xAttr = 'x', yAttr = 'y') {
|
|
return Math.sqrt(Math.pow(point1[xAttr] - point2[xAttr], 2) + Math.pow(point1[yAttr] - point2[yAttr], 2));
|
|
}
|
|
|
|
/**
|
|
* Funtion to return nearest point of given pivot point.
|
|
* It return two points one nearest and other nearest but having both coorditanes smaller than the given point's coordinates.
|
|
*/
|
|
export function getNearestPoint(pivotPoint, points, xAttr = 'x', yAttr = 'y') {
|
|
var nearestPoint = {};
|
|
for (const point of points) {
|
|
if (typeof nearestPoint[xAttr] === 'undefined' || typeof nearestPoint[yAttr] === 'undefined') {
|
|
nearestPoint = point;
|
|
} else if (getDistanceBW2Points(point, pivotPoint, xAttr, yAttr) < getDistanceBW2Points(nearestPoint, pivotPoint, xAttr, yAttr)) {
|
|
// Check for bestImage
|
|
nearestPoint = point;
|
|
}
|
|
}
|
|
return nearestPoint;
|
|
}
|