Changeset 30345 in osm for applications/editors/josm/plugins/alignways
- Timestamp:
- 2014-03-24T21:33:27+01:00 (12 years ago)
- Location:
- applications/editors/josm/plugins/alignways/src/com/tilusnet/josm/plugins/alignways
- Files:
-
- 10 edited
-
AlignWaysAction.java (modified) (1 diff)
-
AlignWaysAlgnSegment.java (modified) (4 diffs)
-
AlignWaysCmdKeepAngles.java (modified) (4 diffs)
-
AlignWaysCmdKeepLength.java (modified) (3 diffs)
-
AlignWaysDialog.java (modified) (1 diff)
-
AlignWaysMode.java (modified) (1 diff)
-
AlignWaysSegment.java (modified) (2 diffs)
-
AlignWaysWhatsNewPanel.java (modified) (3 diffs)
-
geometry/AlignWaysGeomLine.java (modified) (4 diffs)
-
geometry/AlignWaysGeomPoint.java (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/alignways/src/com/tilusnet/josm/plugins/alignways/AlignWaysAction.java
r28624 r30345 32 32 tr("Makes a pair of selected way segments parallel by rotating one of them " 33 33 + "around a chosen pivot."), 34 Shortcut.registerShortcut("tools:alignways", tr("Tool: {0}", tr("Align Ways")),34 Shortcut.registerShortcut("tools:alignways", tr("Tool: {0}", tr("Align Ways")), 35 35 KeyEvent.VK_SPACE, Shortcut.SHIFT) 36 , true);36 , true); 37 37 setEnabled(false); 38 38 } -
applications/editors/josm/plugins/alignways/src/com/tilusnet/josm/plugins/alignways/AlignWaysAlgnSegment.java
r27348 r30345 64 64 } 65 65 66 /* (non-Javadoc)67 * @see com.tilusnet.josm.plugins.alignways.AlignWaysSegment#setSegmentEndpoints(org.openstreetmap.josm.data.osm.WaySegment)68 */69 66 @Override 70 67 void setSegmentEndpoints(WaySegment segment) { … … 75 72 adjWaySegs.put(nA, new ArrayList<WaySegment>(determineAdjacentWaysegments(nA))); 76 73 } 77 78 74 } 79 75 … … 223 219 } 224 220 225 /*226 * (non-Javadoc)227 *228 * @see229 * com.tilusnet.josm.plugins.alignways.AlignWaysRefSegment#paint(java230 * .awt.Graphics2D, org.openstreetmap.josm.gui.MapView,231 * org.openstreetmap.josm.data.Bounds)232 */233 221 @Override 234 222 public void paint(Graphics2D g, MapView mv, Bounds bbox) { … … 248 236 // Highlight active pivot 249 237 highlightPivot(g, mv, getPivotCoord(currPivot)); 250 251 238 } 252 239 -
applications/editors/josm/plugins/alignways/src/com/tilusnet/josm/plugins/alignways/AlignWaysCmdKeepAngles.java
r29854 r30345 55 55 56 56 if (endpoint.getEastNorth().equals(pivot)) { 57 // endpoint is pivot: the coordinates won't change58 return;57 // endpoint is pivot: the coordinates won't change 58 return; 59 59 } 60 60 … … 64 64 // - the alignee following the keep length rule 65 65 // - the adjacent way segment 66 67 Node adjOther1 = getNonEqualNode(alws.get(0), endpoint);68 EastNorth enAdjOther1 = adjOther1.getEastNorth();69 Node adjOther2 = null;70 EastNorth enAdjOther2 = null;66 67 Node adjOther1 = getNonEqualNode(alws.get(0), endpoint); 68 EastNorth enAdjOther1 = adjOther1.getEastNorth(); 69 Node adjOther2 = null; 70 EastNorth enAdjOther2 = null; 71 71 72 72 if (alws.size() == 2) { 73 adjOther2 = getNonEqualNode(alws.get(1), endpoint);74 enAdjOther2 = adjOther2.getEastNorth();75 76 // In order have a chance to align, (enAdjOther1, enAdjOther2 and endpoint) must be collinear77 ArrayList<EastNorth> enAdjPts = new ArrayList<EastNorth>(3);78 enAdjPts.add(enAdjOther1);79 enAdjPts.add(endpoint.getEastNorth());80 enAdjPts.add(enAdjOther2);81 if (!isEnSetCollinear(enAdjPts)) {82 // Not collinear, no point to proceed73 adjOther2 = getNonEqualNode(alws.get(1), endpoint); 74 enAdjOther2 = adjOther2.getEastNorth(); 75 76 // In order have a chance to align, (enAdjOther1, enAdjOther2 and endpoint) must be collinear 77 ArrayList<EastNorth> enAdjPts = new ArrayList<EastNorth>(3); 78 enAdjPts.add(enAdjOther1); 79 enAdjPts.add(endpoint.getEastNorth()); 80 enAdjPts.add(enAdjOther2); 81 if (!isEnSetCollinear(enAdjPts)) { 82 // Not collinear, no point to proceed 83 83 alignableStatKeepAngles = AlignableStatus.ALGN_INV_ANGLE_PRESERVING_CONFLICT; 84 84 return; 85 }86 85 } 86 87 87 } 88 88 89 89 // Update the calculated node for angle preserving alignment 90 90 AlignWaysGeomPoint isectPnt = alignedLineKeepLength.getIntersection(new AlignWaysGeomLine(enAdjOther1.getX(), enAdjOther1.getY(), 91 endpoint.getEastNorth().getX(), endpoint.getEastNorth().getY()));91 endpoint.getEastNorth().getX(), endpoint.getEastNorth().getY())); 92 92 EastNorth enIsectPt = null; 93 93 // If the intersection is null, the adjacent and the alignee are parallel already: 94 94 // there's no need to update this node 95 95 if (isectPnt != null) { 96 enIsectPt = new EastNorth(isectPnt.getX(), isectPnt.getY());97 // Don't "record" it yet as it may not be valid96 enIsectPt = new EastNorth(isectPnt.getX(), isectPnt.getY()); 97 // Don't "record" it yet as it may not be valid 98 98 } else if (alignedLineKeepLength.getIntersectionStatus() == IntersectionStatus.LINES_PARALLEL) { 99 99 alignableStatKeepAngles = AlignableStatus.ALGN_INV_ANGLE_PRESERVING_CONFLICT; … … 107 107 // TODO - find a solution 108 108 if (alws.size() == 2 && enIsectPt != null) { 109 int middlePtIdx = AlignWaysGeomPoint.getMiddleOf3(110 new AlignWaysGeomPoint(enIsectPt),111 new AlignWaysGeomPoint(enAdjOther1),112 new AlignWaysGeomPoint(enAdjOther2));113 if (middlePtIdx != 0) {114 EastNorth middlePt = null;115 switch(middlePtIdx) {116 case 1:117 middlePt = enIsectPt;118 break;119 case 2:120 middlePt = enAdjOther1;121 break;122 case 3:123 middlePt = enAdjOther2;124 break;125 }126 if (middlePt != null) {127 double eps = 1E-6;128 if (!middlePt.equalsEpsilon(enIsectPt, eps)) {129 // Intersection point didn't fall between the two adjacent points; not allowed130 alignableStatKeepAngles = AlignableStatus.ALGN_INV_XPOINT_FALLSOUT;131 return;132 133 /*134 if (middlePt.equalsEpsilon(enAdjOther1, eps)) {135 // Delete adjOther1136 // adjOther1.setDeleted(true);137 } else138 if (true);139 // Delete adjOther2140 // adjOther2.setDeleted(true);141 */142 }143 }144 }109 int middlePtIdx = AlignWaysGeomPoint.getMiddleOf3( 110 new AlignWaysGeomPoint(enIsectPt), 111 new AlignWaysGeomPoint(enAdjOther1), 112 new AlignWaysGeomPoint(enAdjOther2)); 113 if (middlePtIdx != 0) { 114 EastNorth middlePt = null; 115 switch(middlePtIdx) { 116 case 1: 117 middlePt = enIsectPt; 118 break; 119 case 2: 120 middlePt = enAdjOther1; 121 break; 122 case 3: 123 middlePt = enAdjOther2; 124 break; 125 } 126 if (middlePt != null) { 127 double eps = 1E-6; 128 if (!middlePt.equalsEpsilon(enIsectPt, eps)) { 129 // Intersection point didn't fall between the two adjacent points; not allowed 130 alignableStatKeepAngles = AlignableStatus.ALGN_INV_XPOINT_FALLSOUT; 131 return; 132 133 /* 134 if (middlePt.equalsEpsilon(enAdjOther1, eps)) { 135 // Delete adjOther1 136 // adjOther1.setDeleted(true); 137 } else 138 if (true); 139 // Delete adjOther2 140 // adjOther2.setDeleted(true); 141 */ 142 } 143 } 144 } 145 145 } 146 146 147 147 if (isectPnt != null) { 148 148 // Angle preserving alignment passed all verification tests: record it. 149 calculatedNodes.put(endpoint, enIsectPt);149 calculatedNodes.put(endpoint, enIsectPt); 150 150 } 151 151 152 152 153 153 } else { 154 // angle preserving alignment not possible154 // angle preserving alignment not possible 155 155 alignableStatKeepAngles = AlignableStatus.ALGN_INV_TOOMANY_CONNECTED_WS; 156 156 } … … 160 160 161 161 private boolean isEnSetCollinear(ArrayList<EastNorth> enAdjPts) { 162 ArrayList<AlignWaysGeomPoint> awAdjPts = new ArrayList<AlignWaysGeomPoint>();163 164 for (EastNorth en : enAdjPts) {165 AlignWaysGeomPoint pt = new AlignWaysGeomPoint(en.getX(), en.getY());166 awAdjPts.add(pt);167 }168 169 return AlignWaysGeomPoint.isSetCollinear(awAdjPts);170 }171 172 173 private Node getNonEqualNode(WaySegment waySegment, Node endpoint) {174 if (waySegment.getFirstNode().equals(endpoint)) {175 return waySegment.getSecondNode();176 } else if (waySegment.getSecondNode().equals(endpoint)) {177 return waySegment.getFirstNode();178 } else179 return null;180 }181 182 183 /**162 ArrayList<AlignWaysGeomPoint> awAdjPts = new ArrayList<AlignWaysGeomPoint>(); 163 164 for (EastNorth en : enAdjPts) { 165 AlignWaysGeomPoint pt = new AlignWaysGeomPoint(en.getX(), en.getY()); 166 awAdjPts.add(pt); 167 } 168 169 return AlignWaysGeomPoint.isSetCollinear(awAdjPts); 170 } 171 172 173 private Node getNonEqualNode(WaySegment waySegment, Node endpoint) { 174 if (waySegment.getFirstNode().equals(endpoint)) { 175 return waySegment.getSecondNode(); 176 } else if (waySegment.getSecondNode().equals(endpoint)) { 177 return waySegment.getFirstNode(); 178 } else 179 return null; 180 } 181 182 183 /** 184 184 * Reports invalid alignable statuses on screen in dialog boxes. 185 185 * -
applications/editors/josm/plugins/alignways/src/com/tilusnet/josm/plugins/alignways/AlignWaysCmdKeepLength.java
r29854 r30345 197 197 } 198 198 199 /*200 * (non-Javadoc)201 *202 * @see203 * org.openstreetmap.josm.command.Command#fillModifiedData(java.util.Collection204 * , java.util.Collection, java.util.Collection)205 */206 199 @Override 207 200 public void fillModifiedData(Collection<OsmPrimitive> modified, … … 212 205 } 213 206 214 /*215 * (non-Javadoc)216 *217 * @see org.openstreetmap.josm.command.Command#executeCommand()218 */219 207 @Override 220 208 public boolean executeCommand() { … … 223 211 } 224 212 225 /*226 * (non-Javadoc)227 *228 * @see org.openstreetmap.josm.command.Command#undoCommand()229 */230 213 @Override 231 214 public void undoCommand() { -
applications/editors/josm/plugins/alignways/src/com/tilusnet/josm/plugins/alignways/AlignWaysDialog.java
r29854 r30345 74 74 modesPanel.setLayout(new BoxLayout(modesPanel, BoxLayout.PAGE_AXIS)); 75 75 /* 76 modesPanel.setBorder(BorderFactory.createCompoundBorder(77 BorderFactory.createEmptyBorder(10, 10, 10, 10),78 BorderFactory.createTitledBorder(tr("Align with:")))79 );76 modesPanel.setBorder(BorderFactory.createCompoundBorder( 77 BorderFactory.createEmptyBorder(10, 10, 10, 10), 78 BorderFactory.createTitledBorder(tr("Align with:"))) 79 ); 80 80 */ 81 81 modesPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); -
applications/editors/josm/plugins/alignways/src/com/tilusnet/josm/plugins/alignways/AlignWaysMode.java
r27852 r30345 228 228 } 229 229 230 /* (non-Javadoc)231 * @see org.openstreetmap.josm.actions.mapmode.MapMode#layerIsSupported(org.openstreetmap.josm.gui.layer.Layer)232 */233 230 @Override 234 231 public boolean layerIsSupported(Layer l) { -
applications/editors/josm/plugins/alignways/src/com/tilusnet/josm/plugins/alignways/AlignWaysSegment.java
r27348 r30345 27 27 public class AlignWaysSegment implements MapViewPaintable { 28 28 29 protected WaySegment segment;30 protected MapView mapview;31 protected Color segmentColor = Color.WHITE;32 protected Collection<Node> segmentEndPoints;29 protected WaySegment segment; 30 protected MapView mapview; 31 protected Color segmentColor = Color.WHITE; 32 protected Collection<Node> segmentEndPoints; 33 33 34 public AlignWaysSegment(MapView mapview, Point p) throws IllegalArgumentException {35 if (mapview == null)36 throw new IllegalArgumentException(tr(37 "Parameter ''{0}'' must not be null", "mapview"));38 if (p == null)39 throw new IllegalArgumentException(tr(40 "Parameter ''{0}'' must not be null", "p"));34 public AlignWaysSegment(MapView mapview, Point p) throws IllegalArgumentException { 35 if (mapview == null) 36 throw new IllegalArgumentException(tr( 37 "Parameter ''{0}'' must not be null", "mapview")); 38 if (p == null) 39 throw new IllegalArgumentException(tr( 40 "Parameter ''{0}'' must not be null", "p")); 41 41 42 this.mapview = mapview;43 }42 this.mapview = mapview; 43 } 44 44 45 void setSegment(WaySegment segment) {46 this.segment = segment;47 if (segment != null) {48 setSegmentEndpoints(segment);49 mapview.addTemporaryLayer(this);50 }51 }45 void setSegment(WaySegment segment) { 46 this.segment = segment; 47 if (segment != null) { 48 setSegmentEndpoints(segment); 49 mapview.addTemporaryLayer(this); 50 } 51 } 52 52 53 53 54 void setSegmentEndpoints(WaySegment segment) {55 if (segment != null) {56 Node node1 = segment.way.getNode(segment.lowerIndex);57 Node node2 = segment.way.getNode(segment.lowerIndex + 1);54 void setSegmentEndpoints(WaySegment segment) { 55 if (segment != null) { 56 Node node1 = segment.way.getNode(segment.lowerIndex); 57 Node node2 = segment.way.getNode(segment.lowerIndex + 1); 58 58 59 segmentEndPoints = new HashSet<Node>();60 segmentEndPoints.add(node1);61 segmentEndPoints.add(node2);59 segmentEndPoints = new HashSet<Node>(); 60 segmentEndPoints.add(node1); 61 segmentEndPoints.add(node2); 62 62 63 }64 }63 } 64 } 65 65 66 protected WaySegment getNearestWaySegment(Point p) {66 protected WaySegment getNearestWaySegment(Point p) { 67 67 68 return mapview.getNearestWaySegment(p, OsmPrimitive.isUsablePredicate);68 return mapview.getNearestWaySegment(p, OsmPrimitive.isUsablePredicate); 69 69 70 }70 } 71 71 72 public void destroy() {73 if (segment != null) {74 mapview.removeTemporaryLayer(this);75 }76 }72 public void destroy() { 73 if (segment != null) { 74 mapview.removeTemporaryLayer(this); 75 } 76 } 77 77 78 public WaySegment getSegment() {79 return segment;80 }78 public WaySegment getSegment() { 79 return segment; 80 } 81 81 82 public Collection<Node> getSegmentEndPoints() {83 return segmentEndPoints;84 }82 public Collection<Node> getSegmentEndPoints() { 83 return segmentEndPoints; 84 } 85 85 86 @Override87 public void paint(Graphics2D g, MapView mv, Bounds bbox) {88 highlightSegment(segmentColor, g, mv);89 }86 @Override 87 public void paint(Graphics2D g, MapView mv, Bounds bbox) { 88 highlightSegment(segmentColor, g, mv); 89 } 90 90 91 protected void highlightSegment(Color c, Graphics2D g, MapView mv) {91 protected void highlightSegment(Color c, Graphics2D g, MapView mv) { 92 92 93 g.setColor(c);94 g.setStroke(new BasicStroke(6, BasicStroke.CAP_ROUND,95 BasicStroke.JOIN_ROUND));96 drawSegment(g, mv);93 g.setColor(c); 94 g.setStroke(new BasicStroke(6, BasicStroke.CAP_ROUND, 95 BasicStroke.JOIN_ROUND)); 96 drawSegment(g, mv); 97 97 98 }98 } 99 99 100 protected void drawSegment(Graphics2D g, MapView mv) {101 Node n1 = segment.way.getNode(segment.lowerIndex);102 Node n2 = segment.way.getNode(segment.lowerIndex + 1);100 protected void drawSegment(Graphics2D g, MapView mv) { 101 Node n1 = segment.way.getNode(segment.lowerIndex); 102 Node n2 = segment.way.getNode(segment.lowerIndex + 1); 103 103 104 Line2D newline = new Line2D.Double(mv.getPoint(n1), mv.getPoint(n2));105 g.draw(newline);106 }104 Line2D newline = new Line2D.Double(mv.getPoint(n1), mv.getPoint(n2)); 105 g.draw(newline); 106 } 107 107 108 /* 109 * (non-Javadoc) 110 * 111 * @see java.lang.Object#hashCode() 112 */ 113 @Override 114 public int hashCode() { 115 final int prime = 31; 116 int result = 1; 117 result = prime * result + ((segment == null) ? 0 : segment.hashCode()); 118 result = prime * result 119 + ((segmentColor == null) ? 0 : segmentColor.hashCode()); 120 return result; 121 } 108 @Override 109 public int hashCode() { 110 final int prime = 31; 111 int result = 1; 112 result = prime * result + ((segment == null) ? 0 : segment.hashCode()); 113 result = prime * result 114 + ((segmentColor == null) ? 0 : segmentColor.hashCode()); 115 return result; 116 } 122 117 123 /* 124 * (non-Javadoc) 125 * 126 * @see java.lang.Object#equals(java.lang.Object) 127 */ 128 @Override 129 public boolean equals(Object obj) { 130 if (this == obj) 131 return true; 132 if (obj == null) 133 return false; 134 if (!(obj instanceof AlignWaysSegment)) 135 return false; 136 AlignWaysSegment other = (AlignWaysSegment) obj; 137 if (segment == null) { 138 if (other.segment != null) 139 return false; 140 } else if (!segment.equals(other.segment)) 141 return false; 142 /* Segment colour is ignored in comparison 118 @Override 119 public boolean equals(Object obj) { 120 if (this == obj) 121 return true; 122 if (obj == null) 123 return false; 124 if (!(obj instanceof AlignWaysSegment)) 125 return false; 126 AlignWaysSegment other = (AlignWaysSegment) obj; 127 if (segment == null) { 128 if (other.segment != null) 129 return false; 130 } else if (!segment.equals(other.segment)) 131 return false; 132 /* Segment colour is ignored in comparison 143 133 if (segmentColor == null) { 144 134 if (other.segmentColor != null) … … 146 136 } else if (!segmentColor.equals(other.segmentColor)) 147 137 return false; 148 */149 return true;150 }138 */ 139 return true; 140 } 151 141 } -
applications/editors/josm/plugins/alignways/src/com/tilusnet/josm/plugins/alignways/AlignWaysWhatsNewPanel.java
r29854 r30345 47 47 48 48 lblWhatsNew.setText("<html><div style=\"font-family: sans-serif; font-weight: bold; font-style: italic;\"><span style=\"font-size: large;\"><span style=\"font-size: x-large;\">" 49 + tr("What''s new...")50 + "</span></div></html>");49 + tr("What''s new...") 50 + "</span></div></html>"); 51 51 52 52 icnLogo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/wndialog/alignways64.png"))); // NOI18N 53 53 54 54 newItem1.setText("<html><div style=\"font-family: sans-serif;\"><ul style=\"margin-left: 20px;\"><li>" 55 + tr("Added <b>angle preserving</b> aligning mode")56 + "</li></ul></div></html>");55 + tr("Added <b>angle preserving</b> aligning mode") 56 + "</li></ul></div></html>"); 57 57 58 58 btnHelpItem1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/wndialog/extlink10.png"))); // NOI18N … … 73 73 74 74 newItem2.setText("<html><div style=\"font-family: sans-serif;\"><ul style=\"margin-left: 20px;\"><li>" 75 + tr("Various improvements and bugfixes")76 + "</li></ul></div></html>");75 + tr("Various improvements and bugfixes") 76 + "</li></ul></div></html>"); 77 77 78 78 javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); … … 115 115 }// </editor-fold> 116 116 117 private void btnHelpItem1ActionPerformed(java.awt.event.ActionEvent evt) {118 openURI();119 }117 private void btnHelpItem1ActionPerformed(java.awt.event.ActionEvent evt) { 118 openURI(); 119 } 120 120 121 121 // Variables declaration - do not modify -
applications/editors/josm/plugins/alignways/src/com/tilusnet/josm/plugins/alignways/geometry/AlignWaysGeomLine.java
r27588 r30345 8 8 public class AlignWaysGeomLine { 9 9 10 double coef_a, coef_b, coef_c;10 double coef_a, coef_b, coef_c; 11 11 12 12 public enum IntersectionStatus { … … 76 76 77 77 public AlignWaysGeomLine(AlignWaysGeomPoint awPt1, AlignWaysGeomPoint awPt2) { 78 this(awPt1.getX(), awPt1.getY(), awPt2.getX(), awPt2.getY());79 }80 81 /**78 this(awPt1.getX(), awPt1.getY(), awPt2.getX(), awPt2.getY()); 79 } 80 81 /** 82 82 * Returns the intersection point of the line with another line. 83 83 * If the lines are parallel or overlap, returns null. … … 95 95 96 96 // See: http://www.mathwizz.com/algebra/help/help21.htm 97 // and http://en.wikipedia.org/wiki/Cramers_rule 97 // and https://en.wikipedia.org/wiki/Cramer%27s_rule 98 98 99 99 … … 184 184 } 185 185 186 public boolean isPointOnLine(AlignWaysGeomPoint awPt) {187 // Method:188 // 1. create a new line from awPt and one point of 'this'189 // 2. check getIntersectionStatus of the two lines190 // 3. if status is LINES_OVERLAP, the point os one the line, otherwise not191 192 // Need an arbitrary point on this line; let it be (x, y)193 Double x = 0.0;194 Double y = getYonLine(x);195 if (y.isNaN()) y = 0.0;196 197 AlignWaysGeomLine line2 = new AlignWaysGeomLine(awPt, new AlignWaysGeomPoint(x, y));198 getIntersection(line2);199 if (getIntersectionStatus() == IntersectionStatus.LINES_OVERLAP)200 return true;201 else202 return false;203 204 }186 public boolean isPointOnLine(AlignWaysGeomPoint awPt) { 187 // Method: 188 // 1. create a new line from awPt and one point of 'this' 189 // 2. check getIntersectionStatus of the two lines 190 // 3. if status is LINES_OVERLAP, the point os one the line, otherwise not 191 192 // Need an arbitrary point on this line; let it be (x, y) 193 Double x = 0.0; 194 Double y = getYonLine(x); 195 if (y.isNaN()) y = 0.0; 196 197 AlignWaysGeomLine line2 = new AlignWaysGeomLine(awPt, new AlignWaysGeomPoint(x, y)); 198 getIntersection(line2); 199 if (getIntersectionStatus() == IntersectionStatus.LINES_OVERLAP) 200 return true; 201 else 202 return false; 203 204 } 205 205 206 206 } -
applications/editors/josm/plugins/alignways/src/com/tilusnet/josm/plugins/alignways/geometry/AlignWaysGeomPoint.java
r27588 r30345 17 17 18 18 public AlignWaysGeomPoint(EastNorth eastNorth) { 19 this.x = eastNorth.getX();20 this.y = eastNorth.getY();21 }19 this.x = eastNorth.getX(); 20 this.y = eastNorth.getY(); 21 } 22 22 23 public double getX() {23 public double getX() { 24 24 return x; 25 25 } … … 37 37 } 38 38 39 public static boolean isSetCollinear(ArrayList<AlignWaysGeomPoint> awPts) {40 if (awPts.size() <= 1)41 return false;42 43 if (awPts.size() == 2)44 return true;45 else {46 // at least 3 points47 // First create a line of the first two points in the set48 AlignWaysGeomLine line = new AlignWaysGeomLine(awPts.get(0), awPts.get(1));49 // ...then check the subsequent points whether they are on the line50 for (int i = 2; i < awPts.size(); i++) {51 if (!line.isPointOnLine(awPts.get(i))) {52 return false;53 }54 }55 return true;56 }57 }39 public static boolean isSetCollinear(ArrayList<AlignWaysGeomPoint> awPts) { 40 if (awPts.size() <= 1) 41 return false; 42 43 if (awPts.size() == 2) 44 return true; 45 else { 46 // at least 3 points 47 // First create a line of the first two points in the set 48 AlignWaysGeomLine line = new AlignWaysGeomLine(awPts.get(0), awPts.get(1)); 49 // ...then check the subsequent points whether they are on the line 50 for (int i = 2; i < awPts.size(); i++) { 51 if (!line.isPointOnLine(awPts.get(i))) { 52 return false; 53 } 54 } 55 return true; 56 } 57 } 58 58 59 /**60 * Determines which (EastNorth) point falls between the other two.61 * Ideally to be used with collinear points.62 *63 * @return 1, 2 or 3 for pt1, pt2 and pt3, respectively.64 * 0 if middle value cannot be determined (i.e. some values are equal).65 */66 public static int getMiddleOf3(67 AlignWaysGeomPoint pt1,68 AlignWaysGeomPoint pt2,69 AlignWaysGeomPoint pt3) {70 71 int midPtXIdx = getMiddleOf3(pt1.x, pt2.x, pt3.x);72 int midPtYIdx = getMiddleOf3(pt1.y, pt2.y, pt3.y);73 74 if ((midPtXIdx == 0) && (midPtYIdx == 0))75 // All 3 points overlap:76 // Design decision: return the middle point (could be any other or none)77 return 2;78 79 if (midPtXIdx == 0) return midPtYIdx;80 if (midPtYIdx == 0) return midPtXIdx;81 82 // Both x and y middle points could be determined;83 // their indexes must coincide84 if (midPtXIdx == midPtYIdx)85 // Success86 return midPtXIdx; // (or midPtYIdx)87 else88 // Fail89 return 0;90 91 }59 /** 60 * Determines which (EastNorth) point falls between the other two. 61 * Ideally to be used with collinear points. 62 * 63 * @return 1, 2 or 3 for pt1, pt2 and pt3, respectively. 64 * 0 if middle value cannot be determined (i.e. some values are equal). 65 */ 66 public static int getMiddleOf3( 67 AlignWaysGeomPoint pt1, 68 AlignWaysGeomPoint pt2, 69 AlignWaysGeomPoint pt3) { 70 71 int midPtXIdx = getMiddleOf3(pt1.x, pt2.x, pt3.x); 72 int midPtYIdx = getMiddleOf3(pt1.y, pt2.y, pt3.y); 73 74 if ((midPtXIdx == 0) && (midPtYIdx == 0)) 75 // All 3 points overlap: 76 // Design decision: return the middle point (could be any other or none) 77 return 2; 78 79 if (midPtXIdx == 0) return midPtYIdx; 80 if (midPtYIdx == 0) return midPtXIdx; 81 82 // Both x and y middle points could be determined; 83 // their indexes must coincide 84 if (midPtXIdx == midPtYIdx) 85 // Success 86 return midPtXIdx; // (or midPtYIdx) 87 else 88 // Fail 89 return 0; 90 91 } 92 92 93 /**94 * Determine which value, d1, d2 or d3 falls in the middle of the other two.95 * @return 1, 2 or 3 for d1, d2 and d3, respectively.96 * 0 if middle value cannot be determined (i.e. some values are equal).97 */98 private static int getMiddleOf3(double d1, double d2, double d3) {99 100 Double[] dValues = {d1, d2, d3};101 ArrayList<Double> alValues = new ArrayList<Double>(Arrays.asList(dValues));102 Collections.sort(alValues);103 104 if ((Math.abs(alValues.get(1) - alValues.get(0)) < 0.01) ||105 (Math.abs(alValues.get(1) - alValues.get(2)) < 0.01))106 // Cannot determine absolute middle value107 return 0;108 else {109 if (Math.abs(alValues.get(1) - d1) < 0.01) return 1;110 if (Math.abs(alValues.get(1) - d2) < 0.01) return 2;111 if (Math.abs(alValues.get(1) - d3) < 0.01) return 3;112 }113 114 // Should never happen115 return 0;116 }93 /** 94 * Determine which value, d1, d2 or d3 falls in the middle of the other two. 95 * @return 1, 2 or 3 for d1, d2 and d3, respectively. 96 * 0 if middle value cannot be determined (i.e. some values are equal). 97 */ 98 private static int getMiddleOf3(double d1, double d2, double d3) { 99 100 Double[] dValues = {d1, d2, d3}; 101 ArrayList<Double> alValues = new ArrayList<Double>(Arrays.asList(dValues)); 102 Collections.sort(alValues); 103 104 if ((Math.abs(alValues.get(1) - alValues.get(0)) < 0.01) || 105 (Math.abs(alValues.get(1) - alValues.get(2)) < 0.01)) 106 // Cannot determine absolute middle value 107 return 0; 108 else { 109 if (Math.abs(alValues.get(1) - d1) < 0.01) return 1; 110 if (Math.abs(alValues.get(1) - d2) < 0.01) return 2; 111 if (Math.abs(alValues.get(1) - d3) < 0.01) return 3; 112 } 113 114 // Should never happen 115 return 0; 116 } 117 117 }
Note:
See TracChangeset
for help on using the changeset viewer.
