~ubuntu-branches/ubuntu/trusty/libjgraph-java/trusty

« back to all changes in this revision

Viewing changes to src/org/jgraph/util/RectUtils.java

  • Committer: Bazaar Package Importer
  • Author(s): gregor herrmann
  • Date: 2008-03-17 20:28:08 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20080317202808-jol9tcnnn9lu0gc3
Tags: 5.12.0.4.dfsg-1
* New upstream release.
* Remove debian/dirs and create /usr/share/java directly from
  debian/rules.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * $Id: RectUtils.java,v 1.2 2008/02/28 14:38:48 david Exp $
 
3
 *
 
4
 * Copyright (c) 2008 Gaudenz Alder
 
5
 *
 
6
 */
 
7
 
 
8
package org.jgraph.util;
 
9
 
 
10
import java.awt.geom.Rectangle2D;
 
11
 
 
12
public class RectUtils {
 
13
        /**
 
14
         * Unions the pair of source <code>Rectangle2D</code> objects and puts the
 
15
         * result into the returned <code>Rectangle2D</code> object. This method
 
16
         * extends the Rectangle2D version by checking for null parameters, the
 
17
         * returned value will also be <code>null</code> if the two input
 
18
         * rectangles are <code>null</code>
 
19
         * 
 
20
         * @param src1
 
21
         *            the first of a pair of <code>Rectangle2D</code> objects to
 
22
         *            be combined with each other
 
23
         * @param src2
 
24
         *            the second of a pair of <code>Rectangle2D</code> objects to
 
25
         *            be combined with each other
 
26
         * 
 
27
         */
 
28
        public static Rectangle2D union(Rectangle2D src1, Rectangle2D src2) {
 
29
                Rectangle2D result = null;
 
30
                if (src1 == null && src2 == null) {
 
31
                        result = null;
 
32
                } else if (src1 != null && src2 != null) {
 
33
                        double x1 = Math.min(src1.getMinX(), src2.getMinX());
 
34
                        double y1 = Math.min(src1.getMinY(), src2.getMinY());
 
35
                        double x2 = Math.max(src1.getMaxX(), src2.getMaxX());
 
36
                        double y2 = Math.max(src1.getMaxY(), src2.getMaxY());
 
37
                        result = new Rectangle2D.Double();
 
38
                        result.setFrameFromDiagonal(x1, y1, x2, y2);
 
39
                } else if (src1 != null) {
 
40
                        double x1 = src1.getMinX();
 
41
                        double y1 = src1.getMinY();
 
42
                        double x2 = src1.getMaxX();
 
43
                        double y2 = src1.getMaxY();
 
44
                        result = new Rectangle2D.Double();
 
45
                        result.setFrameFromDiagonal(x1, y1, x2, y2);
 
46
                } else {
 
47
                        // only src2 is non-null
 
48
                        double x1 = src2.getMinX();
 
49
                        double y1 = src2.getMinY();
 
50
                        double x2 = src2.getMaxX();
 
51
                        double y2 = src2.getMaxY();
 
52
                        result = new Rectangle2D.Double();
 
53
                        result.setFrameFromDiagonal(x1, y1, x2, y2);
 
54
                }
 
55
                return result;
 
56
        }
 
57
}