001/*
002 * Copyright 2010-2015 Institut Pasteur.
003 * 
004 * This file is part of Icy.
005 * 
006 * Icy is free software: you can redistribute it and/or modify
007 * it under the terms of the GNU General Public License as published by
008 * the Free Software Foundation, either version 3 of the License, or
009 * (at your option) any later version.
010 * 
011 * Icy is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014 * GNU General Public License for more details.
015 * 
016 * You should have received a copy of the GNU General Public License
017 * along with Icy. If not, see <http://www.gnu.org/licenses/>.
018 */
019package icy.type.rectangle;
020
021import icy.type.dimension.Dimension5D;
022import icy.type.point.Point5D;
023
024import java.awt.Rectangle;
025import java.awt.geom.Rectangle2D;
026
027/**
028 * Rectangle5D class.<br>
029 * Incomplete implementation (work in progress...)
030 * 
031 * @author Stephane
032 */
033public abstract class Rectangle5D implements Cloneable
034{
035    /**
036     * Intersects the pair of specified source <code>Rectangle5D</code> objects and puts the result
037     * into the specified destination <code>Rectangle5D</code> object. One of the source rectangles
038     * can also be the destination to avoid creating a third Rectangle5D object, but in this case
039     * the original points of this source rectangle will be overwritten by this method.
040     * 
041     * @param src1
042     *        the first of a pair of <code>Rectangle5D</code> objects to be intersected with each
043     *        other
044     * @param src2
045     *        the second of a pair of <code>Rectangle5D</code> objects to be intersected with each
046     *        other
047     * @param dest
048     *        the <code>Rectangle5D</code> that holds the
049     *        results of the intersection of <code>src1</code> and <code>src2</code>.<br>
050     *        If set to <code>null</code> then a new Rectangle5D is created.
051     * @return resulting <code>Rectangle5D</code> from the intersect process.
052     */
053    public static Rectangle5D intersect(Rectangle5D src1, Rectangle5D src2, Rectangle5D dest)
054    {
055        final Rectangle5D result;
056
057        if (dest == null)
058            result = new Rectangle5D.Double();
059        else
060            result = dest;
061
062        final double x1 = Math.max(src1.getMinX(), src2.getMinX());
063        final double y1 = Math.max(src1.getMinY(), src2.getMinY());
064        final double z1 = Math.max(src1.getMinZ(), src2.getMinZ());
065        final double t1 = Math.max(src1.getMinT(), src2.getMinT());
066        final double c1 = Math.max(src1.getMinC(), src2.getMinC());
067        final double x2 = Math.min(src1.getMaxX(), src2.getMaxX());
068        final double y2 = Math.min(src1.getMaxY(), src2.getMaxY());
069        final double z2 = Math.min(src1.getMaxZ(), src2.getMaxZ());
070        final double t2 = Math.min(src1.getMaxT(), src2.getMaxT());
071        final double c2 = Math.min(src1.getMaxC(), src2.getMaxC());
072
073        double dx;
074        double dy;
075        double dz;
076        double dt;
077        double dc;
078
079        // special infinite case
080        if (x2 == java.lang.Double.POSITIVE_INFINITY)
081            dx = java.lang.Double.POSITIVE_INFINITY;
082        else
083            dx = x2 - x1;
084        // special infinite case
085        if (y2 == java.lang.Double.POSITIVE_INFINITY)
086            dy = java.lang.Double.POSITIVE_INFINITY;
087        else
088            dy = y2 - y1;
089        // special infinite case
090        if (z2 == java.lang.Double.POSITIVE_INFINITY)
091            dz = java.lang.Double.POSITIVE_INFINITY;
092        else
093            dz = z2 - z1;
094        // special infinite case
095        if (t2 == java.lang.Double.POSITIVE_INFINITY)
096            dt = java.lang.Double.POSITIVE_INFINITY;
097        else
098            dt = t2 - t1;
099        // special infinite case
100        if (c2 == java.lang.Double.POSITIVE_INFINITY)
101            dc = java.lang.Double.POSITIVE_INFINITY;
102        else
103            dc = c2 - c1;
104
105        result.setRect(x1, y1, z1, t1, c1, dx, dy, dz, dt, dc);
106
107        return result;
108    }
109
110    /**
111     * Returns a new <code>Rectangle5D</code> object representing the intersection of this
112     * <code>Rectangle5D</code> with the specified <code>Rectangle5D</code>.
113     * 
114     * @param r
115     *        the <code>Rectangle5D</code> to be intersected with this <code>Rectangle5D</code>
116     * @return the largest <code>Rectangle5D</code> contained in both the specified
117     *         <code>Rectangle5D</code> and in this <code>Rectangle5D</code>.
118     */
119    public abstract Rectangle5D createIntersection(Rectangle5D r);
120
121    /**
122     * Unions the pair of source <code>Rectangle5D</code> objects and puts the result into the
123     * specified destination <code>Rectangle5D</code> object. One of the source rectangles can also
124     * be the destination to avoid creating a third Rectangle5D object, but in this case the
125     * original points of this source rectangle will be overwritten by this method.
126     * 
127     * @param src1
128     *        the first of a pair of <code>Rectangle5D</code> objects to be combined with each other
129     * @param src2
130     *        the second of a pair of <code>Rectangle5D</code> objects to be combined with each
131     *        other
132     * @param dest
133     *        the <code>Rectangle5D</code> that holds the
134     *        results of the union of <code>src1</code> and <code>src2</code>.<br>
135     *        If set to <code>null</code> then a new Rectangle5D is created.
136     * @return resulting <code>Rectangle5D</code> from the intersect process.
137     */
138    public static Rectangle5D union(Rectangle5D src1, Rectangle5D src2, Rectangle5D dest)
139    {
140        final Rectangle5D result;
141
142        if (dest == null)
143            result = new Rectangle5D.Double();
144        else
145            result = dest;
146
147        double x1 = Math.min(src1.getMinX(), src2.getMinX());
148        double y1 = Math.min(src1.getMinY(), src2.getMinY());
149        double z1 = Math.min(src1.getMinZ(), src2.getMinZ());
150        double t1 = Math.min(src1.getMinT(), src2.getMinT());
151        double c1 = Math.min(src1.getMinC(), src2.getMinC());
152        double x2 = Math.max(src1.getMaxX(), src2.getMaxX());
153        double y2 = Math.max(src1.getMaxY(), src2.getMaxY());
154        double z2 = Math.max(src1.getMaxZ(), src2.getMaxZ());
155        double t2 = Math.max(src1.getMaxT(), src2.getMaxT());
156        double c2 = Math.max(src1.getMaxC(), src2.getMaxC());
157
158        double dx;
159        double dy;
160        double dz;
161        double dt;
162        double dc;
163
164        // special infinite case
165        if (x2 == java.lang.Double.POSITIVE_INFINITY)
166            dx = java.lang.Double.POSITIVE_INFINITY;
167        else
168            dx = x2 - x1;
169        // special infinite case
170        if (y2 == java.lang.Double.POSITIVE_INFINITY)
171            dy = java.lang.Double.POSITIVE_INFINITY;
172        else
173            dy = y2 - y1;
174        // special infinite case
175        if (z2 == java.lang.Double.POSITIVE_INFINITY)
176            dz = java.lang.Double.POSITIVE_INFINITY;
177        else
178            dz = z2 - z1;
179        // special infinite case
180        if (t2 == java.lang.Double.POSITIVE_INFINITY)
181            dt = java.lang.Double.POSITIVE_INFINITY;
182        else
183            dt = t2 - t1;
184        // special infinite case
185        if (c2 == java.lang.Double.POSITIVE_INFINITY)
186            dc = java.lang.Double.POSITIVE_INFINITY;
187        else
188            dc = c2 - c1;
189
190        result.setRect(x1, y1, z1, t1, c1, dx, dy, dz, dt, dc);
191
192        return result;
193    }
194
195    /**
196     * Returns a new <code>Rectangle5D</code> object representing the union of this
197     * <code>Rectangle5D</code> with the specified <code>Rectangle5D</code>.
198     * 
199     * @param r
200     *        the <code>Rectangle5D</code> to be combined with this <code>Rectangle5D</code>
201     * @return the smallest <code>Rectangle5D</code> containing both the specified
202     *         <code>Rectangle5D</code> and this <code>Rectangle5D</code>.
203     */
204    public abstract Rectangle5D createUnion(Rectangle5D r);
205
206    /**
207     * Sets the position and size of this <code>Rectangle5D</code> to the specified
208     * <code>double</code> values.
209     * 
210     * @param x
211     *        the X coordinate of the minimum corner position of this <code>Rectangle5D</code>
212     * @param y
213     *        the Y coordinate of the minimum corner position of this <code>Rectangle5D</code>
214     * @param z
215     *        the Z coordinate of the minimum corner position of this <code>Rectangle5D</code>
216     * @param t
217     *        the T coordinate of the minimum corner position of this <code>Rectangle5D</code>
218     * @param c
219     *        the C coordinate of the minimum corner position of this <code>Rectangle5D</code>
220     * @param sizeX
221     *        size for X dimension of this <code>Rectangle5D</code>
222     * @param sizeY
223     *        size for Y dimension of this <code>Rectangle5D</code>
224     * @param sizeZ
225     *        size for Z dimension of this <code>Rectangle5D</code>
226     * @param sizeT
227     *        size for T dimension of this <code>Rectangle5D</code>
228     * @param sizeC
229     *        size for C dimension of this <code>Rectangle5D</code>
230     */
231    public abstract void setRect(double x, double y, double z, double t, double c, double sizeX, double sizeY,
232            double sizeZ, double sizeT, double sizeC);
233
234    /**
235     * Returns the minimum X coordinate.
236     */
237    public abstract double getX();
238
239    /**
240     * Returns the minimum Y coordinate.
241     */
242    public abstract double getY();
243
244    /**
245     * Returns the minimum Z coordinate.
246     */
247    public abstract double getZ();
248
249    /**
250     * Returns the minimum T coordinate.
251     */
252    public abstract double getT();
253
254    /**
255     * Returns the minimum C coordinate.
256     */
257    public abstract double getC();
258
259    /**
260     * Returns the size of X dimension.
261     */
262    public abstract double getSizeX();
263
264    /**
265     * Returns the size of Y dimension.
266     */
267    public abstract double getSizeY();
268
269    /**
270     * Returns the size of Z dimension.
271     */
272    public abstract double getSizeZ();
273
274    /**
275     * Returns the size of T dimension.
276     */
277    public abstract double getSizeT();
278
279    /**
280     * Returns the size of C dimension.
281     */
282    public abstract double getSizeC();
283
284    /**
285     * Returns the point coordinate.
286     */
287    public abstract Point5D getPosition();
288
289    /**
290     * Returns the dimension.
291     */
292    public abstract Dimension5D getDimension();
293
294    /**
295     * Returns an integer {@link Rectangle5D} that completely encloses the
296     * double <code>Rectangle</code>. The returned <code>Rectangle</code> might also fail to
297     * completely enclose the original double <code>Rectangle</code> if it overflows
298     * the limited range of the integer data type.
299     * 
300     * @return an integer <code>Rectangle</code> that completely encloses
301     *         the actual double <code>Rectangle</code>.
302     */
303    public Rectangle5D.Integer toInteger()
304    {
305        double sx = getSizeX();
306        double sy = getSizeY();
307        double sz = getSizeZ();
308        double st = getSizeT();
309        double sc = getSizeC();
310        double x = getX();
311        double y = getY();
312        double z = getZ();
313        double t = getT();
314        double c = getC();
315        int ix = (int) Math.floor(x);
316        int iy = (int) Math.floor(y);
317        int iz = (int) Math.floor(z);
318        int it = (int) Math.floor(t);
319        int ic = (int) Math.floor(c);
320        int isx;
321        int isy;
322        int isz;
323        int ist;
324        int isc;
325
326        if (sx < 0d)
327            isx = 0;
328        else if (sx >= java.lang.Integer.MAX_VALUE)
329            isx = java.lang.Integer.MAX_VALUE;
330        else
331            isx = ((int) Math.ceil(x + sx)) - ix;
332        if (sy < 0d)
333            isy = 0;
334        else if (sy >= java.lang.Integer.MAX_VALUE)
335            isy = java.lang.Integer.MAX_VALUE;
336        else
337            isy = ((int) Math.ceil(y + sy)) - iy;
338        if (sz < 0d)
339            isz = 0;
340        else if (sz >= java.lang.Integer.MAX_VALUE)
341            isz = java.lang.Integer.MAX_VALUE;
342        else
343            isz = ((int) Math.ceil(z + sz)) - iz;
344        if (st < 0d)
345            ist = 0;
346        else if (st >= java.lang.Integer.MAX_VALUE)
347            ist = java.lang.Integer.MAX_VALUE;
348        else
349            ist = ((int) Math.ceil(t + st)) - it;
350        if (sc < 0d)
351            isc = 0;
352        else if (sc >= java.lang.Integer.MAX_VALUE)
353            isc = java.lang.Integer.MAX_VALUE;
354        else
355            isc = ((int) Math.ceil(c + sc)) - ic;
356
357        return new Rectangle5D.Integer(ix, iy, iz, it, ic, isx, isy, isz, ist, isc);
358    }
359
360    /**
361     * Sets the minimum X coordinate.
362     */
363    public abstract void setX(double x);
364
365    /**
366     * Sets the minimum Y coordinate.
367     */
368    public abstract void setY(double y);
369
370    /**
371     * Sets the minimum Z coordinate.
372     */
373    public abstract void setZ(double z);
374
375    /**
376     * Sets the minimum T coordinate.
377     */
378    public abstract void setT(double t);
379
380    /**
381     * Sets the minimum C coordinate.
382     */
383    public abstract void setC(double c);
384
385    /**
386     * Sets the size of X dimension.
387     */
388    public abstract void setSizeX(double value);
389
390    /**
391     * Sets the size of Y dimension.
392     */
393    public abstract void setSizeY(double value);
394
395    /**
396     * Sets the size of Z dimension.
397     */
398    public abstract void setSizeZ(double value);
399
400    /**
401     * Sets the size of T dimension.
402     */
403    public abstract void setSizeT(double value);
404
405    /**
406     * Sets the size of C dimension.
407     */
408    public abstract void setSizeC(double value);
409
410    /**
411     * Returns the smallest X coordinate of the rectangle.
412     */
413    public double getMinX()
414    {
415        return getX();
416    }
417
418    /**
419     * Returns the smallest Y coordinate of the rectangle.
420     */
421    public double getMinY()
422    {
423        return getY();
424    }
425
426    /**
427     * Returns the smallest Z coordinate of the rectangle.
428     */
429    public double getMinZ()
430    {
431        return getZ();
432    }
433
434    /**
435     * Returns the smallest T coordinate of the rectangle.
436     */
437    public double getMinT()
438    {
439        return getT();
440    }
441
442    /**
443     * Returns the smallest C coordinate of the rectangle.
444     */
445    public double getMinC()
446    {
447        return getC();
448    }
449
450    /**
451     * Returns the largest X coordinate of the rectangle.
452     */
453    public double getMaxX()
454    {
455        // handle this special case
456        if (getSizeX() == java.lang.Double.POSITIVE_INFINITY)
457            return java.lang.Double.POSITIVE_INFINITY;
458
459        return getX() + getSizeX();
460    }
461
462    /**
463     * Returns the largest Y coordinate of the rectangle.
464     */
465    public double getMaxY()
466    {
467        // handle this special case
468        if (getSizeY() == java.lang.Double.POSITIVE_INFINITY)
469            return java.lang.Double.POSITIVE_INFINITY;
470
471        return getY() + getSizeY();
472    }
473
474    /**
475     * Returns the largest Z coordinate of the rectangle.
476     */
477    public double getMaxZ()
478    {
479        // handle this special case
480        if (getSizeZ() == java.lang.Double.POSITIVE_INFINITY)
481            return java.lang.Double.POSITIVE_INFINITY;
482
483        return getZ() + getSizeZ();
484    }
485
486    /**
487     * Returns the largest T coordinate of the rectangle.
488     */
489    public double getMaxT()
490    {
491        // handle this special case
492        if (getSizeT() == java.lang.Double.POSITIVE_INFINITY)
493            return java.lang.Double.POSITIVE_INFINITY;
494
495        return getT() + getSizeT();
496    }
497
498    /**
499     * Returns the largest C coordinate of the rectangle.
500     */
501    public double getMaxC()
502    {
503        // handle this special case
504        if (getSizeC() == java.lang.Double.POSITIVE_INFINITY)
505            return java.lang.Double.POSITIVE_INFINITY;
506
507        return getC() + getSizeC();
508    }
509
510    /**
511     * Returns the X coordinate of the center of the rectangle.
512     */
513    public double getCenterX()
514    {
515        // handle this special case
516        if (isInfiniteX())
517            return 0d;
518
519        return getX() + (getSizeX() / 2d);
520    }
521
522    /**
523     * Returns the Y coordinate of the center of the rectangle.
524     */
525    public double getCenterY()
526    {
527        // handle this special case
528        if (isInfiniteY())
529            return 0d;
530
531        return getY() + (getSizeY() / 2d);
532    }
533
534    /**
535     * Returns the Z coordinate of the center of the rectangle.
536     */
537    public double getCenterZ()
538    {
539        // handle this special case
540        if (isInfiniteZ())
541            return 0d;
542
543        return getZ() + (getSizeZ() / 2d);
544    }
545
546    /**
547     * Returns the T coordinate of the center of the rectangle.
548     */
549    public double getCenterT()
550    {
551        // handle this special case
552        if (isInfiniteT())
553            return 0d;
554
555        return getT() + (getSizeT() / 2d);
556    }
557
558    /**
559     * Returns the C coordinate of the center of the rectangle.
560     */
561    public double getCenterC()
562    {
563        // handle this special case
564        if (isInfiniteC())
565            return 0d;
566
567        return getC() + (getSizeC() / 2d);
568    }
569
570    /**
571     * Determines whether the <code>Rectangle5D</code> is empty.
572     * 
573     * @return <code>true</code> if the <code>Rectangle5D</code> is empty; <code>false</code>
574     *         otherwise.
575     */
576    public boolean isEmpty()
577    {
578        return (getSizeX() <= 0d) || (getSizeY() <= 0d) || (getSizeZ() <= 0d) || (getSizeT() <= 0d)
579                || (getSizeC() <= 0d);
580    }
581
582    /**
583     * Returns <code>true</code> if the X dimension should be considered as infinite.
584     */
585    public boolean isInfiniteX()
586    {
587        return (getX() == java.lang.Double.NEGATIVE_INFINITY) && (getSizeX() == java.lang.Double.POSITIVE_INFINITY);
588    }
589
590    /**
591     * Returns <code>true</code> if the Y dimension should be considered as infinite.
592     */
593    public boolean isInfiniteY()
594    {
595        return (getY() == java.lang.Double.NEGATIVE_INFINITY) && (getSizeY() == java.lang.Double.POSITIVE_INFINITY);
596    }
597
598    /**
599     * Returns <code>true</code> if the Z dimension should be considered as infinite.
600     */
601    public boolean isInfiniteZ()
602    {
603        return (getZ() == java.lang.Double.NEGATIVE_INFINITY) && (getSizeZ() == java.lang.Double.POSITIVE_INFINITY);
604    }
605
606    /**
607     * Returns <code>true</code> if the T dimension should be considered as infinite.
608     */
609    public boolean isInfiniteT()
610    {
611        return (getT() == java.lang.Double.NEGATIVE_INFINITY) && (getSizeT() == java.lang.Double.POSITIVE_INFINITY);
612    }
613
614    /**
615     * Returns <code>true</code> if the C dimension should be considered as infinite.
616     */
617    public boolean isInfiniteC()
618    {
619        return (getC() == java.lang.Double.NEGATIVE_INFINITY) && (getSizeC() == java.lang.Double.POSITIVE_INFINITY);
620    }
621
622    /**
623     * Sets the X dimension to infinite.
624     */
625    public void setInfiniteX()
626    {
627        setX(java.lang.Double.NEGATIVE_INFINITY);
628        setSizeX(java.lang.Double.POSITIVE_INFINITY);
629    }
630
631    /**
632     * Sets the Y dimension to infinite.
633     */
634    public void setInfiniteY()
635    {
636        setY(java.lang.Double.NEGATIVE_INFINITY);
637        setSizeY(java.lang.Double.POSITIVE_INFINITY);
638    }
639
640    /**
641     * Sets the Z dimension to infinite.
642     */
643    public void setInfiniteZ()
644    {
645        setZ(java.lang.Double.NEGATIVE_INFINITY);
646        setSizeZ(java.lang.Double.POSITIVE_INFINITY);
647    }
648
649    /**
650     * Sets the T dimension to infinite.
651     */
652    public void setInfiniteT()
653    {
654        setT(java.lang.Double.NEGATIVE_INFINITY);
655        setSizeT(java.lang.Double.POSITIVE_INFINITY);
656    }
657
658    /**
659     * Sets the C dimension to infinite.
660     */
661    public void setInfiniteC()
662    {
663        setC(java.lang.Double.NEGATIVE_INFINITY);
664        setSizeC(java.lang.Double.POSITIVE_INFINITY);
665    }
666
667    /**
668     * Tests if the specified coordinates are inside the boundary of the <code>Rectangle5D</code>.
669     * 
670     * @param x
671     *        the specified X coordinate to be tested
672     * @param y
673     *        the specified Y coordinate to be tested
674     * @param z
675     *        the specified Z coordinate to be tested
676     * @param t
677     *        the specified T coordinate to be tested
678     * @param c
679     *        the specified C coordinate to be tested
680     * @return <code>true</code> if the specified coordinates are inside
681     *         the <code>Rectangle5D</code> boundary; <code>false</code> otherwise.
682     */
683    public boolean contains(double x, double y, double z, double t, double c)
684    {
685        return (x >= getMinX()) && (y >= getMinY()) && (z >= getMinZ()) && (t >= getMinT()) && (c >= getMinC())
686                && (x < getMaxX()) && (y < getMaxY()) && (z < getMaxZ()) && (t < getMaxT()) && (c < getMaxC());
687    }
688
689    /**
690     * Tests if the <code>Rectangle5D</code> entirely contains the specified 5D rectangular area.<br>
691     * All coordinates that lie inside the 5D rectangular area must lie within the
692     * <code>Rectangle5D</code>.
693     * 
694     * @param x
695     *        the X coordinate of the minimum corner position of the specified rectangular area
696     * @param y
697     *        the Y coordinate of the minimum corner position of the specified rectangular area
698     * @param z
699     *        the Z coordinate of the minimum corner position of the specified rectangular area
700     * @param t
701     *        the T coordinate of the minimum corner position of the specified rectangular area
702     * @param c
703     *        the C coordinate of the minimum corner position of the specified rectangular area
704     * @param sizeX
705     *        size for X dimension of the specified rectangular area
706     * @param sizeY
707     *        size for Y dimension of the specified rectangular area
708     * @param sizeZ
709     *        size for Z dimension of the specified rectangular area
710     * @param sizeT
711     *        size for T dimension of the specified rectangular area
712     * @param sizeC
713     *        size for C dimension of the specified rectangular area
714     * @return <code>true</code> if the <code>Rectangle5D</code> entirely contains the
715     *         specified 5D rectangular area; <code>false</code> otherwise
716     * @see #intersects
717     */
718    public boolean contains(double x, double y, double z, double t, double c, double sizeX, double sizeY, double sizeZ,
719            double sizeT, double sizeC)
720    {
721        final double maxX;
722        final double maxY;
723        final double maxZ;
724        final double maxT;
725        final double maxC;
726
727        // special infinite case
728        if (sizeX == java.lang.Double.POSITIVE_INFINITY)
729            maxX = java.lang.Double.POSITIVE_INFINITY;
730        else
731            maxX = x + sizeX;
732        // special infinite case
733        if (sizeY == java.lang.Double.POSITIVE_INFINITY)
734            maxY = java.lang.Double.POSITIVE_INFINITY;
735        else
736            maxY = y + sizeY;
737        // special infinite case
738        if (sizeZ == java.lang.Double.POSITIVE_INFINITY)
739            maxZ = java.lang.Double.POSITIVE_INFINITY;
740        else
741            maxZ = z + sizeZ;
742        // special infinite case
743        if (sizeT == java.lang.Double.POSITIVE_INFINITY)
744            maxT = java.lang.Double.POSITIVE_INFINITY;
745        else
746            maxT = t + sizeT;
747        // special infinite case
748        if (sizeC == java.lang.Double.POSITIVE_INFINITY)
749            maxC = java.lang.Double.POSITIVE_INFINITY;
750        else
751            maxC = c + sizeC;
752
753        return (x >= getMinX()) && (y >= getMinY()) && (z >= getMinZ()) && (t >= getMinT()) && (c >= getMinC())
754                && (maxX <= getMaxX()) && (maxY <= getMaxY()) && (maxZ <= getMaxZ()) && (maxT <= getMaxT())
755                && (maxC <= getMaxC());
756    }
757
758    /**
759     * Tests if the <code>Rectangle5D</code> entirely contains the specified
760     * <code>Rectangle5D</code>.
761     * 
762     * @see #contains(double, double, double, double, double, double, double, double, double,
763     *      double)
764     */
765    public boolean contains(Rectangle5D rect)
766    {
767        return contains(rect.getX(), rect.getY(), rect.getZ(), rect.getT(), rect.getC(), rect.getSizeX(),
768                rect.getSizeY(), rect.getSizeZ(), rect.getSizeT(), rect.getSizeC());
769    }
770
771    /**
772     * Tests if the interior of the <code>Rectangle5D</code> intersects the interior of a specified
773     * 5D rectangular area.<br>
774     * The 5D rectangular area is considered to intersect the <code>Rectangle5D</code> if any point
775     * is contained in both the interior of the <code>Rectangle5D</code> and the specified
776     * rectangular area.
777     * 
778     * @param x
779     *        the X coordinate of the minimum corner position of the specified rectangular area
780     * @param y
781     *        the Y coordinate of the minimum corner position of the specified rectangular area
782     * @param z
783     *        the Z coordinate of the minimum corner position of the specified rectangular area
784     * @param t
785     *        the T coordinate of the minimum corner position of the specified rectangular area
786     * @param c
787     *        the C coordinate of the minimum corner position of the specified rectangular area
788     * @param sizeX
789     *        size for X dimension of the specified rectangular area
790     * @param sizeY
791     *        size for Y dimension of the specified rectangular area
792     * @param sizeZ
793     *        size for Z dimension of the specified rectangular area
794     * @param sizeT
795     *        size for T dimension of the specified rectangular area
796     * @param sizeC
797     *        size for C dimension of the specified rectangular area
798     * @return <code>true</code> if the interior of the <code>Rectangle5D</code> and
799     *         the interior of the 5D rectangular area intersect.
800     */
801    public boolean intersects(double x, double y, double z, double t, double c, double sizeX, double sizeY,
802            double sizeZ, double sizeT, double sizeC)
803    {
804        final double maxX;
805        final double maxY;
806        final double maxZ;
807        final double maxT;
808        final double maxC;
809
810        // special infinite case
811        if (sizeX == java.lang.Double.POSITIVE_INFINITY)
812            maxX = java.lang.Double.POSITIVE_INFINITY;
813        else
814            maxX = x + sizeX;
815        // special infinite case
816        if (sizeY == java.lang.Double.POSITIVE_INFINITY)
817            maxY = java.lang.Double.POSITIVE_INFINITY;
818        else
819            maxY = y + sizeY;
820        // special infinite case
821        if (sizeZ == java.lang.Double.POSITIVE_INFINITY)
822            maxZ = java.lang.Double.POSITIVE_INFINITY;
823        else
824            maxZ = z + sizeZ;
825        // special infinite case
826        if (sizeT == java.lang.Double.POSITIVE_INFINITY)
827            maxT = java.lang.Double.POSITIVE_INFINITY;
828        else
829            maxT = t + sizeT;
830        // special infinite case
831        if (sizeC == java.lang.Double.POSITIVE_INFINITY)
832            maxC = java.lang.Double.POSITIVE_INFINITY;
833        else
834            maxC = c + sizeC;
835
836        return (maxX > getMinX()) && (maxY > getMinY()) && (maxZ > getMinZ()) && (maxT > getMinT())
837                && (maxC > getMinC()) && (x < getMaxX()) && (y < getMaxY()) && (z < getMaxZ()) && (t < getMaxT())
838                && (c < getMaxC());
839    }
840
841    /**
842     * Tests if the interior of the <code>Rectangle5D</code> intersects the interior of a specified
843     * <code>Rectangle5D</code>.<br>
844     * 
845     * @see #intersects(double, double, double, double, double, double, double, double, double,
846     *      double)
847     */
848    public boolean intersects(Rectangle5D rect)
849    {
850        return intersects(rect.getX(), rect.getY(), rect.getZ(), rect.getT(), rect.getC(), rect.getSizeX(),
851                rect.getSizeY(), rect.getSizeZ(), rect.getSizeT(), rect.getSizeC());
852    }
853
854    /**
855     * Adds a 5D point, specified by the double precision coordinates arguments, to this
856     * <code>Rectangle5D</code>. The resulting <code>Rectangle5D</code> is the smallest
857     * <code>Rectangle5D</code> that contains both the original <code>Rectangle5D</code> and the
858     * specified 5D point.
859     * <p>
860     * After adding a 5D point, a call to <code>contains</code> with the added point as an argument
861     * does not necessarily return <code>true</code>. The <code>contains</code> method does not
862     * return <code>true</code> for points on the edges of a rectangle. Therefore, if the added 5D
863     * point falls on edge of the enlarged rectangle, <code>contains</code> returns
864     * <code>false</code> for that point.
865     * 
866     * @param newx
867     *        the X coordinate of the new point
868     * @param newy
869     *        the Y coordinate of the new point
870     * @param newz
871     *        the Z coordinate of the new point
872     * @param newt
873     *        the T coordinate of the new point
874     * @param newc
875     *        the C coordinate of the new point
876     */
877    public void add(double newx, double newy, double newz, double newt, double newc)
878    {
879        double x1 = Math.min(getMinX(), newx);
880        double x2 = Math.max(getMaxX(), newx);
881        double y1 = Math.min(getMinY(), newy);
882        double y2 = Math.max(getMaxY(), newy);
883        double z1 = Math.min(getMinZ(), newz);
884        double z2 = Math.max(getMaxZ(), newz);
885        double t1 = Math.min(getMinT(), newt);
886        double t2 = Math.max(getMaxT(), newt);
887        double c1 = Math.min(getMinC(), newc);
888        double c2 = Math.max(getMaxC(), newc);
889
890        double dx;
891        double dy;
892        double dz;
893        double dt;
894        double dc;
895
896        // special infinite case
897        if (x2 == java.lang.Double.POSITIVE_INFINITY)
898            dx = java.lang.Double.POSITIVE_INFINITY;
899        else
900            dx = x2 - x1;
901        // special infinite case
902        if (y2 == java.lang.Double.POSITIVE_INFINITY)
903            dy = java.lang.Double.POSITIVE_INFINITY;
904        else
905            dy = y2 - y1;
906        // special infinite case
907        if (z2 == java.lang.Double.POSITIVE_INFINITY)
908            dz = java.lang.Double.POSITIVE_INFINITY;
909        else
910            dz = z2 - z1;
911        // special infinite case
912        if (t2 == java.lang.Double.POSITIVE_INFINITY)
913            dt = java.lang.Double.POSITIVE_INFINITY;
914        else
915            dt = t2 - t1;
916        // special infinite case
917        if (c2 == java.lang.Double.POSITIVE_INFINITY)
918            dc = java.lang.Double.POSITIVE_INFINITY;
919        else
920            dc = c2 - c1;
921
922        setRect(x1, y1, z1, t1, c1, dx, dy, dz, dt, dc);
923    }
924
925    /**
926     * Adds the <code>Point5D</code> object <code>pt</code> to this <code>Rectangle5D</code>.
927     * The resulting <code>Rectangle5D</code> is the smallest <code>Rectangle5D</code> that contains
928     * both the original <code>Rectangle5D</code> and the specified <code>Point5D</code>.
929     * <p>
930     * After adding a point, a call to <code>contains</code> with the added point as an argument
931     * does not necessarily return <code>true</code>. The <code>contains</code> method does not
932     * return <code>true</code> for points on the edges of a rectangle. Therefore, if the added
933     * point falls on edge of the enlarged rectangle, <code>contains</code> returns
934     * <code>false</code> for that point.
935     * 
936     * @param pt
937     *        the new <code>Point5D</code> to add to this <code>Rectangle5D</code>.
938     */
939    public void add(Point5D pt)
940    {
941        add(pt.getX(), pt.getY(), pt.getZ(), pt.getT(), pt.getC());
942    }
943
944    /**
945     * Adds a <code>Rectangle5D</code> object to this <code>Rectangle5D</code>. The resulting
946     * <code>Rectangle5D</code> is the union of the two <code>Rectangle5D</code> objects.
947     * 
948     * @param r
949     *        the <code>Rectangle5D</code> to add to this <code>Rectangle5D</code>.
950     */
951    public void add(Rectangle5D r)
952    {
953        union(this, r, this);
954    }
955
956    /**
957     * Convert to 2D rectangle
958     */
959    public abstract Rectangle2D toRectangle2D();
960
961    /**
962     * Convert to 3D rectangle
963     */
964    public abstract Rectangle3D toRectangle3D();
965
966    /**
967     * Convert to 4D rectangle
968     */
969    public abstract Rectangle4D toRectangle4D();
970
971    @Override
972    public boolean equals(Object obj)
973    {
974        if (obj == this)
975            return true;
976        if (obj instanceof Rectangle5D)
977        {
978            final Rectangle5D rect = (Rectangle5D) obj;
979            return (getX() == rect.getX()) && (getY() == rect.getY()) && (getC() == rect.getC())
980                    && (getZ() == rect.getZ()) && (getT() == rect.getT()) && (getSizeX() == rect.getSizeX())
981                    && (getSizeY() == rect.getSizeY()) && (getSizeC() == rect.getSizeC())
982                    && (getSizeZ() == rect.getSizeZ()) && (getSizeT() == rect.getSizeT());
983        }
984
985        return super.equals(obj);
986    }
987
988    @Override
989    public int hashCode()
990    {
991        long bits = java.lang.Double.doubleToLongBits(getX());
992        bits ^= java.lang.Double.doubleToLongBits(getY());
993        bits ^= java.lang.Double.doubleToLongBits(getC());
994        bits ^= java.lang.Double.doubleToLongBits(getZ());
995        bits ^= java.lang.Double.doubleToLongBits(getT());
996        bits ^= java.lang.Double.doubleToLongBits(getSizeX());
997        bits ^= java.lang.Double.doubleToLongBits(getSizeY());
998        bits ^= java.lang.Double.doubleToLongBits(getSizeC());
999        bits ^= java.lang.Double.doubleToLongBits(getSizeZ());
1000        bits ^= java.lang.Double.doubleToLongBits(getSizeT());
1001        return (((int) bits) ^ ((int) (bits >> 32)));
1002    }
1003
1004    /**
1005     * Creates a new object of the same class as this object.
1006     * 
1007     * @return a clone of this instance.
1008     * @exception OutOfMemoryError
1009     *            if there is not enough memory.
1010     * @see java.lang.Cloneable
1011     */
1012    @Override
1013    public Object clone()
1014    {
1015        try
1016        {
1017            return super.clone();
1018        }
1019        catch (CloneNotSupportedException e)
1020        {
1021            // this shouldn't happen, since we are Cloneable
1022            throw new InternalError();
1023        }
1024    }
1025
1026    @Override
1027    public String toString()
1028    {
1029        return getClass().getName() + "[" + getX() + "," + getY() + "," + getZ() + "," + getT() + "," + getC() + " - "
1030                + getSizeX() + "," + getSizeY() + "," + getSizeZ() + "," + getSizeT() + "," + getSizeC() + "]";
1031    }
1032
1033    public static class Double extends Rectangle5D
1034    {
1035        public double x;
1036        public double y;
1037        public double z;
1038        public double t;
1039        public double c;
1040
1041        public double sizeX;
1042        public double sizeY;
1043        public double sizeZ;
1044        public double sizeT;
1045        public double sizeC;
1046
1047        public Double(double x, double y, double z, double t, double c, double sizeX, double sizeY, double sizeZ,
1048                double sizeT, double sizeC)
1049        {
1050            super();
1051
1052            this.x = x;
1053            this.y = y;
1054            this.z = z;
1055            this.t = t;
1056            this.c = c;
1057            this.sizeX = sizeX;
1058            this.sizeY = sizeY;
1059            this.sizeZ = sizeZ;
1060            this.sizeT = sizeT;
1061            this.sizeC = sizeC;
1062        }
1063
1064        public Double(Rectangle5D r)
1065        {
1066            this(r.getX(), r.getY(), r.getZ(), r.getT(), r.getC(), r.getSizeX(), r.getSizeY(), r.getSizeZ(), r
1067                    .getSizeT(), r.getSizeC());
1068        }
1069
1070        public Double()
1071        {
1072            this(0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
1073        }
1074
1075        @Override
1076        public void setRect(double x, double y, double z, double t, double c, double sizeX, double sizeY, double sizeZ,
1077                double sizeT, double sizeC)
1078        {
1079            this.x = x;
1080            this.y = y;
1081            this.z = z;
1082            this.t = t;
1083            this.c = c;
1084            this.sizeX = sizeX;
1085            this.sizeY = sizeY;
1086            this.sizeZ = sizeZ;
1087            this.sizeT = sizeT;
1088            this.sizeC = sizeC;
1089        }
1090
1091        @Override
1092        public double getX()
1093        {
1094            return x;
1095        }
1096
1097        @Override
1098        public void setX(double value)
1099        {
1100            x = value;
1101        }
1102
1103        @Override
1104        public double getY()
1105        {
1106            return y;
1107        }
1108
1109        @Override
1110        public void setY(double value)
1111        {
1112            y = value;
1113        }
1114
1115        @Override
1116        public double getZ()
1117        {
1118            return z;
1119        }
1120
1121        @Override
1122        public void setZ(double value)
1123        {
1124            z = value;
1125        }
1126
1127        @Override
1128        public double getT()
1129        {
1130            return t;
1131        }
1132
1133        @Override
1134        public void setT(double value)
1135        {
1136            t = value;
1137        }
1138
1139        @Override
1140        public double getC()
1141        {
1142            return c;
1143        }
1144
1145        @Override
1146        public void setC(double value)
1147        {
1148            c = value;
1149        }
1150
1151        @Override
1152        public double getSizeX()
1153        {
1154            return sizeX;
1155        }
1156
1157        @Override
1158        public void setSizeX(double value)
1159        {
1160            sizeX = value;
1161        }
1162
1163        @Override
1164        public double getSizeY()
1165        {
1166            return sizeY;
1167        }
1168
1169        @Override
1170        public void setSizeY(double value)
1171        {
1172            sizeY = value;
1173        }
1174
1175        @Override
1176        public double getSizeZ()
1177        {
1178            return sizeZ;
1179        }
1180
1181        @Override
1182        public void setSizeZ(double value)
1183        {
1184            sizeZ = value;
1185        }
1186
1187        @Override
1188        public double getSizeT()
1189        {
1190            return sizeT;
1191        }
1192
1193        @Override
1194        public void setSizeT(double value)
1195        {
1196            sizeT = value;
1197        }
1198
1199        @Override
1200        public double getSizeC()
1201        {
1202            return sizeC;
1203        }
1204
1205        @Override
1206        public void setSizeC(double value)
1207        {
1208            sizeC = value;
1209        }
1210
1211        @Override
1212        public Point5D.Double getPosition()
1213        {
1214            return new Point5D.Double(x, y, z, t, c);
1215        }
1216
1217        @Override
1218        public Dimension5D.Double getDimension()
1219        {
1220            return new Dimension5D.Double(sizeX, sizeY, sizeZ, sizeT, sizeC);
1221        }
1222
1223        @Override
1224        public Rectangle5D createIntersection(Rectangle5D r)
1225        {
1226            final Rectangle5D.Double result = new Rectangle5D.Double();
1227
1228            intersect(this, r, result);
1229
1230            return result;
1231        }
1232
1233        @Override
1234        public Rectangle5D createUnion(Rectangle5D r)
1235        {
1236            final Rectangle5D.Double result = new Rectangle5D.Double();
1237
1238            union(this, r, result);
1239
1240            return result;
1241        }
1242
1243        @Override
1244        public Rectangle2D toRectangle2D()
1245        {
1246            return new Rectangle2D.Double(x, y, sizeX, sizeY);
1247        }
1248
1249        @Override
1250        public Rectangle3D toRectangle3D()
1251        {
1252            return new Rectangle3D.Double(x, y, z, sizeX, sizeY, sizeZ);
1253        }
1254
1255        @Override
1256        public Rectangle4D toRectangle4D()
1257        {
1258            return new Rectangle4D.Double(x, y, z, t, sizeX, sizeY, sizeZ, sizeT);
1259        }
1260    }
1261
1262    public static class Float extends Rectangle5D
1263    {
1264        public float x;
1265        public float y;
1266        public float z;
1267        public float t;
1268        public float c;
1269
1270        public float sizeX;
1271        public float sizeY;
1272        public float sizeZ;
1273        public float sizeT;
1274        public float sizeC;
1275
1276        public Float(float x, float y, float z, float t, float c, float sizeX, float sizeY, float sizeZ, float sizeT,
1277                float sizeC)
1278        {
1279            super();
1280
1281            this.x = x;
1282            this.y = y;
1283            this.z = z;
1284            this.t = t;
1285            this.c = c;
1286            this.sizeX = sizeX;
1287            this.sizeY = sizeY;
1288            this.sizeZ = sizeZ;
1289            this.sizeT = sizeT;
1290            this.sizeC = sizeC;
1291        }
1292
1293        public Float(Rectangle5D r)
1294        {
1295            this((float) r.getX(), (float) r.getY(), (float) r.getZ(), (float) r.getT(), (float) r.getC(), (float) r
1296                    .getSizeX(), (float) r.getSizeY(), (float) r.getSizeZ(), (float) r.getSizeT(), (float) r.getSizeC());
1297        }
1298
1299        public Float()
1300        {
1301            this(0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
1302        }
1303
1304        @Override
1305        public void setRect(double x, double y, double z, double t, double c, double sizeX, double sizeY, double sizeZ,
1306                double sizeT, double sizeC)
1307        {
1308            this.x = (float) x;
1309            this.y = (float) y;
1310            this.z = (float) z;
1311            this.t = (float) t;
1312            this.c = (float) c;
1313            this.sizeX = (float) sizeX;
1314            this.sizeY = (float) sizeY;
1315            this.sizeZ = (float) sizeZ;
1316            this.sizeT = (float) sizeT;
1317            this.sizeC = (float) sizeC;
1318        }
1319
1320        @Override
1321        public double getX()
1322        {
1323            // special infinite case
1324            if (x == java.lang.Float.NEGATIVE_INFINITY)
1325                return java.lang.Double.NEGATIVE_INFINITY;
1326            if (x == java.lang.Float.POSITIVE_INFINITY)
1327                return java.lang.Double.POSITIVE_INFINITY;
1328
1329            return x;
1330        }
1331
1332        @Override
1333        public void setX(double value)
1334        {
1335            x = (float) value;
1336        }
1337
1338        @Override
1339        public double getY()
1340        {
1341            // special infinite case
1342            if (y == java.lang.Float.NEGATIVE_INFINITY)
1343                return java.lang.Double.NEGATIVE_INFINITY;
1344            if (y == java.lang.Float.POSITIVE_INFINITY)
1345                return java.lang.Double.POSITIVE_INFINITY;
1346
1347            return y;
1348        }
1349
1350        @Override
1351        public void setY(double value)
1352        {
1353            y = (float) value;
1354        }
1355
1356        @Override
1357        public double getZ()
1358        {
1359            // special infinite case
1360            if (z == java.lang.Float.NEGATIVE_INFINITY)
1361                return java.lang.Double.NEGATIVE_INFINITY;
1362            if (z == java.lang.Float.POSITIVE_INFINITY)
1363                return java.lang.Double.POSITIVE_INFINITY;
1364
1365            return z;
1366        }
1367
1368        @Override
1369        public void setZ(double value)
1370        {
1371            z = (float) value;
1372        }
1373
1374        @Override
1375        public double getT()
1376        {
1377            // special infinite case
1378            if (t == java.lang.Float.NEGATIVE_INFINITY)
1379                return java.lang.Double.NEGATIVE_INFINITY;
1380            if (t == java.lang.Float.POSITIVE_INFINITY)
1381                return java.lang.Double.POSITIVE_INFINITY;
1382
1383            return t;
1384        }
1385
1386        @Override
1387        public void setT(double value)
1388        {
1389            t = (float) value;
1390        }
1391
1392        @Override
1393        public double getC()
1394        {
1395            // special infinite case
1396            if (c == java.lang.Float.NEGATIVE_INFINITY)
1397                return java.lang.Double.NEGATIVE_INFINITY;
1398            if (c == java.lang.Float.POSITIVE_INFINITY)
1399                return java.lang.Double.POSITIVE_INFINITY;
1400
1401            return c;
1402        }
1403
1404        @Override
1405        public void setC(double value)
1406        {
1407            c = (float) value;
1408        }
1409
1410        @Override
1411        public double getSizeX()
1412        {
1413            // special infinite case
1414            if (sizeX == java.lang.Float.POSITIVE_INFINITY)
1415                return java.lang.Double.POSITIVE_INFINITY;
1416
1417            return sizeX;
1418        }
1419
1420        @Override
1421        public void setSizeX(double value)
1422        {
1423            sizeX = (float) value;
1424        }
1425
1426        @Override
1427        public double getSizeY()
1428        {
1429            // special infinite case
1430            if (sizeY == java.lang.Float.POSITIVE_INFINITY)
1431                return java.lang.Double.POSITIVE_INFINITY;
1432
1433            return sizeY;
1434        }
1435
1436        @Override
1437        public void setSizeY(double value)
1438        {
1439            sizeY = (float) value;
1440        }
1441
1442        @Override
1443        public double getSizeZ()
1444        {
1445            // special infinite case
1446            if (sizeZ == java.lang.Float.POSITIVE_INFINITY)
1447                return java.lang.Double.POSITIVE_INFINITY;
1448
1449            return sizeZ;
1450        }
1451
1452        @Override
1453        public void setSizeZ(double value)
1454        {
1455            sizeZ = (float) value;
1456        }
1457
1458        @Override
1459        public double getSizeT()
1460        {
1461            // special infinite case
1462            if (sizeT == java.lang.Float.POSITIVE_INFINITY)
1463                return java.lang.Double.POSITIVE_INFINITY;
1464
1465            return sizeT;
1466        }
1467
1468        @Override
1469        public void setSizeT(double value)
1470        {
1471            sizeT = (float) value;
1472        }
1473
1474        @Override
1475        public double getSizeC()
1476        {
1477            // special infinite case
1478            if (sizeC == java.lang.Float.POSITIVE_INFINITY)
1479                return java.lang.Double.POSITIVE_INFINITY;
1480
1481            return sizeC;
1482        }
1483
1484        @Override
1485        public void setSizeC(double value)
1486        {
1487            sizeC = (float) value;
1488        }
1489
1490        @Override
1491        public Point5D.Float getPosition()
1492        {
1493            return new Point5D.Float(x, y, z, t, c);
1494        }
1495
1496        @Override
1497        public Dimension5D.Float getDimension()
1498        {
1499            return new Dimension5D.Float(sizeX, sizeY, sizeZ, sizeT, sizeC);
1500        }
1501
1502        @Override
1503        public Rectangle5D createIntersection(Rectangle5D r)
1504        {
1505            final Rectangle5D.Float result = new Rectangle5D.Float();
1506
1507            intersect(this, r, result);
1508
1509            return result;
1510        }
1511
1512        @Override
1513        public Rectangle5D createUnion(Rectangle5D r)
1514        {
1515            final Rectangle5D.Float result = new Rectangle5D.Float();
1516
1517            union(this, r, result);
1518
1519            return result;
1520        }
1521
1522        @Override
1523        public Rectangle2D toRectangle2D()
1524        {
1525            return new Rectangle2D.Float(x, y, sizeX, sizeY);
1526        }
1527
1528        @Override
1529        public Rectangle3D toRectangle3D()
1530        {
1531            return new Rectangle3D.Float(x, y, z, sizeX, sizeY, sizeZ);
1532        }
1533
1534        @Override
1535        public Rectangle4D toRectangle4D()
1536        {
1537            return new Rectangle4D.Float(x, y, z, t, sizeX, sizeY, sizeZ, sizeT);
1538        }
1539    }
1540
1541    public static class Integer extends Rectangle5D
1542    {
1543        public int x;
1544        public int y;
1545        public int z;
1546        public int t;
1547        public int c;
1548        public int sizeX;
1549        public int sizeY;
1550        public int sizeZ;
1551        public int sizeT;
1552        public int sizeC;
1553
1554        public Integer(int x, int y, int z, int t, int c, int sizeX, int sizeY, int sizeZ, int sizeT, int sizeC)
1555        {
1556            super();
1557
1558            this.x = x;
1559            this.y = y;
1560            this.z = z;
1561            this.t = t;
1562            this.c = c;
1563            this.sizeX = sizeX;
1564            this.sizeY = sizeY;
1565            this.sizeZ = sizeZ;
1566            this.sizeT = sizeT;
1567            this.sizeC = sizeC;
1568        }
1569
1570        public Integer(Rectangle5D.Integer r)
1571        {
1572            this(r.x, r.y, r.z, r.t, r.c, r.sizeX, r.sizeY, r.sizeZ, r.sizeT, r.sizeC);
1573        }
1574
1575        public Integer(Rectangle5D r)
1576        {
1577            this(r.toInteger());
1578        }
1579
1580        public Integer()
1581        {
1582            this(0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
1583        }
1584
1585        /**
1586         * Sets the bounds of this {@code Rectangle5D} to the integer bounds
1587         * which encompass the specified double bounds.
1588         * 
1589         * @param x
1590         *        the X coordinate of the minimum corner position of this <code>Rectangle5D</code>
1591         * @param y
1592         *        the Y coordinate of the minimum corner position of this <code>Rectangle5D</code>
1593         * @param z
1594         *        the Z coordinate of the minimum corner position of this <code>Rectangle5D</code>
1595         * @param t
1596         *        the T coordinate of the minimum corner position of this <code>Rectangle5D</code>
1597         * @param c
1598         *        the C coordinate of the minimum corner position of this <code>Rectangle5D</code>
1599         * @param sizeX
1600         *        size for X dimension of this <code>Rectangle5D</code>
1601         * @param sizeY
1602         *        size for Y dimension of this <code>Rectangle5D</code>
1603         * @param sizeZ
1604         *        size for Z dimension of this <code>Rectangle5D</code>
1605         * @param sizeT
1606         *        size for T dimension of this <code>Rectangle5D</code>
1607         * @param sizeC
1608         *        size for C dimension of this <code>Rectangle5D</code>
1609         */
1610        @Override
1611        public void setRect(double x, double y, double z, double t, double c, double sizeX, double sizeY, double sizeZ,
1612                double sizeT, double sizeC)
1613        {
1614            final Rectangle5D.Integer r = new Rectangle5D.Double(x, y, z, t, c, sizeX, sizeY, sizeZ, sizeT, sizeC)
1615                    .toInteger();
1616            setRect(r.x, r.y, r.z, r.t, r.c, r.sizeX, r.sizeY, r.sizeZ, r.sizeT, r.sizeC);
1617        }
1618
1619        /**
1620         * Sets the position and size of this <code>Rectangle5D</code> to the specified
1621         * <code>integer</code> values.
1622         * 
1623         * @param x
1624         *        the X coordinate of the minimum corner position of this <code>Rectangle5D</code>
1625         * @param y
1626         *        the Y coordinate of the minimum corner position of this <code>Rectangle5D</code>
1627         * @param z
1628         *        the Z coordinate of the minimum corner position of this <code>Rectangle5D</code>
1629         * @param t
1630         *        the T coordinate of the minimum corner position of this <code>Rectangle5D</code>
1631         * @param c
1632         *        the C coordinate of the minimum corner position of this <code>Rectangle5D</code>
1633         * @param sizeX
1634         *        size for X dimension of this <code>Rectangle5D</code>
1635         * @param sizeY
1636         *        size for Y dimension of this <code>Rectangle5D</code>
1637         * @param sizeZ
1638         *        size for Z dimension of this <code>Rectangle5D</code>
1639         * @param sizeT
1640         *        size for T dimension of this <code>Rectangle5D</code>
1641         * @param sizeC
1642         *        size for C dimension of this <code>Rectangle5D</code>
1643         */
1644        public void setRect(int x, int y, int z, int t, int c, int sizeX, int sizeY, int sizeZ, int sizeT, int sizeC)
1645        {
1646            this.x = x;
1647            this.y = y;
1648            this.z = z;
1649            this.t = t;
1650            this.c = c;
1651            this.sizeX = sizeX;
1652            this.sizeY = sizeY;
1653            this.sizeZ = sizeZ;
1654            this.sizeT = sizeT;
1655            this.sizeC = sizeC;
1656        }
1657
1658        @Override
1659        public double getX()
1660        {
1661            // special infinite case
1662            if (x == java.lang.Integer.MIN_VALUE)
1663                return java.lang.Double.NEGATIVE_INFINITY;
1664            if (x == java.lang.Integer.MAX_VALUE)
1665                return java.lang.Double.POSITIVE_INFINITY;
1666
1667            return x;
1668        }
1669
1670        @Override
1671        public void setX(double value)
1672        {
1673            x = (int) value;
1674        }
1675
1676        @Override
1677        public double getY()
1678        {
1679            // special infinite case
1680            if (y == java.lang.Integer.MIN_VALUE)
1681                return java.lang.Double.NEGATIVE_INFINITY;
1682            if (y == java.lang.Integer.MAX_VALUE)
1683                return java.lang.Double.POSITIVE_INFINITY;
1684
1685            return y;
1686        }
1687
1688        @Override
1689        public void setY(double value)
1690        {
1691            y = (int) value;
1692        }
1693
1694        @Override
1695        public double getZ()
1696        {
1697            // special infinite case
1698            if (z == java.lang.Integer.MIN_VALUE)
1699                return java.lang.Double.NEGATIVE_INFINITY;
1700            if (z == java.lang.Integer.MAX_VALUE)
1701                return java.lang.Double.POSITIVE_INFINITY;
1702
1703            return z;
1704        }
1705
1706        @Override
1707        public void setZ(double value)
1708        {
1709            z = (int) value;
1710        }
1711
1712        @Override
1713        public double getT()
1714        {
1715            // special infinite case
1716            if (t == java.lang.Integer.MIN_VALUE)
1717                return java.lang.Double.NEGATIVE_INFINITY;
1718            if (t == java.lang.Integer.MAX_VALUE)
1719                return java.lang.Double.POSITIVE_INFINITY;
1720
1721            return t;
1722        }
1723
1724        @Override
1725        public void setT(double value)
1726        {
1727            t = (int) value;
1728        }
1729
1730        @Override
1731        public double getC()
1732        {
1733            // special infinite case
1734            if (c == java.lang.Integer.MIN_VALUE)
1735                return java.lang.Double.NEGATIVE_INFINITY;
1736            if (c == java.lang.Integer.MAX_VALUE)
1737                return java.lang.Double.POSITIVE_INFINITY;
1738
1739            return c;
1740        }
1741
1742        @Override
1743        public void setC(double value)
1744        {
1745            c = (int) value;
1746        }
1747
1748        @Override
1749        public double getSizeX()
1750        {
1751            // special infinite case
1752            if (sizeX == java.lang.Integer.MAX_VALUE)
1753                return java.lang.Double.POSITIVE_INFINITY;
1754
1755            return sizeX;
1756        }
1757
1758        @Override
1759        public void setSizeX(double value)
1760        {
1761            sizeX = (int) value;
1762        }
1763
1764        @Override
1765        public double getSizeY()
1766        {
1767            // special infinite case
1768            if (sizeY == java.lang.Integer.MAX_VALUE)
1769                return java.lang.Double.POSITIVE_INFINITY;
1770
1771            return sizeY;
1772        }
1773
1774        @Override
1775        public void setSizeY(double value)
1776        {
1777            sizeY = (int) value;
1778        }
1779
1780        @Override
1781        public double getSizeZ()
1782        {
1783            // special infinite case
1784            if (sizeZ == java.lang.Integer.MAX_VALUE)
1785                return java.lang.Double.POSITIVE_INFINITY;
1786
1787            return sizeZ;
1788        }
1789
1790        @Override
1791        public void setSizeZ(double value)
1792        {
1793            sizeZ = (int) value;
1794        }
1795
1796        @Override
1797        public double getSizeT()
1798        {
1799            // special infinite case
1800            if (sizeT == java.lang.Integer.MAX_VALUE)
1801                return java.lang.Double.POSITIVE_INFINITY;
1802
1803            return sizeT;
1804        }
1805
1806        @Override
1807        public void setSizeT(double value)
1808        {
1809            sizeT = (int) value;
1810        }
1811
1812        @Override
1813        public double getSizeC()
1814        {
1815            // special infinite case
1816            if (sizeC == java.lang.Integer.MAX_VALUE)
1817                return java.lang.Double.POSITIVE_INFINITY;
1818
1819            return sizeC;
1820        }
1821
1822        @Override
1823        public void setSizeC(double value)
1824        {
1825            sizeC = (int) value;
1826        }
1827
1828        @Override
1829        public Point5D.Integer getPosition()
1830        {
1831            return new Point5D.Integer(x, y, z, t, c);
1832        }
1833
1834        @Override
1835        public Dimension5D.Integer getDimension()
1836        {
1837            return new Dimension5D.Integer(sizeX, sizeY, sizeZ, sizeT, sizeC);
1838        }
1839
1840        @Override
1841        public Rectangle5D.Integer toInteger()
1842        {
1843            return (Integer) clone();
1844        }
1845
1846        @Override
1847        public Rectangle5D createIntersection(Rectangle5D r)
1848        {
1849            final Rectangle5D.Integer result = new Rectangle5D.Integer();
1850
1851            intersect(this, r, result);
1852
1853            return result;
1854        }
1855
1856        @Override
1857        public Rectangle5D createUnion(Rectangle5D r)
1858        {
1859            final Rectangle5D.Integer result = new Rectangle5D.Integer();
1860
1861            union(this, r, result);
1862
1863            return result;
1864        }
1865
1866        @Override
1867        public Rectangle2D toRectangle2D()
1868        {
1869            return new Rectangle(x, y, sizeX, sizeY);
1870        }
1871
1872        @Override
1873        public Rectangle3D toRectangle3D()
1874        {
1875            return new Rectangle3D.Integer(x, y, z, sizeX, sizeY, sizeZ);
1876        }
1877
1878        @Override
1879        public Rectangle4D toRectangle4D()
1880        {
1881            return new Rectangle4D.Integer(x, y, z, t, sizeX, sizeY, sizeZ, sizeT);
1882        }
1883    }
1884}