| •1 |
|
| 2 |
|
| 3 |
|
| •4 |
|
| 5 |
|
| •6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| •11 |
|
| 12 |
|
| 13 |
|
| •14 |
|
| 15 |
|
| •16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
package org.stathissideris.ascii2image.graphics; |
| 21 |
|
| •22 |
import java.awt.geom.Point2D.Float; |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
public class ShapePoint extends java.awt.geom.Point2D.Float { |
| 29 |
|
| 30 |
public static final int TYPE_NORMAL = 0; |
| 31 |
public static final int TYPE_ROUND = 1; |
| 32 |
|
| 33 |
private boolean locked = false; |
| 34 |
|
| 35 |
private int type = 0; |
| 36 |
|
| 37 |
public ShapePoint() { |
| 38 |
super(); |
| 39 |
} |
| 40 |
|
| 41 |
public ShapePoint(float x, float y) { |
| 42 |
super(x, y); |
| 43 |
this.type = TYPE_NORMAL; |
| 44 |
} |
| 45 |
|
| 46 |
public ShapePoint(float x, float y, int type) { |
| 47 |
super(x, y); |
| 48 |
this.type = type; |
| 49 |
} |
| 50 |
|
| 51 |
public ShapePoint(ShapePoint other){ |
| 52 |
this(other.x, other.y, other.type); |
| 53 |
} |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
public int getType() { |
| 59 |
return type; |
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
public void setType(int i) { |
| 66 |
type = i; |
| 67 |
} |
| 68 |
|
| 69 |
public boolean isInLineWith(ShapePoint point){ |
| 70 |
if(this.x == point.x) return true; |
| 71 |
if(this.y == point.y) return true; |
| 72 |
return false; |
| 73 |
} |
| 74 |
|
| 75 |
public boolean isWithinEdge(ShapeEdge edge) { |
| 76 |
if(edge.isHorizontal()) { |
| 77 |
if(x >= edge.getStartPoint().x && x <= edge.getEndPoint().x) return true; |
| 78 |
if(x >= edge.getEndPoint().x && x <= edge.getStartPoint().x) return true; |
| 79 |
return false; |
| 80 |
} else if(edge.isVertical()) { |
| 81 |
if(y >= edge.getStartPoint().y && y <= edge.getEndPoint().y) return true; |
| 82 |
if(y >= edge.getEndPoint().y && y <= edge.getStartPoint().y) return true; |
| 83 |
return false; |
| 84 |
} |
| 85 |
throw new RuntimeException("Cannot calculate is ShapePoint is within sloped edge"); |
| 86 |
} |
| 87 |
|
| 88 |
public boolean isNorthOf(ShapePoint point){ |
| 89 |
return (this.y < point.y); |
| 90 |
} |
| 91 |
|
| 92 |
public boolean isSouthOf(ShapePoint point){ |
| 93 |
return (this.y > point.y); |
| 94 |
} |
| 95 |
|
| 96 |
public boolean isWestOf(ShapePoint point){ |
| 97 |
return (this.x < point.x); |
| 98 |
} |
| 99 |
|
| 100 |
public boolean isEastOf(ShapePoint point){ |
| 101 |
return (this.x > point.x); |
| 102 |
} |
| 103 |
|
| 104 |
public String toString(){ |
| 105 |
return "("+x+", "+y+")"; |
| 106 |
} |
| 107 |
|
| 108 |
public void assign(ShapePoint point){ |
| 109 |
this.x = point.x; |
| 110 |
this.y = point.y; |
| 111 |
} |
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
public void moveTo(ShapePoint point){ |
| 120 |
if(locked) return; |
| 121 |
this.x = point.x; |
| 122 |
this.y = point.y; |
| 123 |
} |
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
public boolean isLocked() { |
| 130 |
return locked; |
| 131 |
} |
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
public void setLocked(boolean b) { |
| 137 |
locked = b; |
| 138 |
} |
| 139 |
|
| 140 |
} |