All Downloads are FREE. Search and download functionalities are using the official Maven repository.

nl.tudelft.simulation.dsol.animation.gis.SerializableRectangle2d Maven / Gradle / Ivy

package nl.tudelft.simulation.dsol.animation.gis;

import java.awt.geom.Rectangle2D;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;

/**
 * The SerializableRectangle2d class is a serializable version of the java.awt.geom.Rectangle2D class, yet in an
 * immutable form.
 * 

* Copyright (c) 2020-2024 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See * for project information DSOL Manual. The DSOL * project is distributed under a three-clause BSD-style license, which can be found at * DSOL License. *

* @author Alexander Verbraeck */ public abstract class SerializableRectangle2d extends Rectangle2D implements Serializable { /** */ private static final long serialVersionUID = 20201015L; /** * constructs a new SerializableRectangle2d. */ protected SerializableRectangle2d() { super(); } /** * The SerializableRectangle2d.Double class is a serializable version of the java.awt.geom.Rectangle2D.Double * class. */ public static class Double extends SerializableRectangle2d implements Serializable { /** */ private static final long serialVersionUID = 20201015L; /** the rectangle. */ private Rectangle2D.Double rectangle; /** * constructs a new SerializableRectangle2D.Double. */ public Double() { this.rectangle = new Rectangle2D.Double(); } /** * constructs a new SerializableRectangle2d.Double. * @param x double; lower x * @param y double; lower y * @param w double; width * @param h double; height */ public Double(final double x, final double y, final double w, final double h) { this.rectangle = new Rectangle2D.Double(x, y, w, h); } /** {@inheritDoc} */ @Override public Rectangle2D createIntersection(final Rectangle2D r) { return this.rectangle.createIntersection(r); } /** {@inheritDoc} */ @Override public Rectangle2D createUnion(final Rectangle2D r) { return this.rectangle.createUnion(r); } /** {@inheritDoc} */ @Override public Rectangle2D getBounds2D() { return this.rectangle.getBounds2D(); } /** {@inheritDoc} */ @Override public double getHeight() { return this.rectangle.getHeight(); } /** {@inheritDoc} */ @Override public double getWidth() { return this.rectangle.getWidth(); } /** {@inheritDoc} */ @Override public double getX() { return this.rectangle.getX(); } /** {@inheritDoc} */ @Override public double getY() { return this.rectangle.getY(); } /** {@inheritDoc} */ @Override public boolean isEmpty() { return this.rectangle.isEmpty(); } /** {@inheritDoc} */ @Override public int outcode(final double x, final double y) { return this.rectangle.outcode(x, y); } /** {@inheritDoc} */ @Override public void setRect(final double x, final double y, final double w, final double h) { this.rectangle.setRect(x, y, w, h); } /** {@inheritDoc} */ @Override public void setRect(final Rectangle2D r) { this.rectangle.setRect(r); } /** {@inheritDoc} */ @Override public String toString() { return this.rectangle.toString(); } /** * Serialize the object to the stream. * @param out ObjectOutputStream; the outputstream * @throws java.io.IOException on exception */ private void writeObject(final ObjectOutputStream out) throws java.io.IOException { out.writeDouble(this.rectangle.getX()); out.writeDouble(this.rectangle.getY()); out.writeDouble(this.rectangle.getWidth()); out.writeDouble(this.rectangle.getHeight()); } /** * Read a serialized object from the stream. * @param in ObjectInputStream; the input * @throws IOException on exception */ private void readObject(final ObjectInputStream in) throws IOException { this.rectangle = new Rectangle2D.Double(in.readDouble(), in.readDouble(), in.readDouble(), in.readDouble()); } } /** * The SerializableRectangle2d.Float class is a serializable version of the java.awt.geom.Rectangle2D.Double * class. */ public static class Float extends SerializableRectangle2d { /** the rectangle. */ private Rectangle2D rectangle; /** * constructs a new SerializableRectangle2d.Float. */ public Float() { this.rectangle = new Rectangle2D.Float(); } /** * constructs a new SerializableRectangle2d.Float. * @param x float; the lower x * @param y float; the lower y * @param w float; the width * @param h float; the height */ public Float(final float x, final float y, final float w, final float h) { this.rectangle = new Rectangle2D.Float(x, y, w, h); } /** {@inheritDoc} */ @Override public Rectangle2D createIntersection(final Rectangle2D r) { return this.rectangle.createIntersection(r); } /** {@inheritDoc} */ @Override public Rectangle2D createUnion(final Rectangle2D r) { return this.rectangle.createUnion(r); } /** {@inheritDoc} */ @Override public Rectangle2D getBounds2D() { return this.rectangle.getBounds2D(); } /** {@inheritDoc} */ @Override public double getHeight() { return this.rectangle.getHeight(); } /** {@inheritDoc} */ @Override public double getWidth() { return this.rectangle.getWidth(); } /** {@inheritDoc} */ @Override public double getX() { return this.rectangle.getX(); } /** {@inheritDoc} */ @Override public double getY() { return this.rectangle.getY(); } /** {@inheritDoc} */ @Override public boolean isEmpty() { return this.rectangle.isEmpty(); } /** {@inheritDoc} */ @Override public int outcode(final double x, final double y) { return this.rectangle.outcode(x, y); } /** * @param x float; the lower x * @param y float; the lower y * @param w float; the width * @param h float; the height */ public void setRect(final float x, final float y, final float w, final float h) { this.rectangle.setRect(x, y, w, h); } /** {@inheritDoc} */ @Override public void setRect(final double x, final double y, final double w, final double h) { this.rectangle.setRect(x, y, w, h); } /** {@inheritDoc} */ @Override public void setRect(final Rectangle2D r) { this.rectangle.setRect(r); } /** {@inheritDoc} */ @Override public String toString() { return this.rectangle.toString(); } /** * Serialize the object to the stream. * @param out ObjectOutputStream; the stream * @throws IOException on IOException */ private void writeObject(final ObjectOutputStream out) throws IOException { out.writeDouble(this.rectangle.getX()); out.writeDouble(this.rectangle.getY()); out.writeDouble(this.rectangle.getWidth()); out.writeDouble(this.rectangle.getHeight()); } /** * Read a serialized object from the stream. * @param in ObjectInputStream; the stream * @throws IOException on IOException */ private void readObject(final ObjectInputStream in) throws IOException { this.rectangle = new Rectangle2D.Float(); this.rectangle.setRect(in.readDouble(), in.readDouble(), in.readDouble(), in.readDouble()); } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy