view 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
line wrap: on
line source

/*******************************************************************************
 * Copyright (c) 2000, 2008 IBM Corporation 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:
 *     IBM Corporation - initial API and implementation
 * Port to the D programming language:
 *     Frank Benoit <benoit@tionex.de>
 *******************************************************************************/
module org.eclipse.draw2d.geometry.PrecisionPoint;

import java.lang.all;
import org.eclipse.draw2d.geometry.Point;

/**
 * @author danlee
 */
public class PrecisionPoint : Point {

/** Double value for X **/
public double preciseX_;

/** Double value for Y **/
public double preciseY_;

/**
 * Constructor for PrecisionPoint.
 */
public this() {
    super();
}

/**
 * Constructor for PrecisionPoint.
 * @param copy Point from which the initial values are taken
 */
public this(Point copy) {
    preciseX_ = copy.preciseX();
    preciseY_ = copy.preciseY();
    updateInts();
}

/**
 * Constructor for PrecisionPoint.
 * @param x X value
 * @param y Y value
 */
public this(int x, int y) {
    super(x, y);
    preciseX_ = x;
    preciseY_ = y;
}

/**
 * Constructor for PrecisionPoint.
 * @param x X value
 * @param y Y value
 */
public this(double x, double y) {
    preciseX_ = x;
    preciseY_ = y;
    updateInts();
}

/**
 * @see org.eclipse.draw2d.geometry.Point#getCopy()
 */
public Point getCopy() {
    return new PrecisionPoint(preciseX_, preciseY_);
}


/**
 * @see org.eclipse.draw2d.geometry.Point#performScale(double)
 */
public void performScale(double factor) {
    preciseX_ = preciseX_ * factor;
    preciseY_ = preciseY_ * factor;
    updateInts();
}

/**
 * @see org.eclipse.draw2d.geometry.Point#performTranslate(int, int)
 */
public void performTranslate(int dx, int dy) {
    preciseX_ += dx;
    preciseY_ += dy;
    updateInts();
}

/**
 * @see org.eclipse.draw2d.geometry.Point#setLocation(Point)
 */
public Point setLocation(Point pt) {
    preciseX_ = pt.preciseX();
    preciseY_ = pt.preciseY();
    updateInts();
    return this;
}

/**
 * Updates the integer fields using the precise versions.
 */
public final void updateInts() {
    x = cast(int)Math.floor(preciseX_ + 0.000000001);
    y = cast(int)Math.floor(preciseY_ + 0.000000001);
}

/**
 * @see org.eclipse.draw2d.geometry.Point#preciseX()
 */
public double preciseX() {
    return preciseX_;
}

/**
 * @see org.eclipse.draw2d.geometry.Point#preciseY()
 */
public double preciseY() {
    return preciseY_;
}

}