Inheritance diagram for CanvasLine::
Public Methods | |
CanvasLine (double x1, double y1, double x2, double y2) | |
CanvasLine (double x1, double y1, double x2, double y2, Color color) | |
CanvasLine (double x1, double y1, double x2, double y2, int mode, Color color, boolean stroke, float linew, float trans, double ccs_scale) | |
void | draw (Graphics g) |
Draw CanvasObject on 'g', using internal CCS values. More... | |
Object | clone () |
Return an identical copy of this CanvasObject. More... | |
boolean | isInside (double x, double y) |
boolean | isNear (double x, double y) |
void | setDimension (double w, double h) |
Resize CanvasObject to width 'w' and height 'h'. More... | |
void | doPixelFit (double zoomFactor) |
Round internal ICS values to nearest natural number. More... | |
void | doMove (double w, double h) |
Move CanvasObject 'w' positions in x-direction, and 'h' posi- tions in y-direction. More... | |
CanvasLine (int x1, int y1, int x2, int y2, int mode, Color color, double ccs_scale) | |
boolean | isInsideCcs (int x, int y) |
To be removed. More... | |
boolean | isNearCcs (int x, int y) |
To be removed. More... | |
void | setDimension (int w, int h) |
void | doMove (int w, int h) |
int | changePoint (int index, int x, int y) |
Point | getStart () |
Point | getEnd () |
Protected Methods | |
void | initLine (double x1, double y1, double x2, double y2) |
void | transformICStoCCS () |
Perform a full ICS to CCS coordinate transformation. More... | |
void | transformCCStoICS () |
Perform a full CCS to ICS coordinate transformation. More... | |
Protected Attributes | |
double | ics_endX |
double | ics_endY |
int | ccs_endX |
int | ccs_endY |
|
|
|
|
|
00047 { 00048 super(Math.min(x1,x2), Math.min(y1,y2), 00049 Math.abs(x1-x2), Math.abs(y1-y2), 00050 mode, color, stroke, linew, trans, ccs_scale); 00051 initLine(x1, y1, x2, y2); 00052 } |
|
00184 { 00185 super(Math.min(x1,x2), Math.min(y1,y2), 00186 Math.abs(x1-x2), Math.abs(y1-y2), mode, color, ccs_scale); 00187 00188 int[] ccs_vals = { x1, y1, x2, y2 }; 00189 double[] ics_vals = Converter.CCStoICS(ccs_vals, ccs_scale); 00190 00191 initLine(ics_vals[0], ics_vals[1], ics_vals[2], ics_vals[3]); 00192 } |
|
Draw CanvasObject on 'g', using internal CCS values.
Reimplemented from CanvasObject.
00059 { 00060 setupDrawMode(g); 00061 if (!getTransformOK()) { 00062 transformICStoCCS(); 00063 } 00064 g.drawLine(getStartXCcs(), getStartYCcs(), ccs_endX, ccs_endY); 00065 } |
|
Return an identical copy of this CanvasObject.
Reimplemented from CanvasObject.
00069 { 00070 Color color = drawColor; 00071 if (hasNoColor) { 00072 color = NO_COLOR; 00073 } 00074 return (new CanvasLine(getStartX(), getStartY(), ics_endX, 00075 ics_endY, getDrawMode(), color, strokeSet, 00076 lineWidth, transparency, getZoomFactor())); 00077 } |
|
00081 { 00082 return false; 00083 } |
|
00087 { 00088 // taken from 'Graphics Gems II' - James Arvo, 00089 // chap. 1.3, 'Distance from a point to a line', pages 10-13. 00090 00091 00092 // check if inside enlarged bounding box (== box + SPHERE) 00093 00094 if ((x >= getX1() - SPHERE) && (x < getX1() + getWidth() + SPHERE) && 00095 (y >= getY1() - SPHERE) && (y < getY1() + getHeight() + SPHERE)) { 00096 00097 00098 // calculate the area of the triangle formed by the two 00099 // CanvasLine points and the 'check' point 00100 00101 double area = (y - getStartY())*(ics_endX - getStartX()) - 00102 (x - getStartX())*(ics_endY - getStartY()); 00103 00104 00105 // calculate approximation of distance perpendicular to 00106 // CanvasLine 00107 00108 double abs1 = Math.abs(ics_endX - getStartX()); 00109 double abs2 = Math.abs(ics_endY - getStartY()); 00110 00111 double distance = (int)(Math.abs(area) / 00112 (abs1+abs2 - 0.5*Math.min(abs1, abs2))); 00113 00114 00115 // this approximation can also be used as an approximation 00116 // for the 'true' distance 00117 00118 if (distance <= SPHERE) { 00119 return true; 00120 } 00121 } 00122 return false; 00123 } |
|
Resize CanvasObject to width 'w' and height 'h'. Parameters are assumed Image Coordinate System values. Reimplemented from ScribbleObject.
00127 { 00128 super.setDimension(w, h); 00129 00130 if (getStartX() == getX1()) { 00131 ics_endX = getX1() + getWidth(); 00132 } else { 00133 ics_endX = getX1(); 00134 } 00135 00136 if (getStartY() == getY1()) { 00137 ics_endY = getY1() + getHeight(); 00138 } else { 00139 ics_endY = getY1(); 00140 } 00141 00142 setTransformOK(false); 00143 } |
|
Round internal ICS values to nearest natural number. Although the ICS values are changed, they are not converted to 'integer' internally. Reimplemented from ScribbleObject.
00147 { 00148 super.doPixelFit(zoomFactor); 00149 00150 ics_endX = Math.round(ics_endX); 00151 ics_endY = Math.round(ics_endY); 00152 00153 setTransformOK(false); 00154 } |
|
Move CanvasObject 'w' positions in x-direction, and 'h' posi- tions in y-direction. Parameters are assumed Image Coordinate System values. Reimplemented from ScribbleObject.
00158 { 00159 super.doMove(w, h); 00160 00161 ics_endX += w; 00162 ics_endY += h; 00163 00164 setTransformOK(false); 00165 } |
|
To be removed.
Reimplemented from CanvasObject.
00196 { 00197 return false; 00198 } |
|
To be removed.
Reimplemented from CanvasObject.
00202 { 00203 if (!getTransformOK()) { 00204 transformICStoCCS(); 00205 } 00206 00207 // taken from 'Graphics Gems II' - James Arvo, 00208 // chap. 1.3, 'Distance from a point to a line', pages 10-13. 00209 00210 00211 // check if inside enlarged bounding box (== box + SPHERE) 00212 00213 if ((x >= getX1Ccs() - SPHERE) && (x < getX1Ccs() + getWidthCcs() + SPHERE) && 00214 (y >= getY1Ccs() - SPHERE) && (y < getY1Ccs() + getHeightCcs() + SPHERE)) { 00215 00216 00217 // calculate the area of the triangle formed by the two 00218 // CanvasLine points and the 'check' point 00219 00220 int area = (y - getStartYCcs())*(ccs_endX - getStartXCcs()) - 00221 (x - getStartXCcs())*(ccs_endY - getStartYCcs()); 00222 00223 00224 // calculate approximation of distance perpendicular to 00225 // CanvasLine 00226 00227 int abs1 = Math.abs(ccs_endX - getStartXCcs()); 00228 int abs2 = Math.abs(ccs_endY - getStartYCcs()); 00229 00230 int distance = (int)(Math.abs(area) / 00231 (abs1 + abs2 - 0.5 * Math.min(abs1, abs2))); 00232 00233 00234 // this approximation can also be used as an approximation 00235 // for the 'true' distance 00236 00237 if (distance <= SPHERE) { 00238 return true; 00239 } 00240 } 00241 return false; 00242 } |
|
Reimplemented from ScribbleObject.
00246 { 00247 super.setDimension(w, h); 00248 00249 if (getStartXCcs() == getX1Ccs()) { 00250 ccs_endX = getX1Ccs() + getWidthCcs(); 00251 } else { 00252 ccs_endX = getX1Ccs(); 00253 } 00254 00255 if (getStartYCcs() == getY1Ccs()) { 00256 ccs_endY = getY1Ccs() + getHeightCcs(); 00257 } else { 00258 ccs_endY = getY1Ccs(); 00259 } 00260 00261 transformCCStoICS(); 00262 } |
|
Reimplemented from ScribbleObject.
00266 { 00267 super.doMove(w, h); 00268 00269 ccs_endX += w; 00270 ccs_endY += h; 00271 00272 transformCCStoICS(); 00273 } |
|
Reimplemented from ScribbleFigure.
00277 { 00278 if (!getTransformOK()) { 00279 transformICStoCCS(); 00280 } 00281 00282 if (index == 0) { 00283 setStartXCcs(ccs_endX); 00284 setStartYCcs(ccs_endY); 00285 } else if (index != 1) { 00286 return -1; 00287 } 00288 00289 setDimension(x - getStartXCcs(), y - getStartYCcs()); 00290 return 1; 00291 } |
|
00295 { 00296 if (!getTransformOK()) { 00297 transformICStoCCS(); 00298 } 00299 return new Point(getStartXCcs(), getStartYCcs()); 00300 } |
|
00304 { 00305 if (!getTransformOK()) { 00306 transformICStoCCS(); 00307 } 00308 return new Point(ccs_endX, ccs_endY); 00309 } |
|
00323 { 00324 setStartX(x1); 00325 setStartY(y1); 00326 ics_endX = x2; 00327 ics_endY = y2; 00328 00329 transformICStoCCS(); 00330 } |
|
Perform a full ICS to CCS coordinate transformation.
Reimplemented from CanvasObject.
00334 { 00335 double[] ics_vals = { getX1(), getY1(), getWidth() + getX1(), 00336 getHeight() + getY1(), getStartX(), 00337 getStartY(), ics_endX, ics_endY }; 00338 int[] ccs_vals = Converter.ICStoCCS(ics_vals, getZoomFactor()); 00339 00340 setX1Ccs(ccs_vals[0]); 00341 setY1Ccs(ccs_vals[1]); 00342 setWidthCcs(ccs_vals[2] - getX1Ccs()); 00343 setHeightCcs(ccs_vals[3] - getY1Ccs()); 00344 setStartXCcs(ccs_vals[4]); 00345 setStartYCcs(ccs_vals[5]); 00346 ccs_endX = ccs_vals[6]; 00347 ccs_endY = ccs_vals[7]; 00348 00349 setTransformOK(true); 00350 } |
|
Perform a full CCS to ICS coordinate transformation. This function is used only for scribbled objects. Reimplemented from CanvasObject.
00354 { 00355 int[] ccs_vals = { getX1Ccs(), getY1Ccs(), getWidthCcs() + getX1Ccs(), 00356 getHeightCcs() + getY1Ccs(), getStartXCcs(), 00357 getStartYCcs(), ccs_endX, ccs_endY }; 00358 double[] ics_vals = Converter.CCStoICS(ccs_vals, getZoomFactor()); 00359 00360 setX1(ics_vals[0]); 00361 setY1(ics_vals[1]); 00362 setWidth(ics_vals[2] - getX1()); 00363 setHeight(ics_vals[3] - getY1()); 00364 setStartX(ics_vals[4]); 00365 setStartY(ics_vals[5]); 00366 ics_endX = ics_vals[6]; 00367 ics_endY = ics_vals[7]; 00368 } |
|
|
|
|
|
|
|
|