//***********************************************************
//*
//* File:           Corner.java
//* Author:         Srikant Krishna
//* Contact:        srikant@cs.columbia.edu
//* Update:         10.16..2002
//*
//* Description:    Corner entry object.
//*
//***********************************************************

package Rectangles;

import java.io.Serializable;

public final class Corner implements Comparable, Serializable {

    Vertex  _position;
    char    _orientation;
    boolean _used;
    
    public Corner(int __xpos, int __ypos, char __orientation) throws Exception {
        _position = new Vertex(__xpos, __ypos);
        _orientation = __orientation;
    }

    public int xpos() throws Exception {
        return _position.xpos();
    }
    
    public int ypos() throws Exception {
        return _position.ypos();
    }
    
    public char orientation() throws Exception {
        return _orientation;
    }

    public boolean used() throws Exception {
        return _used;
    }
    
    public void setUsed() throws Exception {
        _used = true;
    }

    public String toString() {
        return _position.toString() + ": " + _orientation + ": " + _used;
    }
    
    public boolean equals(Object __obj) {
        try {
            Corner c = (Corner) __obj;
            
            if ((_orientation == c._orientation &&
                (_position.xpos() == c._position.xpos()) &&
                (_position.ypos() == c._position.ypos()))) {

                    return true;
            }
            return false;

        } catch (Exception EXC) {
            return false;
        }
    }

    public int compareTo(Object __obj) {
        try {
            Corner c = (Corner) __obj;
            
            if (_orientation > c._orientation) {
                return -1;
            }
            else
            if (_orientation < c._orientation) {
                return 1;
            }
            return 0;

        } catch (Exception EXC) {
            return -1;
        }
    }
}
