Update of /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model
In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv26296/src/net/sourceforge/bprocessor/model
Modified Files:
Grid.java
Log Message:
Snapping to grid implemented
Index: Grid.java
===================================================================
RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Grid.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** Grid.java 19 May 2009 10:33:45 -0000 1.6
--- Grid.java 26 May 2009 10:33:50 -0000 1.7
***************
*** 7,10 ****
--- 7,11 ----
package net.sourceforge.bprocessor.model;
+ import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
***************
*** 83,86 ****
--- 84,140 ----
}
+
+ /**
+ *
+ * @return lines
+ */
+ public Collection<Line> lines() {
+
+ double size = getSize();
+ double delta = getDistance();
+ CoordinateSystem system = Project.getInstance().getActiveCoordinateSystem();
+ Vertex origin = system.getOrigin();
+ Vertex v = system.getI();
+ Vertex u = system.getJ();
+ int n = (int) Math.floor((size / 2) / delta);
+
+ Collection<Line> lines = new LinkedList();
+
+ for (int i = 0; i < n; i++) {
+ Vertex o = origin.add(u.scale(i * delta));
+ Line line = new Line(o, v);
+ lines.add(line);
+ }
+ for (int i = 1; i < n; i++) {
+ Vertex o = origin.add(u.scale(-i * delta));
+ Line line = new Line(o, v);
+ lines.add(line);
+ }
+ for (int i = 0; i < n; i++) {
+ Vertex o = origin.add(v.scale(i * delta));
+ Line line = new Line(o, u);
+ lines.add(line);
+ }
+ for (int i = 1; i < n; i++) {
+ Vertex o = origin.add(v.scale(-i * delta));
+ Line line = new Line(o, u);
+ lines.add(line);
+ }
+ return lines;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Collection<Edge> guides(double length) {
+ Collection<Edge> guides = super.guides(length);
+ Collection<Line> lines = lines();
+ for (Line line : lines) {
+ Edge edge = line.edge(length);
+ guides.add(edge);
+ }
+ return guides;
+ }
+
/** {@inheritDoc} */
public String title() {
|