private void adjustDateLineCrossingPoints() { ArrayList<LatLon> corners = new ArrayList<LatLon>(Arrays.asList(sw, se, nw, ne)); if (!LatLon.locationsCrossDateLine(corners)) return; double lonSign = 0; for (LatLon corner : corners) { if (Math.abs(corner.getLongitude().degrees) != 180) lonSign = Math.signum(corner.getLongitude().degrees); } if (lonSign == 0) return; if (Math.abs(sw.getLongitude().degrees) == 180 && Math.signum(sw.getLongitude().degrees) != lonSign) sw = new Position(sw.getLatitude(), sw.getLongitude().multiply(-1), sw.getElevation()); if (Math.abs(se.getLongitude().degrees) == 180 && Math.signum(se.getLongitude().degrees) != lonSign) se = new Position(se.getLatitude(), se.getLongitude().multiply(-1), se.getElevation()); if (Math.abs(nw.getLongitude().degrees) == 180 && Math.signum(nw.getLongitude().degrees) != lonSign) nw = new Position(nw.getLatitude(), nw.getLongitude().multiply(-1), nw.getElevation()); if (Math.abs(ne.getLongitude().degrees) == 180 && Math.signum(ne.getLongitude().degrees) != lonSign) ne = new Position(ne.getLatitude(), ne.getLongitude().multiply(-1), ne.getElevation()); }
private void doCurrentMethodStep() { switch (type) { case 0: // bisectiei if (Math.abs(function.evaluate((Cn.lastElement()).x)) < err) { complete = true; theTimer.stop(); } else if (function.evaluate((An.lastElement()).x) * function.evaluate((Cn.lastElement()).x) < 0) { Bn.add(Cn.lastElement()); Cn.add(new PointDP(((An.lastElement()).x + (Bn.lastElement()).x) / 2, 0.0)); } else { An.add(Cn.lastElement()); Cn.add(new PointDP(((An.lastElement()).x + (Bn.lastElement()).x) / 2, 0.0)); } break; case 1: // coardei { double evn = function.evaluate((An.lastElement()).x); if (Math.abs(evn) < err) { complete = true; theTimer.stop(); } else { double ev0 = function.evaluate((An.firstElement()).x); double newVal = (An.firstElement().x * evn - An.lastElement().x * ev0) / (evn - ev0); An.add(new PointDP(newVal, 0.0)); } } break; case 2: // secantei { double exn = function.evaluate((An.lastElement()).x); if (Math.abs(exn) < err) { complete = true; theTimer.stop(); } else { double exn1 = function.evaluate((An.elementAt(An.size() - 2)).x); double newVal = (An.elementAt(An.size() - 2).x * exn - (An.lastElement()).x * exn1) / (exn - exn1); An.add(new PointDP(newVal, 0.0)); } } break; case 3: // newton double xn = An.lastElement().x; if (Math.abs(function.evaluate(xn)) < err) { complete = true; theTimer.stop(); } An.add(new PointDP(xn - function.evaluate(xn) / function.evaluate_1(xn), 0.0)); break; } }
public Point getEmptyPosition(Dimension spriteSize) { Rectangle trialSpaceOccupied = new Rectangle(0, 0, spriteSize.width, spriteSize.height); Random rand = new Random(System.currentTimeMillis()); boolean empty = false; int numTries = 0; // Search for an empty position while (!empty && numTries++ < 100) { // Get a trial position trialSpaceOccupied.x = Math.abs(rand.nextInt() % backgroundImage.getSize().width); trialSpaceOccupied.y = Math.abs(rand.nextInt() % backgroundImage.getSize().height); // Iterate through existing // sprites, checking if position // is empty boolean collision = false; for (int cnt = 0; cnt < size(); cnt++) { Rectangle testSpaceOccupied = ((Sprite) elementAt(cnt)).getSpaceOccupied(); if (trialSpaceOccupied.intersects(testSpaceOccupied)) { collision = true; } // end if } // end for loop empty = !collision; } // end while loop return new Point(trialSpaceOccupied.x, trialSpaceOccupied.y); } // end getEmptyPosition()
/** * Draw method * * @param g2 Graphics element * @param select Selected node */ public void draw(Graphics2D g2, boolean select) { Point pinit = new Point(centre.x - 25, centre.y - 25); Point pfin = new Point(centre.x + 25, centre.y + 25); figure = new RoundRectangle2D.Float( pinit.x, pinit.y, Math.abs(pfin.x - pinit.x), Math.abs(pfin.y - pinit.y), 20, 20); g2.setColor(Color.black); if (select) { Stroke s = g2.getStroke(); g2.setStroke( new BasicStroke( 5, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[] {1, 1}, 0)); g2.draw(figure); g2.setStroke(s); } else { g2.draw(figure); } g2.drawImage(image, centre.x - 25, centre.y - 25, 50, 50, pd); g2.setFont(new Font("Courier", Font.BOLD + Font.ITALIC, 12)); FontMetrics metrics = g2.getFontMetrics(); int width = metrics.stringWidth(dsc.getName()); int height = metrics.getHeight(); g2.drawString(dsc.getName(), centre.x - width / 2, centre.y + 40); }
private void draw_horizon(int rad, Point center, int[] angles) { // Draw an arc int arc_angle = ((angles[0] > angles[1]) ? (360 - angles[0]) + angles[1] : (angles[1] - angles[0])); Polygon remainder = new Polygon(); offgraphics_.setColor(GREEN); offgraphics_.fillArc(center.x - rad, center.y - rad, 2 * rad, 2 * rad, angles[0], arc_angle); if (pitch_ != 0) { if ((pitch_ > 0 && Math.abs(roll_) < 90) || (pitch_ < 0 && Math.abs(roll_) >= 90)) offgraphics_.setColor(BLUE); int cover_angle = (angles[0] + arc_angle / 2 + ((arc_angle < 180) ? 180 : 0)) % 360; // System.out.println (points[0] + " " + points[1]); // System.out.println (accepted_point); remainder.addPoint( center.x + polar_to_rect_x(rad, cover_angle), center.y - polar_to_rect_y(rad, cover_angle)); remainder.addPoint( center.x + polar_to_rect_x(rad, angles[0]), center.y - polar_to_rect_y(rad, angles[0])); remainder.addPoint( center.x + polar_to_rect_x(rad, angles[1]), center.y - polar_to_rect_y(rad, angles[1])); offgraphics_.fillPolygon(remainder); // offgraphics_.setColor (getBackground ()); // offgraphics_.drawPolygon (remainder); } }
/** Returns the supported cursor size */ static Dimension getBestCursorSize(int preferredWidth, int preferredHeight) { // Fix for bug 4212593 The Toolkit.createCustomCursor does not // check absence of the image of cursor // We use XQueryBestCursor which accepts unsigned ints to obtain // the largest cursor size that could be dislpayed // Dimension d = new Dimension(Math.abs(preferredWidth), Math.abs(preferredHeight)); Dimension d; XToolkit.awtLock(); try { long display = XToolkit.getDisplay(); long root_window = XlibWrapper.RootWindow(display, XlibWrapper.DefaultScreen(display)); XlibWrapper.XQueryBestCursor( display, root_window, Math.abs(preferredWidth), Math.abs(preferredHeight), XlibWrapper.larg1, XlibWrapper.larg2); d = new Dimension( XlibWrapper.unsafe.getInt(XlibWrapper.larg1), XlibWrapper.unsafe.getInt(XlibWrapper.larg2)); } finally { XToolkit.awtUnlock(); } return d; }
public void draw(Graphics g) { Graphics2D g2d = (Graphics2D) g; g2d.setPaint(this.getPaint()); int width = Math.abs(this.getX1() - this.getX2()); int height = Math.abs(this.getY1() - this.getY2()); int smallX = this.getX1() < this.getX2() ? this.getX1() : this.getX2(); int smallY = this.getY1() < this.getY2() ? this.getY1() : this.getY2(); Stroke myStroke; if (this.isDashed()) { myStroke = new BasicStroke( this.getWidth(), BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL, 10, this.getDashWidth(), 0); } else { myStroke = new BasicStroke(this.getWidth(), BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL); } g2d.setStroke(myStroke); if (this.isFilled()) { g2d.fillOval(smallX, smallY, width, height); } else { g2d.drawOval(smallX, smallY, width, height); } }
/** * Writes the <code>shape</code>, <code>coords</code>, <code>href</code>, * <code>nohref</code> Attribute for the specified figure and ellipse. * * @return Returns true, if the circle is inside of the image bounds. */ private boolean writeCircleAttributes(IXMLElement elem, SVGFigure f, Ellipse2D.Double ellipse) { AffineTransform t = TRANSFORM.getClone(f); if (t == null) { t = drawingTransform; } else { t.preConcatenate(drawingTransform); } if ((t.getType() & (AffineTransform.TYPE_UNIFORM_SCALE | AffineTransform.TYPE_TRANSLATION)) == t.getType() && ellipse.width == ellipse.height ) { Point2D.Double start = new Point2D.Double(ellipse.x, ellipse.y); Point2D.Double end = new Point2D.Double(ellipse.x + ellipse.width, ellipse.y + ellipse.height); t.transform(start, start); t.transform(end, end); ellipse.x = Math.min(start.x, end.x); ellipse.y = Math.min(start.y, end.y); ellipse.width = Math.abs(start.x - end.x); ellipse.height = Math.abs(start.y - end.y); elem.setAttribute("shape", "circle"); elem.setAttribute("coords", (int) (ellipse.x + ellipse.width / 2d)+","+ (int) (ellipse.y + ellipse.height / 2d)+","+ (int) (ellipse.width / 2d) ); writeHrefAttribute(elem, f); return bounds.intersects(ellipse.getBounds()); } else { return writePolyAttributes(elem, f, (Shape) ellipse); } }
private boolean isSignificantMouseMove() { if (zoomBoxEnd == null) return false; if (Math.abs(zoomBoxStart.x - zoomBoxEnd.x) < MIN_MOVEMENT) return false; if (Math.abs(zoomBoxStart.y - zoomBoxEnd.y) < MIN_MOVEMENT) return false; return true; }
/** * Translate a point in the direction specified by an angle. * * @param apt Point2D * @param alpha double * @param dist double * @return Point2D */ public static Point2D translateByAngle(Point2D apt, double alpha, double dist) { double dx = dist * Math.cos(alpha); double dy = dist * Math.sin(alpha); if (Math.abs(dx) < 0.000000001) dx = 0; if (Math.abs(dy) < 0.000000001) dy = 0; return new Point2D.Double(apt.getX() + dx, apt.getY() + dy); }
/** * Tegner raketten. * * @param g tegneflaten */ public void draw(Graphics2D g) { int whichImage = 9; int adx = Math.abs((int) _xSpeed); int ady = Math.abs((int) _ySpeed); if ((_xSpeed < 0) && (adx > 2 * ady)) { // W whichImage = 0 + _age % 2; } else if ((_ySpeed < 0) && (ady > 2 * adx)) { // N whichImage = 4 + _age % 2; } else if ((_xSpeed > 0) && (adx > 2 * ady)) { // E whichImage = 8 + _age % 2; } else if ((_ySpeed > 0) && (ady > 2 * adx)) { // S whichImage = 12 + _age % 2; } else if ((_xSpeed < 0) && (_ySpeed < 0)) { // NW whichImage = 2 + _age % 2; } else if ((_ySpeed < 0) && (_xSpeed > 0)) { // NE whichImage = 6 + _age % 2; } else if ((_ySpeed > 0) && (_xSpeed > 0)) { // SE whichImage = 10 + _age % 2; } else if ((_xSpeed < 0) && (_ySpeed > 0)) { // SW whichImage = 14 + _age % 2; } g.drawImage(_movie[whichImage], x, y, null); }
void MidpointLine(int x0, int y0, int x1, int y1, Graphics g) { if (x0 == x1) { for (int i = Math.min(y1, y0); i <= Math.max(y1, y0); i++) { WritePixel(x0, i, 10, g); } } else if (y0 == y1) { for (int i = Math.min(x1, x0); i <= Math.max(x1, x0); i++) { WritePixel(i, y0, 10, g); } } else { int dx = Math.abs(x1 - x0); int dy = Math.abs(y1 - y0); int d = dx - dy; int sx, sy, d2; if (x0 < x1) sx = 1; else sx = -1; if (y0 < y1) sy = 1; else sy = -1; do { WritePixel(x0, y0, 10, g); d2 = d * 2; if (d2 > -dy) { x0 += sx; d -= dy; } if (d2 < dx) { d += dx; y0 += sy; } } while (x0 != x1 && y0 != y1); } }
public void renderBox(GL gl) { gl.glDisable(GL_TEXTURE_2D); int c1 = Math.abs(this.hashCode()) % 256; int c2 = Math.abs(getImage().hashCode()) % 256; gl.glColor4f(c1 / 256f, c2 / 256f, ((c1 + c2) * 34) % 256 / 256f, 0.3f); gl.glPushMatrix(); gl.glTranslatef(bounds.getLeft(), bounds.getTop(), minHeight); gl.glScalef(bounds.getWidth(), bounds.getHeight(), maxHeight - minHeight); gl.glBegin(GL_QUADS); gl.glVertex3f(0, 0, 0); gl.glVertex3f(0, 1, 0); gl.glVertex3f(1, 1, 0); gl.glVertex3f(1, 0, 0); gl.glVertex3f(0, 0, 1); gl.glVertex3f(0, 1, 1); gl.glVertex3f(1, 1, 1); gl.glVertex3f(1, 0, 1); gl.glEnd(); gl.glColor4f(1, 1, 0, 0.2f); gl.glBegin(GL_QUAD_STRIP); gl.glVertex3f(0, 0, 0); gl.glVertex3f(0, 0, 1); gl.glVertex3f(0, 1, 0); gl.glVertex3f(0, 1, 1); gl.glVertex3f(1, 1, 0); gl.glVertex3f(1, 1, 1); gl.glVertex3f(1, 0, 0); gl.glVertex3f(1, 0, 1); gl.glVertex3f(0, 0, 0); gl.glVertex3f(0, 0, 1); gl.glEnd(); gl.glPopMatrix(); }
public Dimension getDocumentSize() { float pageViewWidth = 0; float pageViewHeight = 0; if (pagesPanel != null) { int currCompIndex = documentViewController.getCurrentPageIndex(); int numComponents = pagesPanel.getComponentCount(); if (currCompIndex >= 0 && currCompIndex < numComponents) { Component comp = pagesPanel.getComponent(currCompIndex); if (comp instanceof PageViewDecorator) { PageViewDecorator pvd = (PageViewDecorator) comp; Dimension dim = pvd.getPreferredSize(); pageViewWidth = dim.width; pageViewHeight = dim.height; } } } // normalize the dimensions to a zoom level of zero. float currentZoom = documentViewModel.getViewZoom(); pageViewWidth = Math.abs(pageViewWidth / currentZoom); pageViewHeight = Math.abs(pageViewHeight / currentZoom); // add any horizontal padding from layout manager pageViewWidth += AbstractDocumentView.horizontalSpace * 2; pageViewHeight += AbstractDocumentView.verticalSpace * 2; return new Dimension((int) pageViewWidth, (int) pageViewHeight); }
public boolean containsPoint(int x, int y) { int l = Math.min(getStart().x, getEnd().x); int t = Math.min(getStart().y, getEnd().y); int w = Math.abs(getWidth()); int h = Math.abs(getHeight()); if (x >= l && x < l + w && y >= t && y < t + h) return true; else return false; }
public void paint(Graphics g) { g.setColor(Color.black); super.paint(g); int h = Math.abs(y1 - y2) - 1, w = Math.abs(x1 - x2) - 1; // int x0=x1>x2?x2:x1, y0=y1>y2?y2:y1; int x0 = 0, y0 = 0; g.drawRect(x0, y0, w, h); }
private void pitch_horizon(int rad, int[] angles) { boolean upside_down = Math.abs(roll_) >= 90; int angle_shift = (int) Math.round((double) (90 - (Math.abs(roll_) % 180)) / 90.0 * pitch_); // System.out.println ("angle_shift " + angle_shift); angles[0] += angle_shift; angles[1] -= angle_shift; }
public void update_display(int lat, int lon, int alt, int heading) { String lat_str = Math.abs(lat) + "" + DEGREE + ((lat > 0) ? " N" : " S"); String long_str = Math.abs(lon) + "" + DEGREE + ((lon > 0) ? " E" : " W"); lat_.setText(lat_str); long_.setText(long_str); alt_.setText(alt + " Kft"); heading_.setText(heading + "" + DEGREE + " "); }
void handleMouseMove(int sx, int sy) { // Do rubber banding int tool = Toolbar.getToolId(); if (!(tool == Toolbar.POLYGON || tool == Toolbar.POLYLINE || tool == Toolbar.ANGLE)) { imp.deleteRoi(); imp.draw(); return; } drawRubberBand(sx, sy); degrees = Double.NaN; double len = -1; if (nPoints > 1) { double x1, y1, x2, y2; if (xpf != null) { x1 = xpf[nPoints - 2]; y1 = ypf[nPoints - 2]; x2 = xpf[nPoints - 1]; y2 = ypf[nPoints - 1]; } else { x1 = xp[nPoints - 2]; y1 = yp[nPoints - 2]; x2 = xp[nPoints - 1]; y2 = yp[nPoints - 1]; } degrees = getAngle( (int) Math.round(x1), (int) Math.round(y1), (int) Math.round(x2), (int) Math.round(y2)); if (tool != Toolbar.ANGLE) { Calibration cal = imp.getCalibration(); double pw = cal.pixelWidth, ph = cal.pixelHeight; if (IJ.altKeyDown()) { pw = 1.0; ph = 1.0; } len = Math.sqrt((x2 - x1) * pw * (x2 - x1) * pw + (y2 - y1) * ph * (y2 - y1) * ph); } } if (tool == Toolbar.ANGLE) { if (nPoints == 2) angle1 = degrees; else if (nPoints == 3) { double angle2 = getAngle(xp[1], yp[1], xp[2], yp[2]); degrees = Math.abs(180 - Math.abs(angle1 - angle2)); if (degrees > 180.0) degrees = 360.0 - degrees; } } String length = len != -1 ? ", length=" + IJ.d2s(len) : ""; double degrees2 = tool == Toolbar.ANGLE && nPoints == 3 && Prefs.reflexAngle ? 360.0 - degrees : degrees; String angle = !Double.isNaN(degrees) ? ", angle=" + IJ.d2s(degrees2) : ""; int ox = ic != null ? ic.offScreenX(sx) : sx; int oy = ic != null ? ic.offScreenY(sy) : sy; IJ.showStatus(imp.getLocationAsString(ox, oy) + length + angle); }
public void paint(Graphics g) { System.out.println("paint"); Graphics2D g2d = (Graphics2D) g; Point1 p1, p2; n = paintInfo.size(); if (toolFlag == 2) g2d.clearRect(0, 0, getSize().width - 100, getSize().height - 100); // 清除 for (int i = 0; i < n - 1; i++) { p1 = (Point1) paintInfo.elementAt(i); p2 = (Point1) paintInfo.elementAt(i + 1); size = new BasicStroke(p1.boarder, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL); g2d.setColor(p1.col); g2d.setStroke(size); if (p1.tool == p2.tool) { switch (p1.tool) { case 0: // 画笔 Line2D line1 = new Line2D.Double(p1.x, p1.y, p2.x, p2.y); g2d.draw(line1); break; case 1: // 橡皮 g.clearRect(p1.x, p1.y, p1.boarder, p1.boarder); break; case 3: // 画直线 Line2D line2 = new Line2D.Double(p1.x, p1.y, p2.x, p2.y); g2d.draw(line2); break; case 4: // 画圆 Ellipse2D ellipse = new Ellipse2D.Double(p1.x, p1.y, Math.abs(p2.x - p1.x), Math.abs(p2.y - p1.y)); g2d.draw(ellipse); break; case 5: // 画矩形 Rectangle2D rect = new Rectangle2D.Double(p1.x, p1.y, Math.abs(p2.x - p1.x), Math.abs(p2.y - p1.y)); g2d.draw(rect); break; case 6: // 截断,跳过 i = i + 1; break; default: } // end switch } // end if } // end for }
public void setXY(double x, double y) { // not validated // x and y between -1 and 1 double sigmoidSteepness, sigmoidZero, baseLength; double sensitivity = 1.1; // evaluated with set to 1.1: a sensitivity of 1 means the complete space of the button // is used. 2 means only the middle part is used, making it more sensitive and more // easy to get to extreme arousal (from a CHI perspective). if (!down) { p = x * sensitivity; d = y * sensitivity; baseLength = Math.max(Math.abs(p), Math.abs(d)); // MAX (P, D) base // baseLength=Math.sqrt(Math.pow(p,2)+Math.pow(d,2))/Math.sqrt(2.0); //euclid P,D base // now do the mapping to arousal. // Arousal is controlled simple by using a Sigmoid function based on length of PD vector sigmoidSteepness = 11; sigmoidZero = 8; a = 2 / (1 + Math.exp(-(sigmoidSteepness * baseLength - sigmoidZero))) - 1; a_base = a; // Arousal is controlled simply by using a quadratic function that has 0,0,0 as middle point, // then drops to -1, then to 1 based MIN (P,D) length (mimics better original linear) // sigmoidSteepness=6; // sigmoidZero=0.35; // a=sigmoidSteepness*Math.pow(Math.max(Math.abs(p),Math.abs(d))-sigmoidZero, 2)-1; p = (p > 1 ? 1 : (p < -1 ? -1 : p)); d = (d > 1 ? 1 : (d < -1 ? -1 : d)); a = (a > 1 ? 1 : (a < -1 ? -1 : a)); } else { double tmp_p, tmp_d; tmp_p = x * sensitivity; tmp_d = y * sensitivity; baseLength = Math.max(Math.abs(tmp_p), Math.abs(tmp_d)); // MAX (P, D) base // baseLength=Math.sqrt(Math.pow(p,2)+Math.pow(d,2))/Math.sqrt(2.0); //euclid P,D base // now do the mapping to arousal. // Arousal is controlled simple by using a Sigmoid function based on length of PD vector sigmoidSteepness = 11; sigmoidZero = 8; // a=a_base-(d-tmp_d)+2/(1+Math.exp(-(sigmoidSteepness*baseLength-sigmoidZero)))-1; a = tmp_d; // Arousal is controlled simply by using a quadratic function that has 0,0,0 as middle point, // then drops to -1, then to 1 based MIN (P,D) length (mimics better original linear) // sigmoidSteepness=6; // sigmoidZero=0.35; // a=sigmoidSteepness*Math.pow(Math.max(Math.abs(p),Math.abs(d))-sigmoidZero, 2)-1; // p=(p>1?1:(p<-1?-1:p)); // d=(d>1?1:(d<-1?-1:d)); a = (a > 1 ? 1 : (a < -1 ? -1 : a)); } }
public boolean ManipBoxPattern(int xMin, int yMin, int xMax, int yMax, double amount) { int x; int y; y = yMin; while (y < yMax) { x = xMin; while (x < xMax) { Pixel p = this.getPixel(x, y); int yOffset = Math.abs(yMin - y); int xOffset = Math.abs(xMin - x); double ra = normal(x, xMin, xMax); if (ra >= 1.0) { int R = (int) (p.getRed() * amount); int G = (int) (p.getGreen() * amount); int B = (int) (255 * amount); p.setRed(R); p.setGreen(G); p.setBlue(B); p.getColor().brighter(); } else { int R = (int) (p.getRed() * amount); int G = (int) (255 * amount); int B = (int) (p.getBlue() * amount); p.setRed(R); p.setGreen(G); p.setBlue(B); } if (x % 2 == 0) { int R = (int) (255 * amount); int G = (int) (p.getGreen() * amount); int B = (int) (p.getBlue() * amount); p.setRed(R); p.setGreen(G); p.setBlue(B); } x = x + 1; } y = y + 1; } return true; }
private void squareGradient(int[] pixels, int y, int w, int h) { int off = 0; float radius = Math.max(Math.abs(p2.x - p1.x), Math.abs(p2.y - p1.y)); for (int x = 0; x < w; x++) { float distance = Math.max(Math.abs(x - p1.x), Math.abs(y - p1.y)); float ratio = distance / radius; if (repeat) ratio = ratio % 2; else if (ratio > 1.0) ratio = 1.0f; int rgb = colormap.getColor(map(ratio)); pixels[off] = PixelUtils.combinePixels(rgb, pixels[off], paintMode); off++; } }
private Line addLine(Point p1, Point p2) { if (Math.abs(p1.getX() - p2.getX()) < 5 || Math.abs(p1.getY() - p2.getY()) < 5) { return null; } Line line = null; if (p1 != null && p2 != null) { line = new Line(p1, p2); canvas.add(line); } repaint(); return line; }
public void mouseDrag(MouseEvent e, int x, int y) { super.mouseDrag(e, x, y); fMoved = (Math.abs(x - fAnchorX) > 4) || (Math.abs(y - fAnchorY) > 4); if (fMoved) { FigureEnumeration figures = getUndoActivity().getAffectedFigures(); while (figures.hasMoreElements()) { figures.nextFigure().moveBy(x - fLastX, y - fLastY); } } fLastX = x; fLastY = y; }
private String readablePeriod(Period period) { if (period.isZero()) return "Hoy"; String startsWith = period.isNegative() ? "Hace " : "En "; long months = Math.abs(period.toTotalMonths()); int days = Math.abs(period.getDays()); if (Math.abs(months) > 0) { String endsWith = (months > 1) ? "es" : ""; return startsWith + months + " mes" + endsWith; } else { String endsWith = (days > 1) ? "s" : ""; return startsWith + days + " dia" + endsWith; } }
/** * When the ERASE or SMUDGE tools are used and the mouse jumps from (x1,y1) to (x2,y2), the tool * has to be applied to a line of pixel positions between the two points in order to cover the * entire line that the mouse moves along. The change is made to the off-screen canvas, and * repaint() is called to copy the changes to the screen. */ void applyToolAlongLine(int x1, int y1, int x2, int y2) { Graphics g = OSC.getGraphics(); g.setColor(fillColor); // (for ERASE only) int w = OSC.getWidth(); // (for SMUDGE only) int h = OSC.getHeight(); // (for SMUDGE only) int dist = Math.max(Math.abs(x2 - x1), Math.abs(y2 - y1)); // dist is the number of points along the line from // (x1,y1) to (x2,y2) at which the tool will be applied. double dx = (double) (x2 - x1) / dist; double dy = (double) (y2 - y1) / dist; for (int d = 1; d <= dist; d++) { // Apply the tool at one of the points (x,y) along the // line from (x1,y1) to (x2,y2). int x = (int) Math.round(x1 + dx * d); int y = (int) Math.round(y1 + dy * d); if (currentTool == Tool.ERASE) { // Erase a 10-by-10 block of pixels around (x,y) g.fillRect(x - 5, y - 5, 10, 10); repaint(x - 5, y - 5, 10, 10); } else { // For the SMUDGE tool, blend some of the color from // the smudgeRed, smudgeGreen, and smudgeBlue arrays // into the pixels in a 7-by-7 block around (x,y), and // vice versa. The effect is to smear out the color // of pixels that are visited by the tool. for (int i = 0; i < 7; i++) { for (int j = 0; j < 7; j++) { int r = y + j - 3; int c = x + i - 3; if (!(r < 0 || r >= h || c < 0 || c >= w || smudgeRed[i][j] == -1)) { int curCol = OSC.getRGB(c, r); int curRed = (curCol >> 16) & 0xFF; int curGreen = (curCol >> 8) & 0xFF; int curBlue = curCol & 0xFF; int newRed = (int) (curRed * 0.7 + smudgeRed[i][j] * 0.3); int newGreen = (int) (curGreen * 0.7 + smudgeGreen[i][j] * 0.3); int newBlue = (int) (curBlue * 0.7 + smudgeBlue[i][j] * 0.3); int newCol = newRed << 16 | newGreen << 8 | newBlue; OSC.setRGB(c, r, newCol); smudgeRed[i][j] = curRed * 0.3 + smudgeRed[i][j] * 0.7; smudgeGreen[i][j] = curGreen * 0.3 + smudgeGreen[i][j] * 0.7; smudgeBlue[i][j] = curBlue * 0.3 + smudgeBlue[i][j] * 0.7; } } } repaint(x - 3, y - 3, 7, 7); } } g.dispose(); }
private int computeDifference(int PIXEL_OG, int PIXEL_MD) { int OG_RED = (PIXEL_OG & 0xff0000) >> 16; int OG_GREEN = (PIXEL_OG & 0xff00) >> 8; int OG_BLUE = (PIXEL_OG & 0xff); int MD_RED = (PIXEL_MD & 0xff0000) >> 16; int MD_GREEN = (PIXEL_MD & 0xff00) >> 8; int MD_BLUE = (PIXEL_MD & 0xff); int difference = Math.abs(OG_RED - MD_RED) + Math.abs(OG_GREEN - MD_GREEN) + Math.abs(OG_BLUE - MD_BLUE); return difference; }
protected void updateNearest(double[] vec, int ax, int ay, int x, int y) { int type = this.map[x][y] - 1; if (type > -1) { int dx = x - ax; int dy = y - ay; int d = Math.abs(dx) + Math.abs(dy); int ind = this.numCells + type; if (d < vec[ind]) { vec[ind] = d; } } }
void doStep() { double vac = volts[anode] - volts[cnode]; // typically negative double vag = volts[anode] - volts[gnode]; // typically positive if (Math.abs(vac - lastvac) > .01 || Math.abs(vag - lastvag) > .01) sim.converged = false; lastvac = vac; lastvag = vag; diode.doStep(volts[inode] - volts[gnode]); double icmult = 1 / triggerI; double iamult = 1 / holdingI - icmult; // System.out.println(icmult + " " + iamult); aresistance = (-icmult * ic + ia * iamult > 1) ? .0105 : 10e5; // System.out.println(vac + " " + vag + " " + sim.converged + " " + ic + " " + ia + " " + // aresistance + " " + volts[inode] + " " + volts[gnode] + " " + volts[anode]); sim.stampResistor(nodes[anode], nodes[inode], aresistance); }