org.eclipse.jface.util.Geometry.distanceSquared()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(4.0k)|赞(0)|评价(0)|浏览(91)

本文整理了Java中org.eclipse.jface.util.Geometry.distanceSquared()方法的一些代码示例,展示了Geometry.distanceSquared()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Geometry.distanceSquared()方法的具体详情如下:
包路径:org.eclipse.jface.util.Geometry
类名称:Geometry
方法名:distanceSquared

Geometry.distanceSquared介绍

[英]Returns the square of the distance between two points.

This is preferred over the real distance when searching for the closest point, since it avoids square roots.
[中]返回两点之间距离的平方。
在搜索最近点时,这比实际距离更可取,因为它避免了平方根。

代码示例

代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.jdt.ui

/**
 * Returns the monitor whose client area contains the given point. If no monitor contains the
 * point, returns the monitor that is closest to the point.
 * <p>
 * Copied from <code>org.eclipse.jface.window.Window.getClosestMonitor(Display, Point)</code>
 * </p>
 *
 * @param display the display showing the monitors
 * @param point point to find (display coordinates)
 * @return the monitor closest to the given point
 */
private static Monitor getClosestMonitor(Display display, Point point) {
  int closest= Integer.MAX_VALUE;
  Monitor[] monitors= display.getMonitors();
  Monitor result= monitors[0];
  for (int i= 0; i < monitors.length; i++) {
    Monitor current= monitors[i];
    Rectangle clientArea= current.getClientArea();
    if (clientArea.contains(point))
      return current;
    int distance= Geometry.distanceSquared(Geometry.centerPoint(clientArea), point);
    if (distance < closest) {
      closest= distance;
      result= current;
    }
  }
  return result;
}

代码示例来源:origin: org.eclipse.rap/org.eclipse.rap.jface

int distance = Geometry.distanceSquared(Geometry
    .centerPoint(clientArea), toFind);
if (distance < closest) {

代码示例来源:origin: org.eclipse.platform/org.eclipse.jface

int distance = Geometry.distanceSquared(Geometry.centerPoint(clientArea), toFind);
if (distance < closest) {
  closest = distance;

代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.jface

int distance = Geometry.distanceSquared(Geometry
    .centerPoint(clientArea), toFind);
if (distance < closest) {

代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.jface.text

/**
 * Copied from org.eclipse.jface.window.Window. Returns the monitor whose client area contains
 * the given point. If no monitor contains the point, returns the monitor that is closest to the
 * point. If this is ever made public, it should be moved into a separate utility class.
 *
 * @param display the display to search for monitors
 * @param rectangle the rectangle to find the closest monitor for (display coordinates)
 * @return the monitor closest to the given point
 * @since 3.3
 */
private Monitor getClosestMonitor(Display display, Rectangle rectangle) {
  int closest = Integer.MAX_VALUE;
  Point toFind= Geometry.centerPoint(rectangle);
  Monitor[] monitors = display.getMonitors();
  Monitor result = monitors[0];
  for (int idx = 0; idx < monitors.length; idx++) {
    Monitor current = monitors[idx];
    Rectangle clientArea = current.getClientArea();
    if (clientArea.contains(toFind)) {
      return current;
    }
    int distance = Geometry.distanceSquared(Geometry.centerPoint(clientArea), toFind);
    if (distance < closest) {
      closest = distance;
      result = current;
    }
  }
  return result;
}

代码示例来源:origin: org.eclipse.platform/org.eclipse.jface.text

/**
   * Copied from org.eclipse.jface.window.Window. Returns the monitor whose client area
   * contains the given point. If no monitor contains the point, returns the monitor that is
   * closest to the point. If this is ever made public, it should be moved into a separate
   * utility class.
   *
   * @param toSearch point to find (display coordinates)
   * @param rectangle rectangle to find (display coordinates)
   * @return the monitor closest to the given point
   * @since 3.3
   */
  private Monitor getClosestMonitor(Display toSearch, Rectangle rectangle) {
    int closest = Integer.MAX_VALUE;
    Point toFind= Geometry.centerPoint(rectangle);
    Monitor[] monitors = toSearch.getMonitors();
    Monitor result = monitors[0];
    for (Monitor current : monitors) {
      Rectangle clientArea = current.getClientArea();
      if (clientArea.contains(toFind)) {
        return current;
      }
      int distance = Geometry.distanceSquared(Geometry.centerPoint(clientArea), toFind);
      if (distance < closest) {
        closest = distance;
        result = current;
      }
    }
    return result;
  }
}

代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.jface.text

int distance = Geometry.distanceSquared(Geometry.centerPoint(clientArea), toFind);
if (distance < closest) {
  closest = distance;

相关文章