blob: ac9cbe7ea0a6ef79fd973c8fa7937d1a1f35937b [file] [log] [blame]
/*=============================================================================#
# Copyright (c) 2012, 2021 Stephan Wahlbrink and others.
#
# This program and the accompanying materials are made available under the
# terms of the Eclipse Public License 2.0 which is available at
# https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
# which is available at https://www.apache.org/licenses/LICENSE-2.0.
#
# SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
#
# Contributors:
# Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation
#=============================================================================*/
package org.eclipse.statet.ecommons.waltable.coordinate;
import static org.eclipse.statet.ecommons.waltable.coordinate.Orientation.HORIZONTAL;
/**
* Instances of this class represent places on the (x, y)
* coordinate plane.
*
* <p>The coordinate space for rectangles and points is considered
* to have increasing values downward and to the right from its
* origin making this the normal, computer graphics oriented notion
* of (x, y) coordinates rather than the strict mathematical one.
* </p>
*
* @see LRectangle
*/
public final class LPoint {
/**
* the x coordinate of the point
*/
public final long x;
/**
* the y coordinate of the point
*/
public final long y;
/**
* Creates a new point with the specified x and y coordinates.
*
* @param x the x coordinate
* @param y the y coordinate
*/
public LPoint (final long x, final long y) {
this.x= x;
this.y= y;
}
public long get(final Orientation orientation) {
return (orientation == HORIZONTAL) ?
this.x :
this.y;
}
@Override
public int hashCode() {
int h= (int) (this.x ^ (this.x >>> 32));
h= Integer.rotateRight(h, 15);
h ^= (int) (this.y ^ (this.y >>> 32));
return h ^ (h >>> 7);
}
@Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof LPoint) {
final LPoint other= (LPoint) obj;
return (this.x == other.x && this.y == other.y);
}
return false;
}
@Override
public String toString () {
return "LPoint {" + this.x + ", " + this.y + "}"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
}