Debian Codegraph @

src/org/stathissideris/ascii2image/graphics/ShapePoint.java

raw symbols ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 /*
2 * DiTAA - Diagrams Through Ascii Art
3 *
4 * Copyright (C) 2004 Efstathios Sideris
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 *
20 */
21 package org.stathissideris.ascii2image.graphics;
22
23
24 /**
25 *
26 * @author Efstathios Sideris
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 * @return
57 */
58 public int getType() {
59 return type;
60 }
61
62 /**
63 * @param i
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 * Does the same as assign, but respects the
115 * locked attribute
116 *
117 * @param point
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 * @return
128 */
129 public boolean isLocked() {
130 return locked;
131 }
132
133 /**
134 * @param b
135 */
136 public void setLocked(boolean b) {
137 locked = b;
138 }
139
140 }