01: /*
02: * The Unified Mapping Platform (JUMP) is an extensible, interactive GUI
03: * for visualizing and manipulating spatial features with geometry and attributes.
04: *
05: * Copyright (C) 2003 Vivid Solutions
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU General Public License
09: * as published by the Free Software Foundation; either version 2
10: * of the License, or (at your option) any later version.
11: *
12: * This program is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: * GNU General Public License for more details.
16: *
17: * You should have received a copy of the GNU General Public License
18: * along with this program; if not, write to the Free Software
19: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20: *
21: * For more information, contact:
22: *
23: * Vivid Solutions
24: * Suite #1A
25: * 2328 Government Street
26: * Victoria BC V8T 5G5
27: * Canada
28: *
29: * (250)385-6040
30: * www.vividsolutions.com
31: */
32:
33: package com.vividsolutions.jump.plugin.edit;
34:
35: import java.util.*;
36: import java.awt.*;
37: import java.awt.event.*;
38:
39: import javax.swing.*;
40: import com.vividsolutions.jump.I18N;
41:
42: import com.vividsolutions.jts.geom.*;
43: import com.vividsolutions.jump.geom.*;
44: import com.vividsolutions.jump.util.ColorUtil;
45: import com.vividsolutions.jump.feature.*;
46: import com.vividsolutions.jump.task.*;
47: import com.vividsolutions.jump.workbench.WorkbenchContext;
48: import com.vividsolutions.jump.workbench.model.*;
49: import com.vividsolutions.jump.workbench.plugin.*;
50: import com.vividsolutions.jump.workbench.ui.*;
51:
52: /**
53: * Class used by {@link AffineTransformation} to build a transformation from a src
54: * Coordinate[2] array and a dest Coordinate[2] array.
55: *
56: * @author Martin Davis
57: */
58:
59: class TwoPointTransRotScaleBuilder extends TransRotScaleBuilder {
60:
61: /**
62: * Creates a builder from two Coordinate[2] arrays defining the src and dest vectors.
63: *
64: * @param srcVector the two Coordinates defining the src vector
65: * @param destVector the two Coordinates defining the dest vector
66: */
67: TwoPointTransRotScaleBuilder(Coordinate[] srcVector,
68: Coordinate[] destVector) {
69: super (srcVector, destVector);
70: }
71:
72: protected void compute(Coordinate[] srcVector,
73: Coordinate[] destVector) {
74: originX = srcVector[0].x;
75: originY = srcVector[0].y;
76:
77: double srcLen = srcVector[0].distance(srcVector[1]);
78: double destLen = destVector[0].distance(destVector[1]);
79:
80: boolean isZeroLength = (srcLen == 0.0 || destLen == 0.0);
81:
82: if (!isZeroLength) {
83: scaleX = destLen / srcLen;
84: scaleY = scaleX;
85:
86: double angleSrc = Angle.angle(srcVector[0], srcVector[1]);
87: double angleDest = Angle
88: .angle(destVector[0], destVector[1]);
89: double angleRad = angleDest - angleSrc;
90: angle = Math.toDegrees(angleRad);
91: }
92:
93: dx = destVector[0].x - srcVector[0].x;
94: dy = destVector[0].y - srcVector[0].y;
95: }
96:
97: }
|