Changeset 106


Ignore:
Timestamp:
06/20/08 13:33:11 (16 years ago)
Author:
ra33
Message:

Changed all the (int)(x+0.5) float conversions to use the Math.round(x) which does Math.floor(x+0.5F) so that negative numbers are rounded properly

Location:
trunk/src/org/expeditee
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/actions/Simple.java

    r105 r106  
    348348         * @param pause
    349349         */
    350         public static void DebugFrame(Item current, double pause, Color color) {
    351                 RunFrame(current, false, true, (int) (pause * 1000 + 0.5), color);
     350        public static void DebugFrame(Item current, float pause, Color color) {
     351                RunFrame(current, false, true, Math.round(pause * 1000), color);
    352352        }
    353353
     
    359359         *            the time to pause between
    360360         */
    361         public static void DebugFrame(Item current, double pause) {
     361        public static void DebugFrame(Item current, float pause) {
    362362                DebugFrame(current, pause, null);
    363363        }
    364364
    365365        public static void DebugFrame(Item current) {
    366                 DebugFrame(current, -1.0, null);
     366                DebugFrame(current, -1.0F, null);
    367367        }
    368368
  • trunk/src/org/expeditee/gui/DisplayIO.java

    r105 r106  
    213213                int mouseX = (int) _Browser.getContentPane().getLocationOnScreen()
    214214                                .getX()
    215                                 + (int) (x + 0.5);
     215                                + Math.round(x);
    216216                int mouseY = (int) _Browser.getContentPane().getLocationOnScreen()
    217217                                .getY()
    218                                 + (int) (y + 0.5);
     218                                + Math.round(y);
    219219                _Robot.mouseMove(mouseX, mouseY);
    220220                // System.out.println("MouseMoved: " + x + "," + y);
  • trunk/src/org/expeditee/gui/FrameGraphics.java

    r105 r106  
    279279                        i.setActionMark(false);
    280280                        if (!(i instanceof Line)) {
    281                                 i.setXY((int) (i.getX() * scale + dx + 0.5), (int) (i.getY()
    282                                                 * scale + dy + 0.5));
    283                                 i.setThickness((int) (i.getThickness() * scale + 0.5));
     281                                i.setXY(Math.round(i.getX() * scale + dx), Math.round(i.getY()
     282                                                * scale + dy));
     283                                i.setThickness(Math.round(i.getThickness() * scale));
    284284                                i
    285                                                 .setArrowheadLength((int) (i.getArrowheadLength()
    286                                                                 * scale + 0.5));
     285                                                .setArrowheadLength(Math.round(i.getArrowheadLength()
     286                                                                * scale));
    287287                                if (i.getColor() == null) {
    288288                                        i.setColor(defaultForeground);
     
    296296                        }
    297297                        if (i instanceof Text)
    298                                 i.setSize((int) (i.getSize() * scale + 0.5));
     298                                i.setSize(Math.round(i.getSize() * scale));
    299299                        items.add(i);
    300300                }
  • trunk/src/org/expeditee/gui/FrameMouseActions.java

    r105 r106  
    335335                        _lastRanged = (Text) on;
    336336                        // set start-drag point
    337                         _lastRanged.setSelectionStart(DisplayIO.getMouseX(), FrameMouseActions.getY());
     337                        _lastRanged.setSelectionStart(DisplayIO.getMouseX(),
     338                                        FrameMouseActions.getY());
    338339                }
    339340
     
    342343                        _lastCropped = (Picture) on;
    343344                        // set start crop point
    344                         _lastCropped.setStartCrop(DisplayIO.getMouseX(), FrameMouseActions.getY());
     345                        _lastCropped.setStartCrop(DisplayIO.getMouseX(), FrameMouseActions
     346                                        .getY());
    345347                        _lastCropped.setShowCrop(true);
    346348                }
     
    844846                        // otherwise the user is creating a line
    845847                } else {
    846                         Item on = FrameUtils.onItem(DisplayIO.getCurrentFrame(), Math.round(MouseX),
    847                                         Math.round(MouseY));
     848                        Item on = FrameUtils.onItem(DisplayIO.getCurrentFrame(), Math
     849                                        .round(MouseX), Math.round(MouseY));
    848850                        // If we have permission to copy this item then pick it up
    849851                        if (on != null && on.isLineEnd()
     
    862864                                Item newPoint = oldLine.getStartItem().copy();
    863865                                newPoint.setPosition(MouseX, MouseY);
    864                                
     866
    865867                                Item end = oldLine.getEndItem();
    866868                                // create the Line
     
    11751177                                                        && on.Permission >= Item.PERMISSION_FULL) {
    11761178
    1177                                                 Line onLine = (Line)on;
     1179                                                Line onLine = (Line) on;
    11781180                                                Line newLine = onLine.copy();
    11791181                                                Item end = newLine.getEndItem();
     
    11861188                                                // attach the line to the cursor
    11871189                                                pickup(end);
    1188                                                
     1190
    11891191                                                List<Item> toMerge = new LinkedList<Item>();
    11901192                                                toMerge.add(newLine.getStartItem());
     
    13211323                        } else {
    13221324                                // update the ranged section
    1323                                 _lastRanged.setSelectionEnd(DisplayIO.getMouseX(), FrameMouseActions.getY());
     1325                                _lastRanged.setSelectionEnd(DisplayIO.getMouseX(),
     1326                                                FrameMouseActions.getY());
    13241327                                _isNoOp = false;
    13251328                        }
     
    13491352                        }
    13501353                        // update the ranged section
    1351                         _lastCropped.setEndCrop(DisplayIO.getMouseX(), FrameMouseActions.getY());
     1354                        _lastCropped.setEndCrop(DisplayIO.getMouseX(), FrameMouseActions
     1355                                        .getY());
    13521356
    13531357                        FrameGraphics.Repaint();
     
    14141418                // System.out.println("MouseMoved: " + MouseX + "," + MouseY + " " +
    14151419                // System.currentTimeMillis());
    1416                 LastRobotX = (int) (x + 0.5);
    1417                 LastRobotY = (int) (y + 0.5);
     1420                LastRobotX = Math.round(x);
     1421                LastRobotY = Math.round(y);
    14181422                _RobotTimer.start();
    14191423        }
     
    15371541
    15381542                                                        if (vLength > hLength) {
    1539                                                                 MouseX = (int) (hOtherEnd.getX() + vLength
    1540                                                                                 * (MouseX > hOtherEnd.getX() ? 1 : -1) + 0.5);
     1543                                                                MouseX = Math.round(hOtherEnd.getX() + vLength
     1544                                                                                * (MouseX > hOtherEnd.getX() ? 1 : -1));
    15411545                                                        } else /* if (hLength > vLength) */{
    1542                                                                 MouseY = (int) (vOtherEnd.getY() + hLength
    1543                                                                                 * (MouseY > vOtherEnd.getY() ? 1 : -1) + 0.5);
     1546                                                                MouseY = Math.round(vOtherEnd.getY() + hLength
     1547                                                                                * (MouseY > vOtherEnd.getY() ? 1 : -1));
    15441548                                                        }
    15451549                                                }
     
    15741578                                                double l_new = l3 / (2 * cosTheta);
    15751579                                                double ratio = l_new / l1;
    1576                                                 MouseX = (int) ((e.getX() - lineEnd1.getX()) * ratio + 0.5)
     1580                                                MouseX = Math.round((e.getX() - lineEnd1.getX())
     1581                                                                * ratio)
    15771582                                                                + lineEnd1.getX();
    1578                                                 MouseY = (int) ((e.getY() - lineEnd1.getY()) * ratio + 0.5)
     1583                                                MouseY = Math.round((e.getY() - lineEnd1.getY())
     1584                                                                * ratio)
    15791585                                                                + lineEnd1.getY();
    15801586
     
    16381644                                        // Checks that we are actually pointing on a character
    16391645                                        // not just space in the text box's bounding box
    1640                                         if (((Item) on).contains(DisplayIO.getMouseX(), FrameMouseActions.getY())) {
     1646                                        if (((Item) on).contains(DisplayIO.getMouseX(),
     1647                                                        FrameMouseActions.getY())) {
    16411648                                                _context = CONTEXT_AT_TEXT;
    16421649                                        } else {
     
    17881795                        return;
    17891796                }
    1790                 //This is to make sure the TEXT_CURSOR doesnt get inadvertantly turned off!
     1797                // This is to make sure the TEXT_CURSOR doesnt get inadvertantly turned
     1798                // off!
    17911799                Item on = FrameUtils.getCurrentItem();
    1792                 if(on != null && on instanceof Text){
     1800                if (on != null && on instanceof Text) {
    17931801                        return;
    17941802                }
     
    18201828
    18211829                for (Item move : toMove) {
    1822                         move.setPosition(move.getX() - deltax, move.getY() - deltay);
     1830                        if (!(move instanceof Line))
     1831                                move.setPosition(move.getX() - deltax, move.getY() - deltay);
    18231832
    18241833                        if (move instanceof Text) {
     
    25972606
    25982607        public static int getX() {
    2599                 return (int)(MouseX + 0.5);
    2600         }
    2601        
     2608                return Math.round(MouseX);
     2609        }
     2610
    26022611        public static int getY() {
    2603                 return (int)(MouseY + 0.5);
     2612                return Math.round(MouseY);
    26042613        }
    26052614}
  • trunk/src/org/expeditee/items/FrameBitmap.java

    r98 r106  
    5959                                        // Space is transparent as is 0
    6060                                        if (Character.isDigit(currentPixel)) {
    61                                                 int alpha = (int)((currentPixel - '0') * 25.5F + 0.5F);
     61                                                int alpha = Math.round((currentPixel - '0') * 25.5F);
    6262                                                currentColor = new Color(c.getRed(), c.getGreen(), c
    6363                                                                .getBlue(), alpha).getRGB();
  • trunk/src/org/expeditee/items/Item.java

    r105 r106  
    785785         */
    786786        public int getX() {
    787                 return (int) (_x + 0.5);
     787                return Math.round(_x);
    788788        }
    789789
     
    794794         */
    795795        public int getY() {
    796                 return (int) (_y + 0.5);
     796                return Math.round(_y);
    797797        }
    798798
  • trunk/src/org/expeditee/items/Picture.java

    r105 r106  
    481481
    482482                int multiplier = 1000 + (diff) * 40;
    483                 _scale = ((int)(_scale * multiplier + 0.5)) / 1000F;
     483                _scale = (Math.round(_scale * multiplier)) / 1000F;
    484484
    485485                //If the above formula didnt change stuff due to rounding
  • trunk/src/org/expeditee/items/Text.java

    r105 r106  
    396396                float y = getLineDrop(last) * line;
    397397
    398                 int x = ((int) (getX() + caret[0] + 0.5) + getJustOffset(last));
     398                int x = (Math.round(getX() + caret[0]) + getJustOffset(last));
    399399                x = Math
    400400                                .min(
    401401                                                x,
    402402                                                (getX() - Item.MARGIN_RIGHT - (2 * getGravity()) + getBoundsWidth()));
    403                 return new Point(x, (int) (getY() + y + caret[1] + 0.5));
     403                return new Point(x, Math.round(getY() + y + caret[1]));
    404404        }
    405405
     
    617617                float y = getLineDrop(current) * line;
    618618
    619                 int x = (int) (getX() + caret[0] + 0.5) + getJustOffset(current);
     619                int x = Math.round(getX() + caret[0]) + getJustOffset(current);
    620620                x = Math
    621621                                .min(
    622622                                                x,
    623623                                                (getX() - Item.MARGIN_RIGHT - (2 * getGravity()) + getBoundsWidth()));
    624                 return new Point(x, (int) (getY() + y + caret[1] + 0.5));
     624                return new Point(x, Math.round(getY() + y + caret[1]));
    625625        }
    626626
     
    701701                float y = getLineDrop(current) * line;
    702702
    703                 return new Point((int) (getX() + caret[0] + 0.5)
    704                                 + getJustOffset(current), (int) (getY() + y + caret[1] + 0.5));
     703                return new Point(Math.round(getX() + caret[0])
     704                                + getJustOffset(current), Math.round(getY() + y + caret[1]));
    705705        }
    706706
  • trunk/src/org/expeditee/stats/SessionStats.java

    r105 r106  
    115115                long elapsedTime = currentTime.getTime() - _StartTime.getTime();
    116116                String time = ""
    117                                 + (int) ((double) elapsedTime / MILLISECONDS_PER_MINUTE + 0.5); // (new
    118                 // SimpleDateFormat("m").format(elapsedTime));
    119 
     117                                + Math.round((float) elapsedTime / MILLISECONDS_PER_MINUTE );
    120118                return time;
    121119        }
Note: See TracChangeset for help on using the changeset viewer.