OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libjava/] [classpath/] [gnu/] [java/] [awt/] [java2d/] [LineSegment.java] - Blame information for rev 769

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 769 jeremybenn
/* LineSegment.java -- Line segment used for BasicStroke
2
   Copyright (C) 2006 Free Software Foundation, Inc.
3
 
4
This file is part of GNU Classpath.
5
 
6
GNU Classpath is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2, or (at your option)
9
any later version.
10
 
11
GNU Classpath is distributed in the hope that it will be useful, but
12
WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
General Public License for more details.
15
 
16
You should have received a copy of the GNU General Public License
17
along with GNU Classpath; see the file COPYING.  If not, write to the
18
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19
02110-1301 USA.
20
 
21
Linking this library statically or dynamically with other modules is
22
making a combined work based on this library.  Thus, the terms and
23
conditions of the GNU General Public License cover the whole
24
combination.
25
 
26
As a special exception, the copyright holders of this library give you
27
permission to link this library with independent modules to produce an
28
executable, regardless of the license terms of these independent
29
modules, and to copy and distribute the resulting executable under
30
terms of your choice, provided that you also meet, for each linked
31
independent module, the terms and conditions of the license of that
32
module.  An independent module is a module which is not derived from
33
or based on this library.  If you modify this library, you may extend
34
this exception to your version of the library, but you are not
35
obligated to do so.  If you do not wish to do so, delete this
36
exception statement from your version. */
37
 
38
 
39
package gnu.java.awt.java2d;
40
 
41
 
42
import java.awt.geom.Point2D;
43
 
44
public class LineSegment extends Segment
45
{
46
  public LineSegment(double x1, double y1, double x2, double y2)
47
  {
48
    super();
49
    P1 = new Point2D.Double(x1, y1);
50
    P2 = new Point2D.Double(x2, y2);
51
  }
52
 
53
  public LineSegment(Point2D p1, Point2D p2)
54
  {
55
    super();
56
    P1 = (Point2D) p1.clone();
57
    P2 = (Point2D) p2.clone();
58
  }
59
 
60
  /**
61
   * Clones this segment
62
   */
63
  public Object clone()
64
  {
65
    LineSegment segment = null;
66
 
67
    try
68
      {
69
        segment = (LineSegment) super.clone();
70
        segment.P1 = (Point2D) P1.clone();
71
        segment.P2 = (Point2D) P2.clone();
72
      }
73
    catch (CloneNotSupportedException cnse)
74
      {
75
        InternalError ie = new InternalError();
76
        ie.initCause(cnse);
77
        throw ie;
78
      }
79
 
80
    return segment;
81
  }
82
 
83
  /**
84
   * Get the "top" and "bottom" segments of this segment.
85
   * First array element is p0 + normal, second is p0 - normal.
86
   */
87
  public Segment[] getDisplacedSegments(double radius)
88
  {
89
    this.radius = radius;
90
    double x0 = P1.getX();
91
    double y0 = P1.getY();
92
    double x1 = P2.getX();
93
    double y1 = P2.getY();
94
    double[] p = normal(x0, y0, x1, y1);
95
    Segment s1 = (new LineSegment(x0 + p[0], y0 + p[1],
96
                                  x1 + p[0], y1 + p[1] ));
97
    Segment s2 = (new LineSegment(x0 - p[0], y0 - p[1],
98
                                  x1 - p[0], y1 - p[1] ));
99
    return new Segment[]{s1, s2};
100
  }
101
 
102
  public void reverse()
103
  {
104
    Point2D p = P1;
105
    P1 = P2;
106
    P2 = p;
107
  }
108
 
109
  public double[] cp1()
110
  {
111
    return new double[]{P2.getX(), P2.getY()};
112
  }
113
 
114
  public double[] cp2()
115
  {
116
    return new double[]{P1.getX(), P1.getY()};
117
  }
118
} // class LineSegment

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.