MCPcopy Create free account
hub / github.com/AstroImageJ/astroimagej / moveHandle

Method moveHandle

ij/src/main/java/ij/gui/Line.java:175–350  ·  view source on GitHub ↗
(int sx, int sy)

Source from the content-addressed store, hash-verified

173 }
174
175 protected void moveHandle(int sx, int sy) {
176 if (constrain && activeHandle == 2) { // constrain translation in 90deg steps
177 int dx = sx - previousSX;
178 int dy = sy - previousSY;
179 if (Math.abs(dx) > Math.abs(dy))
180 dy = 0;
181 else
182 dx = 0;
183 sx = previousSX + dx;
184 sy = previousSY + dy;
185 }
186 double ox = offScreenXD(sx);
187 double oy = offScreenYD(sy);
188 double x1d=getXBase()+x1R, y1d=getYBase()+y1R;
189 double x2d=getXBase()+x2R, y2d=getYBase()+y2R;
190 double length = Math.sqrt(sqr(x2d-x1d) + sqr(y2d-y1d));
191 switch (activeHandle) {
192 case 0:
193 double dx = ox-x1d;
194 double dy = oy-y1d;
195 x1d=ox;
196 y1d=oy;
197 if(center){
198 x2d -= dx;
199 y2d -= dy;
200 }
201 if (aspect){
202 double ratio = length/(Math.sqrt(sqr(x2d-x1d) + sqr(y2d-y1d)));
203 double xcd = x1d+(x2d-x1d)/2;
204 double ycd = y1d+(y2d-y1d)/2;
205
206 if(center){
207 x1d=xcd-ratio*(xcd-x1d);
208 x2d=xcd+ratio*(x2d-xcd);
209 y1d=ycd-ratio*(ycd-y1d);
210 y2d=ycd+ratio*(y2d-ycd);
211 } else {
212 x1d=x2d-ratio*(x2d-x1d);
213 y1d=y2d-ratio*(y2d-y1d);
214 }
215
216 }
217 break;
218 case 1:
219 dx = ox-x2d;
220 dy = oy-y2d;
221 x2d=ox;
222 y2d=oy;
223 if(center){
224 x1d -= dx;
225 y1d -= dy;
226 }
227 if(aspect){
228 double ratio = length/(Math.sqrt((x2d-x1d)*(x2d-x1d) + (y2d-y1d)*(y2d-y1d)));
229 double xcd = x1d+(x2d-x1d)/2;
230 double ycd = y1d+(y2d-y1d)/2;
231
232 if(center){

Callers

nothing calls this directly

Calls 13

updateCoordinatesMethod · 0.95
getXBaseMethod · 0.80
getYBaseMethod · 0.80
updateClipRectMethod · 0.80
absMethod · 0.45
offScreenXDMethod · 0.45
offScreenYDMethod · 0.45
sqrtMethod · 0.45
sqrMethod · 0.45
minMethod · 0.45
roundMethod · 0.45

Tested by

no test coverage detected