⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pixeltools.java

📁 EclipseTrader is a stock exchange analysis system, featuring shares pricing watch, intraday and hi
💻 JAVA
字号:
/* * Copyright (c) 2004-2006 Marco Maccaferri and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: *     Marco Maccaferri - initial API and implementation */package net.sourceforge.eclipsetrader.charts.internal;/** */public class PixelTools{  /**   * Determine if the point (x,y) lies on the polyline defined by the given pointArray parameter.   *    * @param x - the reference point x position   * @param y - the reference point y position   * @param pointArray - the polyline array of (x,y) values   * @return true if the reference point is on the line, false otherwise   */  public static boolean isPointOnLine(int x, int y, int[] pointArray)  {    for (int i = 3; i < pointArray.length; i += 2)    {      if (isPointOnLine(x, y, pointArray[i - 3], pointArray[i - 2], pointArray[i - 1], pointArray[i]))        return true;    }    return false;  }  /**   * Determine if the point (x,y) lies on the line (x1,y1)-(x2,y2).   * <p>This is the Bresenham's Algorithm for approximating lines, modified to compare the calculated point   * against the reference point instead of drawing. This may not be the most efficent way for doing this   * job but it works and it is very precise.</p>   *    * @param x - the reference point x position   * @param y - the reference point y position   * @param x1 - the starting point x position   * @param y1 - the starting point y position   * @param x2 - the ending point x position   * @param y2 - the ending point y position   * @return true if the reference point is on the line, false otherwise   */  public static boolean isPointOnLine(int x, int y, int x1, int y1, int x2, int y2)  {    int d;             /* Decision variable */    int dx, dy;        /* Dx and Dy values for the line */    int Eincr, NEincr; /* Decision variable increments */    int yincr;         /* Increment for y values */    int tmp;           /* Counters etc. */    dx = Math.abs(x2 - x1);    dy = Math.abs(y2 - y1);    if (dy <= dx)    {      /*       * We have a line with slope (|1/2| >= slope) (ie: includes horizontal       * lines). Ensure that we are always scan converting the line from left to       * right to ensure that we produce the same line from P1 to P0 as the line       * from P0 to P1.       */      if (x2 < x1)      {        tmp = x2; x2 = x1; x1 = tmp; /* Swap X coordinates */        tmp = y2; y2 = y1; y1 = tmp; /* Swap Y coordinates */      }      if (y2 > y1)        yincr = 1;      else        yincr = -1;      d = 2 * dy - dx;        /* Initial decision variable value */      Eincr = 2 * dy;         /* Increment to move to E pixel */      NEincr = 2 * (dy - dx); /* Increment to move to NE pixel */      /* Draw the first point at (x1,y1) */      if (Math.abs(x - x1) <= 1 && Math.abs(y - y1) <= 1)        return true;      // putPixel(x1,y1,color);       /* Incrementally determine the positions of the remaining pixels */      for (x1++; x1 <= x2; x1++)      {        if (d < 0)          d += Eincr;  /* Choose the Eastern Pixel */        else        {          d += NEincr; /* Choose the North Eastern Pixel */          y1 += yincr; /* (or SE pixel for dx/dy < 0!) */        }                /* Draw the point */        if (Math.abs(x - x1) <= 1 && Math.abs(y - y1) <= 1)          return true;        // putPixel(x1,y1,color);      }    }    else    {      /*       * We have a line with slope (|1/2| < slope) (ie: includes vertical       * lines). We must swap our x and y coordinates for this. Ensure that we       * are always scan converting the line from left to right to ensure that       * we produce the same line from P1 to P0 as the line from P0 to P1.       */      if (y2 < y1)      {        tmp = x2; x2 = x1; x1 = tmp; /* Swap X coordinates */        tmp = y2; y2 = y1; y1 = tmp; /* Swap Y coordinates */      }      if (x2 > x1)        yincr = 1;      else        yincr = -1;      d = 2 * dx - dy;        /* Initial decision variable value */      Eincr = 2 * dx;         /* Increment to move to E pixel */      NEincr = 2 * (dx - dy); /* Increment to move to NE pixel */            /* Draw the first point at (x1,y1) */      if (Math.abs(x - x1) <= 1 && Math.abs(y - y1) <= 1)        return true;      // putPixel(x1,y1,color);       /* Incrementally determine the positions of the remaining pixels */      for (y1++; y1 <= y2; y1++)      {        if (d < 0)          d += Eincr;  /* Choose the Eastern Pixel */        else        {          d += NEincr; /* Choose the North Eastern Pixel */          x1 += yincr; /* (or SE pixel for dx/dy < 0!) */        }                /* Draw the point */        if (Math.abs(x - x1) <= 1 && Math.abs(y - y1) <= 1)          return true;        // putPixel(x1,y1,color);      }    }    return false;  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -