javauis/eswt_qt/s60utils/java/src/com/nokia/mj/impl/uitestutils/Rect.java
changeset 35 85266cc22c7f
parent 26 dc7c549001d5
child 40 c6043ea9b06a
child 44 0105bdca6f9c
child 47 f40128debb5d
child 49 35baca0e7a2e
equal deleted inserted replaced
26:dc7c549001d5 35:85266cc22c7f
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 package com.nokia.mj.impl.uitestutils;
       
    18 
       
    19 /**
       
    20  * Simple rect container
       
    21  * @author sampkaar
       
    22  *
       
    23  */
       
    24 public class Rect {
       
    25 	
       
    26 	private int x;
       
    27 	private int y;
       
    28 	private int width;
       
    29 	private int height;
       
    30 	
       
    31 	public Rect(int x, int y, int width, int height) {
       
    32 		this.x = x;
       
    33 		this.y = y;
       
    34 		this.width = width;
       
    35 		this.height = height;
       
    36 	}
       
    37 	
       
    38 	public int x() {
       
    39 		return this.x;
       
    40 	}
       
    41 	
       
    42 	public int y() {
       
    43 		return this.y;
       
    44 	}
       
    45 	
       
    46 	public int width() {
       
    47 		return this.width;
       
    48 	}
       
    49 	
       
    50 	public int height() {
       
    51 		return this.height;
       
    52 	}
       
    53 
       
    54 	public Rect intersection(Rect aRect){
       
    55 
       
    56 		if( aRect.x < this.x && aRect.x+aRect.width < this.x ||
       
    57             aRect.x > this.x+this.width && aRect.x+aRect.width > this.x+this.width)
       
    58         { // no intersection
       
    59         	return new Rect(0,0,0,0);
       
    60         } 
       
    61         if( aRect.y < this.y && aRect.y+aRect.height < this.y ||
       
    62             aRect.y > this.y+this.height && aRect.y+aRect.height > this.y+this.height)
       
    63         { // no intersection
       
    64             return new Rect(0,0,0,0);
       
    65         }
       
    66         int x = 0;
       
    67         int y = 0;
       
    68         int w = 0;
       
    69         int h = 0;
       
    70         
       
    71         if(aRect.x < this.x)
       
    72         {
       
    73         	x = this.x;
       
    74         	if (this.x + this.width < aRect.x + aRect.width)
       
    75         	{
       
    76         		w = this.width;
       
    77         	}else
       
    78         	{
       
    79         		w = aRect.x + aRect.width - this.x;        		
       
    80         	}
       
    81         } else
       
    82         { // aRect.x >= this.x
       
    83         	x = aRect.x;        	
       
    84         	if (aRect.x + aRect.width < this.x + this.width)
       
    85         	{
       
    86         		w = aRect.width;
       
    87         	}else
       
    88         	{
       
    89         		w = this.x + this.width - aRect.x;
       
    90         	}
       
    91         }
       
    92         if(aRect.y < this.y)
       
    93         {
       
    94         	y = this.y;
       
    95         	if (this.y + this.height < aRect.y + aRect.height)
       
    96         	{
       
    97         		h = this.height;
       
    98         	}else
       
    99         	{
       
   100         		h = aRect.y + aRect.height - this.y;
       
   101         	}
       
   102         } else
       
   103         { // aRect.y >= this.y
       
   104         	y = aRect.y;        	
       
   105         	if (aRect.y + aRect.height < this.y + this.height)
       
   106         	{
       
   107         		h = aRect.height;
       
   108         	}else
       
   109         	{
       
   110         		h = this.y + this.height - aRect.y;        		
       
   111         	}
       
   112         }
       
   113 		return new Rect(x, y, w, h);
       
   114 	}
       
   115 
       
   116 }