comparison org.eclipse.draw2d/src/org/eclipse/draw2d/geometry/PrecisionPoint.d @ 12:bc29606a740c

Added dwt-addons in original directory structure of eclipse.org
author Frank Benoit <benoit@tionex.de>
date Sat, 14 Mar 2009 18:23:29 +0100
parents
children
comparison
equal deleted inserted replaced
11:43904fec5dca 12:bc29606a740c
1 /*******************************************************************************
2 * Copyright (c) 2000, 2008 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * IBM Corporation - initial API and implementation
10 * Port to the D programming language:
11 * Frank Benoit <benoit@tionex.de>
12 *******************************************************************************/
13 module org.eclipse.draw2d.geometry.PrecisionPoint;
14
15 import java.lang.all;
16 import org.eclipse.draw2d.geometry.Point;
17
18 /**
19 * @author danlee
20 */
21 public class PrecisionPoint : Point {
22
23 /** Double value for X **/
24 public double preciseX_;
25
26 /** Double value for Y **/
27 public double preciseY_;
28
29 /**
30 * Constructor for PrecisionPoint.
31 */
32 public this() {
33 super();
34 }
35
36 /**
37 * Constructor for PrecisionPoint.
38 * @param copy Point from which the initial values are taken
39 */
40 public this(Point copy) {
41 preciseX_ = copy.preciseX();
42 preciseY_ = copy.preciseY();
43 updateInts();
44 }
45
46 /**
47 * Constructor for PrecisionPoint.
48 * @param x X value
49 * @param y Y value
50 */
51 public this(int x, int y) {
52 super(x, y);
53 preciseX_ = x;
54 preciseY_ = y;
55 }
56
57 /**
58 * Constructor for PrecisionPoint.
59 * @param x X value
60 * @param y Y value
61 */
62 public this(double x, double y) {
63 preciseX_ = x;
64 preciseY_ = y;
65 updateInts();
66 }
67
68 /**
69 * @see org.eclipse.draw2d.geometry.Point#getCopy()
70 */
71 public Point getCopy() {
72 return new PrecisionPoint(preciseX_, preciseY_);
73 }
74
75
76 /**
77 * @see org.eclipse.draw2d.geometry.Point#performScale(double)
78 */
79 public void performScale(double factor) {
80 preciseX_ = preciseX_ * factor;
81 preciseY_ = preciseY_ * factor;
82 updateInts();
83 }
84
85 /**
86 * @see org.eclipse.draw2d.geometry.Point#performTranslate(int, int)
87 */
88 public void performTranslate(int dx, int dy) {
89 preciseX_ += dx;
90 preciseY_ += dy;
91 updateInts();
92 }
93
94 /**
95 * @see org.eclipse.draw2d.geometry.Point#setLocation(Point)
96 */
97 public Point setLocation(Point pt) {
98 preciseX_ = pt.preciseX();
99 preciseY_ = pt.preciseY();
100 updateInts();
101 return this;
102 }
103
104 /**
105 * Updates the integer fields using the precise versions.
106 */
107 public final void updateInts() {
108 x = cast(int)Math.floor(preciseX_ + 0.000000001);
109 y = cast(int)Math.floor(preciseY_ + 0.000000001);
110 }
111
112 /**
113 * @see org.eclipse.draw2d.geometry.Point#preciseX()
114 */
115 public double preciseX() {
116 return preciseX_;
117 }
118
119 /**
120 * @see org.eclipse.draw2d.geometry.Point#preciseY()
121 */
122 public double preciseY() {
123 return preciseY_;
124 }
125
126 }