Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package mypkg;
- public class Rectangle
- {
- private int iX1, iY1, iX2, iY2;
- public Rectangle()
- {
- iX1 = 0;
- iY1 = 0;
- iX2 = 0;
- iY2 = 0;
- }
- public Rectangle(int x1, int y1, int x2, int y2)
- {
- iX1 = x1;
- iY1 = y1;
- iX2 = x2;
- iY2 = y2;
- }
- public int getiX1()
- {
- return iX1;
- }
- public int getiY1()
- {
- return iY1;
- }
- public int getiX2()
- {
- return iX2;
- }
- public int getiY2()
- {
- return iY2;
- }
- public int calcArea()
- {
- int height = getiY1() - getiY2();
- int width = getiX2() - getiX1();
- return height*width;
- }
- public int compareTo(Object r)
- {
- if ( (getiY1() - getiY2()) * (getiX2() - getiX1()) > ((Rectangle) r).calcArea())
- return 1;
- else if ( (getiY1() - getiY2()) * (getiX2() - getiX1()) < ((Rectangle) r).calcArea())
- return -1;
- else
- return 0;
- }
- public String toString()
- {
- return iX1+" "+iY1+" "+iX2+" "+iY2;
- }
- public boolean equals(Rectangle r)
- {
- return this.calcArea() == r.calcArea();
- }
- public void translateX(int iPoints)
- {
- iX1 = iX1 + iPoints;
- iX2 = iX2 + iPoints;
- }
- public void translateY(int iPoints)
- {
- iX1 = iX1 + iPoints;
- iX2 = iX2 + iPoints;
- }
- public void translateXY(int iPoints)
- {
- iX1 = iX1 + iPoints;
- iX2 = iX2 + iPoints;
- iX1 = iX1 + iPoints;
- iX2 = iX2 + iPoints;
- }
- public boolean isInside(int ptX, int ptY)
- {
- if(ptX > iX1 && ptX < iX2 && ptY > iY1 && ptY < iY2)
- return true;
- return false;
- }
- public Rectangle intersectionRect(Rectangle r)
- {
- int leftX = Math.max(this.iX1, r.iX1);
- int rightX = Math.min(this.iX2, r.iX2);
- int topY = Math.max(this.iY1, r.iY1);
- int bottomY = Math.min(this.iY2, r.iY2);
- if (leftX < rightX && topY < bottomY)
- return new Rectangle(leftX, topY, rightX, bottomY);
- else
- return null;
- }
- public Rectangle unionRect(Rectangle r)
- {
- int leftX = Math.min(this.iX1, r.iX1);
- int rightX = Math.max(this.iX2, r.iX2);
- int topY = Math.min(this.iY1, r.iY1);
- int bottomY = Math.max(this.iY2, r.iY2);
- if (leftX < rightX && topY < bottomY)
- return new Rectangle(leftX, topY, rightX, bottomY);
- else
- return null;
- }
- /*public static void main(String[] args)
- {
- Rectangle oR1 = new Rectangle(0,0,10,8);
- Rectangle oR2 = new Rectangle(2,3,7,9);
- System.out.println(oR1);
- System.out.println(oR2);
- oR1.calcArea();
- }*/
- }
- public class Color implements Comparable
- {
- private long RValue, GValue, BValue;
- private long ColorValue = 256*256*RValue + 256*GValue + 1*BValue;
- public Color()
- {}
- public Color(long c)
- {
- ColorValue = c;
- }
- public long getRValue()
- {
- return RValue;
- }
- public long getGValue()
- {
- return GValue;
- }
- public long getBValue()
- {
- return BValue;
- }
- public void setRValue(long R)
- {
- RValue = R;
- }
- public void setGValue(long G)
- {
- GValue = G;
- }
- public void setBValue(long B)
- {
- BValue = B;
- }
- public String toString()
- {
- return RValue+" "+GValue+" "+BValue+" "+Color;
- }
- public boolean equals(Object c)
- {
- if(this.RValue == ((Color) c).getRValue() && this.GValue == ((Color) c).getGValue() && this.BValue == ((Color) c).getBValue())
- return true;
- }
- public int compareTo(Object c)
- {
- if (ColorValue < ((Color) c).ColorValue)
- return -1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement