MCPcopy Create free account
hub / github.com/OpenSourcePhysics/osp / getShape

Method getShape

src/org/opensourcephysics/media/core/TVector.java:240–276  ·  view source on GitHub ↗

Gets the shape to be filled in the draw method. @param vidPanel the video panel @return the line shape

(VideoPanel vidPanel)

Source from the content-addressed store, hash-verified

238 * @return the line shape
239 */
240 @Override
241protected Shape getShape(VideoPanel vidPanel) {
242 this.center(tip, tail);
243 Point p1 = tail.getScreenPosition(vidPanel); // tail
244 Point p2 = tip.getScreenPosition(vidPanel); // tip
245 // set up transform
246 double theta = Math.atan2(p2.y-p1.y, p2.x-p1.x);
247 rotation.setToRotation(theta, p1.x, p1.y);
248 rotation.translate(p1.x, p1.y);
249 // get line length d
250 float d = (float) p1.distance(p2);
251 // set up head hit shape usng full line length
252 path.reset();
253 path.moveTo(d-4, 0);
254 path.lineTo(d-6, -2);
255 path.lineTo(d, 0);
256 path.lineTo(d-6, 2);
257 path.closePath();
258 head = rotation.createTransformedShape(path);
259 // shorten line length to account for stroke width
260 // see Java 2D API Graphics, by VJ Hardy (Sun, 2000) page 147
261 float w = stroke.getLineWidth();
262 d = d-1.58f*w;
263 // set up shaft hit shape using shortened line length
264 line.setLine(0, 0, d-length, 0);
265 shaft = rotation.createTransformedShape(line);
266 // set up and return fill shape usng shortened line length
267 path.reset();
268 path.moveTo(0, 0);
269 path.lineTo(d-length+width, 0);
270 path.lineTo(d-length, -width);
271 path.lineTo(d, 0);
272 path.lineTo(d-length, width);
273 path.lineTo(d-length+width, 0);
274 Shape vector = rotation.createTransformedShape(path);
275 return stroke.createStrokedShape(vector);
276 }
277
278 //_________________________ inner End classes _________________________
279 class LineEnd extends TPoint {

Callers

nothing calls this directly

Calls 9

centerMethod · 0.80
getScreenPositionMethod · 0.80
setToRotationMethod · 0.80
moveToMethod · 0.80
lineToMethod · 0.80
closePathMethod · 0.80
resetMethod · 0.65
getLineWidthMethod · 0.65
translateMethod · 0.45

Tested by

no test coverage detected