• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java LineSegment类的典型用法和代码示例

java 4次浏览

本文整理汇总了Java中gnu.java.awt.java2d.LineSegment的典型用法代码示例。如果您正苦于以下问题:Java LineSegment类的具体用法?Java LineSegment怎么用?Java LineSegment使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。

LineSegment类属于gnu.java.awt.java2d包,在下文中一共展示了LineSegment类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: joinInnerSegments

点赞 3

import gnu.java.awt.java2d.LineSegment; //导入依赖的package包/类
/**
 * Join a and b segments, removing any overlap
 */
private void joinInnerSegments(Segment a, Segment b, Point2D p)
{
  double[] p0 = a.last.cp2();
  double[] p1 = new double[] { a.last.P2.getX(), a.last.P2.getY() };
  double[] p2 = new double[] { b.P1.getX(), b.P1.getY() };
  double[] p3 = b.cp1();

  if (p == null)
    {
      // Dodgy.
      a.add(new LineSegment(a.last.P2, b.P1));
      p = new Point2D.Double((b.P1.getX() + a.last.P2.getX()) / 2.0,
                             (b.P1.getY() + a.last.P2.getY()) / 2.0);
    }
  else
    // This assumes segments a and b are single segments, which is
    // incorrect - if they are a linked list of segments (ie, passed in
    // from a flattening operation), this produces strange results!!
    a.last.P2 = b.P1 = p;
}
 

开发者ID:vilie,
项目名称:javify,
代码行数:24,
代码来源:BasicStroke.java

示例2: convertPath

点赞 2

import gnu.java.awt.java2d.LineSegment; //导入依赖的package包/类
/**
 * Append the Segments in s to the GeneralPath p
 */
private void convertPath(GeneralPath p, Segment s)
{
  Segment v = s;
  p.moveTo((float)s.P1.getX(), (float)s.P1.getY());

  do
    {
      if(v instanceof LineSegment)
        p.lineTo((float)v.P2.getX(), (float)v.P2.getY());
      else if(v instanceof QuadSegment)
        p.quadTo((float)((QuadSegment)v).cp.getX(),
                 (float)((QuadSegment)v).cp.getY(),
                 (float)v.P2.getX(),
                 (float)v.P2.getY());
      else if(v instanceof CubicSegment)
        p.curveTo((float)((CubicSegment)v).cp1.getX(),
                  (float)((CubicSegment)v).cp1.getY(),
                  (float)((CubicSegment)v).cp2.getX(),
                  (float)((CubicSegment)v).cp2.getY(),
                  (float)v.P2.getX(),
                  (float)v.P2.getY());
      v = v.next;
    } while(v != s && v != null);

  p.closePath();
}
 

开发者ID:vilie,
项目名称:javify,
代码行数:30,
代码来源:BasicStroke.java

示例3: convertPath

点赞 2

import gnu.java.awt.java2d.LineSegment; //导入依赖的package包/类
/**
 * Append the Segments in s to the GeneralPath p
 */
private void convertPath(GeneralPath p, Segment s)
{
  Segment v = s;
  p.moveTo((float)s.P1.getX(), (float)s.P1.getY());

  do
    {
      if(v instanceof LineSegment)
        p.lineTo((float)v.P2.getX(), (float)v.P2.getY());
      else if(v instanceof QuadSegment)
        p.quadTo((float)((QuadSegment)v).cp.getX(),
                 (float)((QuadSegment)v).cp.getY(),
                 (float)v.P2.getX(), 
                 (float)v.P2.getY());
      else if(v instanceof CubicSegment)
        p.curveTo((float)((CubicSegment)v).cp1.getX(),
                  (float)((CubicSegment)v).cp1.getY(),
                  (float)((CubicSegment)v).cp2.getX(),
                  (float)((CubicSegment)v).cp2.getY(),
                  (float)v.P2.getX(), 
                  (float)v.P2.getY());
      v = v.next;
    } while(v != s && v != null);

  p.closePath();
}
 

开发者ID:nmldiegues,
项目名称:jvm-stm,
代码行数:30,
代码来源:BasicStroke.java

示例4: capEnd

点赞 2

import gnu.java.awt.java2d.LineSegment; //导入依赖的package包/类
/**
 * Make a cap between a and b segments,
 * where a-->b is the direction of iteration.
 */
private void capEnd(Segment a, Segment b)
{
  double[] p0, p1;
  double dx, dy, l;
  Point2D c1,c2;

  switch( cap )
    {
    case CAP_BUTT:
      a.add(new LineSegment(a.last.P2, b.P1));
      break;

    case CAP_SQUARE:
      p0 = a.last.cp2();
      p1 = new double[]{a.last.P2.getX(), a.last.P2.getY()};
      dx = p1[0] - p0[0];
      dy = p1[1] - p0[1];
      l = Math.sqrt(dx * dx + dy * dy);
      dx = 0.5*width*dx/l;
      dy = 0.5*width*dy/l;
      c1 = new Point2D.Double(p1[0] + dx, p1[1] + dy);
      c2 = new Point2D.Double(b.P1.getX() + dx, b.P1.getY() + dy);
      a.add(new LineSegment(a.last.P2, c1));
      a.add(new LineSegment(c1, c2));
      a.add(new LineSegment(c2, b.P1));
      break;

    case CAP_ROUND:
      p0 = a.last.cp2();
      p1 = new double[]{a.last.P2.getX(), a.last.P2.getY()};
      dx = p1[0] - p0[0];
      dy = p1[1] - p0[1];
      if (dx != 0 && dy != 0)
        {
          l = Math.sqrt(dx * dx + dy * dy);
          dx = (2.0/3.0)*width*dx/l;
          dy = (2.0/3.0)*width*dy/l;
        }

      c1 = new Point2D.Double(p1[0] + dx, p1[1] + dy);
      c2 = new Point2D.Double(b.P1.getX() + dx, b.P1.getY() + dy);
      a.add(new CubicSegment(a.last.P2, c1, c2, b.P1));
      break;
    }
  a.add(b);
}
 

开发者ID:vilie,
项目名称:javify,
代码行数:51,
代码来源:BasicStroke.java

示例5: joinOuterSegments

点赞 2

import gnu.java.awt.java2d.LineSegment; //导入依赖的package包/类
/**
 * Join a and b segments, where a-->b is the direction of iteration.
 *
 * insideP is the inside intersection point of the join, needed for
 * calculating miter lengths.
 */
private void joinOuterSegments(Segment a, Segment b, Point2D insideP)
{
  double[] p0, p1;
  double dx, dy, l;
  Point2D c1,c2;

  switch( join )
    {
    case JOIN_MITER:
      p0 = a.last.cp2();
      p1 = new double[]{a.last.P2.getX(), a.last.P2.getY()};
      double[] p2 = new double[]{b.P1.getX(), b.P1.getY()};
      double[] p3 = b.cp1();
      Point2D p = lineIntersection(p0[0],p0[1],p1[0],p1[1],p2[0],p2[1],p3[0],p3[1], true);
      if( p == null || insideP == null )
        a.add(new LineSegment(a.last.P2, b.P1));
      else if((p.distance(insideP)/width) < limit)
        {
          a.add(new LineSegment(a.last.P2, p));
          a.add(new LineSegment(p, b.P1));
        }
      else
        {
          // outside miter limit, do a bevel join.
          a.add(new LineSegment(a.last.P2, b.P1));
        }
      break;

    case JOIN_ROUND:
      p0 = a.last.cp2();
      p1 = new double[]{a.last.P2.getX(), a.last.P2.getY()};
      dx = p1[0] - p0[0];
      dy = p1[1] - p0[1];
      l = Math.sqrt(dx * dx + dy * dy);
      dx = 0.5*width*dx/l;
      dy = 0.5*width*dy/l;
      c1 = new Point2D.Double(p1[0] + dx, p1[1] + dy);

      p0 = new double[]{b.P1.getX(), b.P1.getY()};
      p1 = b.cp1();

      dx = p0[0] - p1[0]; // backwards direction.
      dy = p0[1] - p1[1];
      l = Math.sqrt(dx * dx + dy * dy);
      dx = 0.5*width*dx/l;
      dy = 0.5*width*dy/l;
      c2 = new Point2D.Double(p0[0] + dx, p0[1] + dy);
      a.add(new CubicSegment(a.last.P2, c1, c2, b.P1));
      break;

    case JOIN_BEVEL:
      a.add(new LineSegment(a.last.P2, b.P1));
      break;
    }
}
 

开发者ID:vilie,
项目名称:javify,
代码行数:62,
代码来源:BasicStroke.java

示例6: capEnd

点赞 2

import gnu.java.awt.java2d.LineSegment; //导入依赖的package包/类
/**
 * Make a cap between a and b segments, 
 * where a-->b is the direction of iteration.
 */
private void capEnd(Segment a, Segment b)
{
  double[] p0, p1;
  double dx, dy, l;
  Point2D c1,c2;

  switch( cap )
    {
    case CAP_BUTT:
      a.add(new LineSegment(a.last.P2, b.P1));
      break;

    case CAP_SQUARE:
      p0 = a.last.cp2();
      p1 = new double[]{a.last.P2.getX(), a.last.P2.getY()};
      dx = p1[0] - p0[0];
      dy = p1[1] - p0[1];
      l = Math.sqrt(dx * dx + dy * dy);
      dx = 0.5*width*dx/l;
      dy = 0.5*width*dy/l;
      c1 = new Point2D.Double(p1[0] + dx, p1[1] + dy);
      c2 = new Point2D.Double(b.P1.getX() + dx, b.P1.getY() + dy);
      a.add(new LineSegment(a.last.P2, c1));
      a.add(new LineSegment(c1, c2));
      a.add(new LineSegment(c2, b.P1));
      break;

    case CAP_ROUND:
      p0 = a.last.cp2();
      p1 = new double[]{a.last.P2.getX(), a.last.P2.getY()};
      dx = p1[0] - p0[0];
      dy = p1[1] - p0[1];
      if (dx != 0 && dy != 0)
        {
          l = Math.sqrt(dx * dx + dy * dy);
          dx = (2.0/3.0)*width*dx/l;
          dy = (2.0/3.0)*width*dy/l;
        }
      
      c1 = new Point2D.Double(p1[0] + dx, p1[1] + dy);
      c2 = new Point2D.Double(b.P1.getX() + dx, b.P1.getY() + dy);
      a.add(new CubicSegment(a.last.P2, c1, c2, b.P1));
      break;
    }
  a.add(b);
}
 

开发者ID:nmldiegues,
项目名称:jvm-stm,
代码行数:51,
代码来源:BasicStroke.java

示例7: joinOuterSegments

点赞 2

import gnu.java.awt.java2d.LineSegment; //导入依赖的package包/类
/**
 * Join a and b segments, where a-->b is the direction of iteration.
 *
 * insideP is the inside intersection point of the join, needed for
 * calculating miter lengths.
 */
private void joinOuterSegments(Segment a, Segment b, Point2D insideP)
{
  double[] p0, p1;
  double dx, dy, l;
  Point2D c1,c2;

  switch( join )
    {
    case JOIN_MITER:
      p0 = a.last.cp2();
      p1 = new double[]{a.last.P2.getX(), a.last.P2.getY()};
      double[] p2 = new double[]{b.P1.getX(), b.P1.getY()};
      double[] p3 = b.cp1();
      Point2D p = lineIntersection(p0[0],p0[1],p1[0],p1[1],p2[0],p2[1],p3[0],p3[1], true);
      if( p == null || insideP == null )
        a.add(new LineSegment(a.last.P2, b.P1));
      else if((p.distance(insideP)/width) < limit)
        {
          a.add(new LineSegment(a.last.P2, p));
          a.add(new LineSegment(p, b.P1));
        } 
      else
        {
          // outside miter limit, do a bevel join.
          a.add(new LineSegment(a.last.P2, b.P1));
        }
      break;

    case JOIN_ROUND:
      p0 = a.last.cp2();
      p1 = new double[]{a.last.P2.getX(), a.last.P2.getY()};
      dx = p1[0] - p0[0];
      dy = p1[1] - p0[1];
      l = Math.sqrt(dx * dx + dy * dy);
      dx = 0.5*width*dx/l;
      dy = 0.5*width*dy/l;
      c1 = new Point2D.Double(p1[0] + dx, p1[1] + dy);

      p0 = new double[]{b.P1.getX(), b.P1.getY()};
      p1 = b.cp1();

      dx = p0[0] - p1[0]; // backwards direction.
      dy = p0[1] - p1[1];
      l = Math.sqrt(dx * dx + dy * dy);
      dx = 0.5*width*dx/l;
      dy = 0.5*width*dy/l;
      c2 = new Point2D.Double(p0[0] + dx, p0[1] + dy);
      a.add(new CubicSegment(a.last.P2, c1, c2, b.P1));
      break;

    case JOIN_BEVEL:
      a.add(new LineSegment(a.last.P2, b.P1));
      break;
    }
}
 

开发者ID:nmldiegues,
项目名称:jvm-stm,
代码行数:62,
代码来源:BasicStroke.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)