mirror of
https://github.com/euphy/polargraphcontroller
synced 2024-11-15 10:47:56 +01:00
127 lines
3.0 KiB
Plaintext
127 lines
3.0 KiB
Plaintext
/**
|
|
Polargraph controller
|
|
Copyright Sandy Noble 2015.
|
|
|
|
This file is part of Polargraph Controller.
|
|
|
|
Polargraph Controller is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
Polargraph Controller is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with Polargraph Controller. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
Requires the excellent ControlP5 GUI library available from http://www.sojamo.de/libraries/controlP5/.
|
|
Requires the excellent Geomerative library available from http://www.ricardmarxer.com/geomerative/.
|
|
|
|
This is an application for controlling a polargraph machine, communicating using ASCII command language over a serial link.
|
|
|
|
sandy.noble@gmail.com
|
|
http://www.polargraph.co.uk/
|
|
https://github.com/euphy/polargraphcontroller
|
|
|
|
*/
|
|
class Rectangle
|
|
{
|
|
public PVector position = null;
|
|
public PVector size = null;
|
|
|
|
public Rectangle(float px, float py, float width, float height)
|
|
{
|
|
this.position = new PVector(px, py);
|
|
this.size = new PVector(width, height);
|
|
}
|
|
public Rectangle(PVector position, PVector size)
|
|
{
|
|
this.position = position;
|
|
this.size = size;
|
|
}
|
|
public Rectangle(Rectangle r)
|
|
{
|
|
this.position = new PVector(r.getPosition().x, r.getPosition().y);
|
|
this.size = new PVector(r.getSize().x, r.getSize().y);
|
|
}
|
|
|
|
public float getWidth()
|
|
{
|
|
return this.size.x;
|
|
}
|
|
public void setWidth(float w)
|
|
{
|
|
this.size.x = w;
|
|
}
|
|
public float getHeight()
|
|
{
|
|
return this.size.y;
|
|
}
|
|
public void setHeight(float h)
|
|
{
|
|
this.size.y = h;
|
|
}
|
|
public PVector getPosition()
|
|
{
|
|
return this.position;
|
|
}
|
|
public PVector getSize()
|
|
{
|
|
return this.size;
|
|
}
|
|
public PVector getTopLeft()
|
|
{
|
|
return getPosition();
|
|
}
|
|
public PVector getTopRight()
|
|
{
|
|
return new PVector(this.size.x+this.position.x, this.position.y);
|
|
}
|
|
public PVector getBotRight()
|
|
{
|
|
return PVector.add(this.position, this.size);
|
|
}
|
|
public float getLeft()
|
|
{
|
|
return getPosition().x;
|
|
}
|
|
public float getRight()
|
|
{
|
|
return getPosition().x + getSize().x;
|
|
}
|
|
public float getTop()
|
|
{
|
|
return getPosition().y;
|
|
}
|
|
public float getBottom()
|
|
{
|
|
return getPosition().y + getSize().y;
|
|
}
|
|
|
|
public void setPosition(float x, float y)
|
|
{
|
|
if (this.position == null)
|
|
this.position = new PVector(x, y);
|
|
else
|
|
{
|
|
this.position.x = x;
|
|
this.position.y = y;
|
|
}
|
|
}
|
|
|
|
public Boolean surrounds(PVector p)
|
|
{
|
|
if (p.x >= this.getLeft()
|
|
&& p.x < this.getRight()
|
|
&& p.y >= this.getTop()
|
|
&& p.y < this.getBottom()-1)
|
|
return true;
|
|
else
|
|
return false;
|
|
}
|
|
|
|
}
|