Rectangle.java
/**
* Copyright 2010,2021 Nikolas S Boyd.
Permission is granted to copy this work provided this copyright statement is retained in all copies.
*/
package Hoot.Geometry;
import Hoot.Runtime.Functions.*;
import Hoot.Runtime.Faces.*;
import Hoot.Runtime.Values.*;
import Hoot.Runtime.Blocks.*;
import Smalltalk.Core.*;
import Smalltalk.Blocks.*;
import Smalltalk.Magnitudes.*;
import Hoot.Behaviors.*;
import Hoot.Behaviors.Nil;
import Hoot.Behaviors.Object;
import Hoot.Behaviors.True;
import Hoot.Behaviors.False;
import Hoot.Behaviors.Boolean;
import Hoot.Magnitudes.*;
import Hoot.Magnitudes.Integer;
import Hoot.Magnitudes.Character;
import Hoot.Magnitudes.Float;
import Hoot.Magnitudes.Double;
import Hoot.Collections.*;
import Hoot.Collections.String;
import Hoot.Magnitudes.Number;
public class Rectangle extends Object
{
public static Metaclass type() { return (Metaclass)Metaclass.$class; }
@Override public Metaclass $class() { return (Metaclass)Metaclass.$class; }
public static class Metaclass extends Object.Metaclass
{
static final Rectangle.Metaclass $class = new Rectangle.Metaclass();
public Metaclass() {
this(Rectangle.Metaclass.class);
}
public Metaclass(java.lang.Class aClass) {
super(aClass);
}
@Override public java.lang.Class outerClass() { return Rectangle.class; }
/**
* @return
*/
@Override public Rectangle $new()
{
java.lang.String exitID = "RectangleMetatype>>$new";
Frame f0 = new Frame(exitID);
return f0.evaluate(() -> {
return (Rectangle)f0.exit(exitID, new Rectangle());
});
}
}
protected Point origin = new Point();
protected Point extent = new Point();
/**
*
*/
protected Rectangle()
{
java.lang.String exitID = "Rectangle>>Rectangle";
Frame f0 = new Frame(exitID);
origin = (SmallInteger.from(0).at(SmallInteger.from(0)));
extent = (SmallInteger.from(0).at(SmallInteger.from(0)));
}
/**
*
*/
protected Rectangle(final Point originPoint, final Point extentPoint)
{
java.lang.String exitID = "Rectangle>>Rectangle";
Frame f0 = new Frame(exitID);
origin = originPoint;
extent = extentPoint;
}
/**
* @return
*/
public static Rectangle origin_extent(final Point origin, final Point extent)
{
java.lang.String exitID = "Rectangle>>$origin_extent";
Frame f0 = new Frame(exitID);
return (Rectangle)new Rectangle(origin, extent);
}
/**
* @return
*/
public static Rectangle origin_corner(final Point origin, final Point corner)
{
java.lang.String exitID = "Rectangle>>$origin_corner";
Frame f0 = new Frame(exitID);
Rectangle result = new Rectangle();
result.origin(origin);
result.corner(corner);
return (Rectangle)result;
}
/**
* @return
*/
public Point origin()
{
java.lang.String exitID = "Rectangle>>origin";
Frame f0 = new Frame(exitID);
return (Point)origin;
}
/**
* @return
*/
public Point origin(final Point originPoint)
{
java.lang.String exitID = "Rectangle>>origin";
Frame f0 = new Frame(exitID);
origin = originPoint;
return (Point)originPoint;
}
/**
* @return
*/
public Point corner()
{
java.lang.String exitID = "Rectangle>>corner";
Frame f0 = new Frame(exitID);
return (Point)((origin.x().plus(extent.x())).at((origin.y().plus(extent.y()))));
}
/**
* @return
*/
public Point corner(final Point cornerPoint)
{
java.lang.String exitID = "Rectangle>>corner";
Frame f0 = new Frame(exitID);
this.extent((cornerPoint.minus(origin)));
return (Point)cornerPoint;
}
/**
* @return
*/
public Number top()
{
java.lang.String exitID = "Rectangle>>top";
Frame f0 = new Frame(exitID);
return (Number)this.origin().y();
}
/**
* @return
*/
public Number bottom()
{
java.lang.String exitID = "Rectangle>>bottom";
Frame f0 = new Frame(exitID);
return (Number)this.corner().y();
}
/**
* @return
*/
public Number left()
{
java.lang.String exitID = "Rectangle>>left";
Frame f0 = new Frame(exitID);
return (Number)this.origin().x();
}
/**
* @return
*/
public Number right()
{
java.lang.String exitID = "Rectangle>>right";
Frame f0 = new Frame(exitID);
return (Number)this.corner().x();
}
/**
* @return
*/
public Point center()
{
java.lang.String exitID = "Rectangle>>center";
Frame f0 = new Frame(exitID);
return (Point)(this.origin().plus((this.extent().divideWith(SmallInteger.from(2)))));
}
/**
* @return
*/
public Point topCenter()
{
java.lang.String exitID = "Rectangle>>topCenter";
Frame f0 = new Frame(exitID);
return (Point)(this.center().x().at(this.top()));
}
/**
* @return
*/
public Point bottomCenter()
{
java.lang.String exitID = "Rectangle>>bottomCenter";
Frame f0 = new Frame(exitID);
return (Point)(this.center().x().at(this.bottom()));
}
/**
* @return
*/
public Point leftCenter()
{
java.lang.String exitID = "Rectangle>>leftCenter";
Frame f0 = new Frame(exitID);
return (Point)(this.left().at(this.center().y()));
}
/**
* @return
*/
public Point rightCenter()
{
java.lang.String exitID = "Rectangle>>rightCenter";
Frame f0 = new Frame(exitID);
return (Point)(this.right().at(this.center().y()));
}
/**
* @return
*/
public Point bottomLeft()
{
java.lang.String exitID = "Rectangle>>bottomLeft";
Frame f0 = new Frame(exitID);
return (Point)(this.left().at(this.bottom()));
}
/**
* @return
*/
public Point bottomRight()
{
java.lang.String exitID = "Rectangle>>bottomRight";
Frame f0 = new Frame(exitID);
return (Point)(this.right().at(this.bottom()));
}
/**
* @return
*/
public Point leftTop()
{
java.lang.String exitID = "Rectangle>>leftTop";
Frame f0 = new Frame(exitID);
return (Point)(this.left().at(this.top()));
}
/**
* @return
*/
public Point leftBottom()
{
java.lang.String exitID = "Rectangle>>leftBottom";
Frame f0 = new Frame(exitID);
return (Point)this.bottomLeft();
}
/**
* @return
*/
public Point rightTop()
{
java.lang.String exitID = "Rectangle>>rightTop";
Frame f0 = new Frame(exitID);
return (Point)(this.right().at(this.top()));
}
/**
* @return
*/
public Point rightBottom()
{
java.lang.String exitID = "Rectangle>>rightBottom";
Frame f0 = new Frame(exitID);
return (Point)this.bottomRight();
}
/**
* @return
*/
public Point topLeft()
{
java.lang.String exitID = "Rectangle>>topLeft";
Frame f0 = new Frame(exitID);
return (Point)this.leftTop();
}
/**
* @return
*/
public Point topRight()
{
java.lang.String exitID = "Rectangle>>topRight";
Frame f0 = new Frame(exitID);
return (Point)this.rightTop();
}
/**
* @return
*/
public Array<Point> corners()
{
java.lang.String exitID = "Rectangle>>corners";
Frame f0 = new Frame(exitID);
return (Array<Point>)Array.withAll(this.leftTop(), this.rightTop(), this.leftBottom(), this.rightBottom());
}
/**
* @return
*/
public Point extent()
{
java.lang.String exitID = "Rectangle>>extent";
Frame f0 = new Frame(exitID);
return (Point)extent;
}
/**
* @return
*/
public Point extent(final Point extentPoint)
{
java.lang.String exitID = "Rectangle>>extent";
Frame f0 = new Frame(exitID);
extent = extentPoint;
return (Point)extentPoint;
}
/**
* @return
*/
public Number width()
{
java.lang.String exitID = "Rectangle>>width";
Frame f0 = new Frame(exitID);
return (Number)extent.x();
}
/**
* @return
*/
public Number width(final Number width)
{
java.lang.String exitID = "Rectangle>>width";
Frame f0 = new Frame(exitID);
extent.x(width);
return (Number)width;
}
/**
* @return
*/
public Number height()
{
java.lang.String exitID = "Rectangle>>height";
Frame f0 = new Frame(exitID);
return (Number)extent.y();
}
/**
* @return
*/
public Number height(final Number height)
{
java.lang.String exitID = "Rectangle>>height";
Frame f0 = new Frame(exitID);
extent.y(height);
return (Number)height;
}
/**
* @return
*/
public Number area()
{
java.lang.String exitID = "Rectangle>>area";
Frame f0 = new Frame(exitID);
return (Number)(this.width().times(this.height()));
}
/**
* @return
*/
@Override public int hashCode()
{
java.lang.String exitID = "Rectangle>>hashCode";
Frame f0 = new Frame(exitID);
return (int)origin.hash().bitXor(extent.hash()).primitiveInteger();
}
/**
* @return
*/
public Boolean equals(final Rectangle aRectangle)
{
java.lang.String exitID = "Rectangle>>equals";
Frame f0 = new Frame(exitID);
return (Boolean)((Boolean)(origin.equals(aRectangle.origin())).and(Predicate.with(f2 -> {
return (extent.equals(aRectangle.extent()));
}, "")));
}
/**
* @return
*/
@Override public Boolean equals(final Subject value)
{
java.lang.String exitID = "Rectangle>>equals";
Frame f0 = new Frame(exitID);
if (value instanceof Rectangle) {
return this.equals(((Rectangle)value));
};
return (Boolean)False.literal();
}
/**
* @return
*/
public java.awt.Rectangle primitiveRectangle()
{
java.lang.String exitID = "Rectangle>>primitiveRectangle";
Frame f0 = new Frame(exitID);
return (java.awt.Rectangle)new java.awt.Rectangle(origin.primitivePoint(), extent.primitiveDimension());
}
/**
* @return
*/
@Override public String printString()
{
java.lang.String exitID = "Rectangle>>printString";
Frame f0 = new Frame(exitID);
return (String)origin.printString().append(String.from(" extent: ")).append(extent.printString());
}
/**
* @return
*/
@Override public java.lang.String toString()
{
java.lang.String exitID = "Rectangle>>toString";
Frame f0 = new Frame(exitID);
return (java.lang.String)this.printTerm().toString();
}
/**
* @return
*/
public Boolean contains(final Rectangle aRectangle)
{
java.lang.String exitID = "Rectangle>>contains";
Frame f0 = new Frame(exitID);
return (Boolean)((Boolean)(this.origin().notMore(aRectangle.origin())).and(Predicate.with(f2 -> {
return (this.corner().notLess(aRectangle.corner()));
}, "")));
}
/**
* @return
*/
public Boolean containsPoint(final Point aPoint)
{
java.lang.String exitID = "Rectangle>>containsPoint";
Frame f0 = new Frame(exitID);
return (Boolean)((Boolean)aPoint.between_and(this.origin(), this.corner()));
}
/**
* @return
*/
public Boolean intersects(final Rectangle aRectangle)
{
java.lang.String exitID = "Rectangle>>intersects";
Frame f0 = new Frame(exitID);
return (Boolean)((Boolean)(this.origin().notMore(aRectangle.corner())).and(Predicate.with(f2 -> {
return (aRectangle.origin().notMore(this.corner()));
}, "")));
}
}