Добавлен интерфейс Clippable для классов Clip/PolygonClip

This commit is contained in:
Victor 2014-03-03 15:20:39 +02:00
parent 3d476f1778
commit a693c784fb
2 changed files with 6 additions and 5 deletions

View File

@ -3,7 +3,7 @@ package com.annimon.graphics;
/** /**
* @author aNNiMON * @author aNNiMON
*/ */
public class Clip extends Rect { public class Clip extends Rect implements Clippable {
public Clip(double x, double y, double width, double height) { public Clip(double x, double y, double width, double height) {
super(x, y, width, height); super(x, y, width, height);
@ -24,6 +24,7 @@ public class Clip extends Rect {
return y + height; return y + height;
} }
@Override
public double[] clip(double x1, double y1, double x2, double y2) { public double[] clip(double x1, double y1, double x2, double y2) {
int c1 = getClipCode(x1, y1); int c1 = getClipCode(x1, y1);
int c2 = getClipCode(x2, y2); int c2 = getClipCode(x2, y2);
@ -68,7 +69,7 @@ public class Clip extends Rect {
return new double[] { x1, y1, x2, y2 }; return new double[] { x1, y1, x2, y2 };
} }
public int getClipCode(double x, double y) { private int getClipCode(double x, double y) {
int xmin = (x < super.x) ? 1 : 0; int xmin = (x < super.x) ? 1 : 0;
int xmax = (x > getXMax()) ? 1 : 0; int xmax = (x > getXMax()) ? 1 : 0;
int ymin = (y < super.y) ? 1 : 0; int ymin = (y < super.y) ? 1 : 0;

View File

@ -4,7 +4,7 @@ package com.annimon.graphics;
* *
* @author aNNiMON * @author aNNiMON
*/ */
public class PolygonClip extends Clip { public class PolygonClip extends Clip implements Clippable {
private final Polygon poly; private final Polygon poly;
@ -54,11 +54,11 @@ public class PolygonClip extends Clip {
Point dirV = new Point(p2.getX() - p1.getX(), p2.getY() - p1.getY()); Point dirV = new Point(p2.getX() - p1.getX(), p2.getY() - p1.getY());
Point F = new Point(); Point F = new Point();
boolean visible = true; boolean visible = true;
int i = 0; int i = 0;
while ((i < poly.nPoints) && visible) { while ((i < poly.nPoints) && visible) {
F.setX(p1.getX() - poly.v[i].getX()); F.setX(p1.getX() - poly.v[i].getX());
F.setY(p1.getY() - poly.v[i].getY()); F.setY(p1.getY() - poly.v[i].getY());
double num = pointProduction(n[i], F); double num = pointProduction(n[i], F);
double den = pointProduction(n[i], dirV); double den = pointProduction(n[i], dirV);