diff --git a/src/com/annimon/graphics/Clip.java b/src/com/annimon/graphics/Clip.java new file mode 100644 index 0000000..e7a6d37 --- /dev/null +++ b/src/com/annimon/graphics/Clip.java @@ -0,0 +1,35 @@ +package com.annimon.graphics; + +/** + * @author aNNiMON + */ +public class Clip extends Rect { + + public Clip(double x, double y, double width, double height) { + super(x, y, width, height); + } + + public void setClip(double x, double y, double width, double height) { + super.x = x; + super.y = y; + super.width = width; + super.height = height; + } + + public double getXMax() { + return x + width; + } + + public double getYMax() { + return y + height; + } + + public int getClipCode(double x, double y) { + int xmin = (x < super.x) ? 1 : 0; + int xmax = (x > getXMax()) ? 1 : 0; + int ymin = (y < super.y) ? 1 : 0; + int ymax = (y > getYMax()) ? 1 : 0; + return (xmin << 3) | (xmax << 2) | (ymin << 1) | ymax; + } + +}