Search Results

Search found 968 results on 39 pages for 'closest'.

Page 5/39 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • Which of these algorithms is best for my goal?

    - by JonathonG
    I have created a program that restricts the mouse to a certain region based on a black/white bitmap. The program is 100% functional as-is, but uses an inaccurate, albeit fast, algorithm for repositioning the mouse when it strays outside the area. Currently, when the mouse moves outside the area, basically what happens is this: A line is drawn between a pre-defined static point inside the region and the mouse's new position. The point where that line intersects the edge of the allowed area is found. The mouse is moved to that point. This works, but only works perfectly for a perfect circle with the pre-defined point set in the exact center. Unfortunately, this will never be the case. The application will be used with a variety of rectangles and irregular, amorphous shapes. On such shapes, the point where the line drawn intersects the edge will usually not be the closest point on the shape to the mouse. I need to create a new algorithm that finds the closest point to the mouse's new position on the edge of the allowed area. I have several ideas about this, but I am not sure of their validity, in that they may have far too much overhead. While I am not asking for code, it might help to know that I am using Objective C / Cocoa, developing for OS X, as I feel the language being used might affect the efficiency of potential methods. My ideas are: Using a bit of trigonometry to project lines would work, but that would require some kind of intense algorithm to test every point on every line until it found the edge of the region... That seems too resource intensive since there could be something like 200 lines that would have each have to have as many as 200 pixels checked for black/white.... Using something like an A* pathing algorithm to find the shortest path to a black pixel; however, A* seems resource intensive, even though I could probably restrict it to only checking roughly in one direction. It also seems like it will take more time and effort than I have available to spend on this small portion of the much larger project I am working on, correct me if I am wrong and it would not be a significant amount of code (100 lines or around there). Mapping the border of the region before the application begins running the event tap loop. I think I could accomplish this by using my current line-based algorithm to find an edge point and then initiating an algorithm that checks all 8 pixels around that pixel, finds the next border pixel in one direction, and continues to do this until it comes back to the starting pixel. I could then store that data in an array to be used for the entire duration of the program, and have the mouse re-positioning method check the array for the closest pixel on the border to the mouse target position. That last method would presumably execute it's initial border mapping fairly quickly. (It would only have to map between 2,000 and 8,000 pixels, which means 8,000 to 64,000 checked, and I could even permanently store the data to make launching faster.) However, I am uncertain as to how much overhead it would take to scan through that array for the shortest distance for every single mouse move event... I suppose there could be a shortcut to restrict the number of elements in the array that will be checked to a variable number starting with the intersecting point on the line (from my original algorithm), and raise/lower that number to experiment with the overhead/accuracy tradeoff. Please let me know if I am over thinking this and there is an easier way that will work just fine, or which of these methods would be able to execute something like 30 times per second to keep mouse movement smooth, or if you have a better/faster method. I've posted relevant parts of my code below for reference, and included an example of what the area might look like. (I check for color value against a loaded bitmap that is black/white.) // // This part of my code runs every single time the mouse moves. // CGPoint point = CGEventGetLocation(event); float tX = point.x; float tY = point.y; if( is_in_area(tX,tY, mouse_mask)){ // target is inside O.K. area, do nothing }else{ CGPoint target; //point inside restricted region: float iX = 600; // inside x float iY = 500; // inside y // delta to midpoint between iX,iY and tX,tY float dX; float dY; float accuracy = .5; //accuracy to loop until reached do { dX = (tX-iX)/2; dY = (tY-iY)/2; if(is_in_area((tX-dX),(tY-dY),mouse_mask)){ iX += dX; iY += dY; } else { tX -= dX; tY -= dY; } } while (abs(dX)>accuracy || abs(dY)>accuracy); target = CGPointMake(roundf(tX), roundf(tY)); CGDisplayMoveCursorToPoint(CGMainDisplayID(),target); } Here is "is_in_area(int x, int y)" : bool is_in_area(NSInteger x, NSInteger y, NSBitmapImageRep *mouse_mask){ NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; NSUInteger pixel[4]; [mouse_mask getPixel:pixel atX:x y:y]; if(pixel[0]!= 0){ [pool release]; return false; } [pool release]; return true; }

    Read the article

  • Constant opacity with glBlendFunc on iPhone

    - by Jeff Johnson
    What glBlendFunc should I use to ensure that the opacity of my drawing is always the same? When I use glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) and multiple images are drawn on top of each other, the result is more and more opaque until it's completely opaque after a certain number of imgaes. The closest I have come is to use glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_ONE_MINUS_SRC_ALPHA) which maintains a constant opacity no matter how many images are on top of each other, although there is a slight variation in opacity if the images overlap each other. Any other render states I should consider trying? Any other ideas? I am making a drawing app for my kid and I don't want the images (brush) they draw to cover up the background. Heres the closest I've got: I want to have it so that the overlap part of the circles is the same color and opacity as the center part of the circle. I am using cocos2d iphone v. 0.99

    Read the article

  • How do I fix incorrect inline Javascript indentation in Vim?

    - by Charles Roper
    I can't seem to get inline Javascript indenting properly in Vim. Consider the following: $(document).ready(function() { // Closing brace correctly indented $("input").focus(function() { $(this).closest("li").addClass("cur-focus"); }); // <-- I had to manually unindent this // Closing brace incorrectly indented $("input").blur(function() { $(this).closest("li").removeClass("cur-focus"); }); // <-- This is what it does by default. Argh! }); Vim seems to insist on automatically indenting the closing brace shown in the second case there. It does the same if I re-indent the whole file. How do I get it to automatically indent using the more standard JS indenting style seen in the first case?

    Read the article

  • How to tell if XUL menupopup opens down or up?

    - by Jon
    I have an extension that can be placed on any toolbar (like the bookmarks, menu or status bars). In general, the context menu opens downward, but when placed on the status bar and Firefox is closed to the bottom of the screen, the context menu opens upward. I'd like to try reordering the context menu based on its up or down orientation, so that the same options are always closest to the mouse. For example, when opened downward it appears like this: -- (mouse) --------------- - MenuItem A - --------------- - MenuItem B - --------------- - MenuItem C - --------------- - ....... - --------------- When it opens upwards its like this: --------------- - MenuItem A - --------------- - MenuItem B - --------------- - MenuItem C - --------------- - ....... - --------------- -- (mouse) However, I'd like "MenuItem A" to appear closest to the mouse at all times, since its the most common item. I can render the items dynamically, so I really just need to find out the orientation.

    Read the article

  • bug in my jquery code while trying replace html elements with own values

    - by loviji
    I today ask a question, about using Jquery, replace html elements with own values. link text And I use answer, and get a problem. function replaceWithValues not works same in all cases.I call this function two times: 1. btnAddParam click 2. btnCancelEdit click $("#btnAddParam").click(function() { var lastRow = $('#mainTable tr:last'); var rowState = $("#mainTable tr:last>td:first"); replaceWithValues(lastRow, rowState); var htmlToAppend = "<tr bgcolor='#B0B0B0' ><td class='textField' er='editable'><input value='' type='text' /></td><td><textarea cols='40' rows='3' ></textarea></td><td>" + initSelectType(currentID) + "</td><td><input id='txt" + currentID + "3' type='text' class='measureUnit' /></td><td><input type='checkbox' /></td><td></td></tr>"; $("#mainTable").append(htmlToAppend); }); //buttonCancelEdit located in end of row $('#mainTable input:button').unbind().live('click', function() { var row = $(this).closest('tr'); var rowState = $(this).closest('tr').find("td:first"); replaceWithValues(row, rowState); $(this).remove(); }); //do row editable -- replaceWithElements $('#mainTable tr').unbind().live('click', function() { if ($(this).find("td:first").attr("er") == "readable") { var rowState = $(this).closest('tr').find("td:first"); replaceWithElements($(this), rowState); } }); function replaceWithValues(row, er) { if (er.attr("er") == "editable") { var inputElements = $('td > input:text', row); inputElements.each(function() { var value = $(this).val(); $(this).replaceWith(value); }); er.attr("er", "readable"); } } function replaceWithElements(row, er) { if (er.attr("er") == "readable") { var tdinit = $("<td>").attr("er", "editable").addClass("textField"); $('.textField', row).each(function() { var element = tdinit.append($("<input type='text' value="+$.trim($(this).text())+" />")); $(this).empty().replaceWith(element); }); row.find("td:last").append("<input type='button'/>"); //$('.selectField') ... //$('.textAreaField') ... } } $("#btnAddParam").click() function works well. it call function replaceWithValues. I call $('#mainTable tr').unbind().live('click', function() { } to do row editable, and it creates a button in the end of row. After user can click this button and call function $('#mainTable input:button').unbind().live('click', function() {}. and this function call function replaceWithValues. but in this case it doesn't work.

    Read the article

  • jquery add row on click only if it's empty?

    - by KittyYoung
    The code below works, insomuch that if I click in an input field, it'll add another row. I'm trying to figure out though, how to do that only if the input field is empty? $("#tableSearchData > tbody > tr > td > input").bind('focus', function(){ var row = $(this).closest("tr").get(0); if( row.className.indexOf("clicked")==-1 ) { var rowCopy=$(row).clone(true); $(row).closest("tbody").append(rowCopy); row.className+=" clicked"; } });

    Read the article

  • Java M4A atom tagging free space issue

    - by Brett
    Hey, I've been trying to be able to read and write iTunes style M4A atoms and while I've successfully done the reading part, I've come to a bit of a halt in regards to the free space atoms. I figured that I should be able edit and shift the padding around to accommodate writing an atom with more data than it originally had. I've been stuck on this for about a day now, and I've been trying to figure out how to determine the closest free space atom with enough size to accommodate the new data. so far I have: private freeAtom acquireFreeSpaceAtom( long position ) { long atomStart = Long.MAX_VALUE; freeAtom atom = null; for( freeAtom a : freeSpace ) { if( Math.abs( position - atomStart ) > Math.abs( position - a.getAtomStart() ) ) atomStart = ( atom = a ).getAtomStart(); } return atom; } That code only takes into account the closest free space atom and completely disregards the fact that it should be greater than or equal to a certain size, but I can't quite figure out how I should check for both closeness and size efficiently.

    Read the article

  • Why I am not getting Row value on click using this?

    - by rockers
    $("#grid td:first-child").click(function() { var value = $(this).closest('tr').find('td:eq(2)').text(); // for third column alert(value); var value = $(this).closest('tr').find('td:eq(3)').text(); // for fourth column alert(value); var AccountName = accountid; var x = function() { $(this).click($("#showregiongrid").load('/analyst/ror/regionspeexc/?a=' + AccountName)); } clickTimer = window.setTimeout(x, 300); }); Why i am not getting the row values of eq(2) and eq(3).. is there anyting I am doing wrong? if I delete td:first-child from my click event I am getting null vallues on popup? thanks

    Read the article

  • Referencing the current jQuery object in a chain?

    - by Lance McNearney
    At DevDays in SF last year (before jQuery 1.4 was released), I thought they mentioned an upcoming feature in 1.4 that would allow you to reference the current jQuery object while in a chain. I've read through all of the 1.4 improvements and wasn't able to find it. Does anyone know how this can be done? Example Being able to access the current jQuery object would be helpful when working with methods that are in relation to the current object like .next(): // Current way var items = $(this).closest('tr'); items = items.add(items.next(':not([id])')); // Magical 1.4 way? Is there a "chain"-like object? var items = $(this).closest('tr') .add(chain.next(':not([id])'));

    Read the article

  • How do I add a function to an element via jQuery?

    - by Chad Johnson
    I want to do something like this: $('.dynamicHtmlForm').validate = function() { return true; } $('.dynamicHtmlForm .saveButton').click(function() { if (!$(this).closest('.dynamicHtmlForm').validate()) { return false; } return true; }); And then when I have a form of class dynamicHtmlForm, I want to be able to provide a custom validate() function: $('#myDynamicHtmlForm').validate = function() { // do some validation if (there are errors) { return false; } return true; } But I get this when I do this: $(this).closest(".dynamicHtmlForm").validate is not a function Is what I've described even possible? If so, what am I doing wrong?

    Read the article

  • how to view associated click function code

    - by llamerr
    For example, i associate following function with some element $('table#users tbody tr:first #save').click(function(){ $(this).closest('tr').remove(); }); Now, if i don't know where this function is stored, is there a way to view associated with click() code? In above example, i want a way to view that in firebug, or in another way $(this).closest('tr').remove(); If I'm writing in console following, i'm get a link to dom inspector >>> ($('table#users tbody tr:first #save').click) function() but link is for jquery library, not the code i want.

    Read the article

  • jQuery click listener on <object> in IE failing

    - by Steve Meisner
    $("#listView object.modal").click(function(){ // Get the ID of the clicked link: var link = $(this).closest("h2").attr("title"); var id = $(this).closest("div").attr("id"); showDialog(link, id); return false; }); This fires a modal (jQuery UI). It it working in FF, Chrome/Safari but not in IE 7/8. Is there something I'm missing here? Big Picture: We're using a swf to render custom type and there is a link in the rendered (flash) content. We're hoping to catch the link action in the jQuery listener so we don't have to extend our swf have an optional param to return false on link click. We thought we got around it, until IE testing commenced... Let me know if any more info is needed. Thanks!

    Read the article

  • How can I delete a row in the view only if the AJAX call & db deletion was successful?

    - by user1760663
    I have a table where each row has a button for deletion. Actually I delete the row everytime without checking if the ajax call was successfull. How can I achieve that, so that the row will only be deleted if the ajax call was ok. Here is my clickhandler on each row $("body").on('click', ".ui-icon-trash" ,function(){ var $closestTr = $(this).closest('tr'); // This will give the closest tr // If the class element is the child of tr deleteRowFromDB(oTable, closestTr); $closestTr.remove() ; // Will delete that }); And here my ajax call function deleteRowFromDB(oTable, sendallproperty){ var deleteEntryRoute = #{jsRoute @Application.deleteConfigurationEntry() /} console.log("route is: " + deleteEntryRoute.url) $.ajax({ url: deleteEntryRoute.url({id: sendallproperty}), type: deleteEntryRoute.method, data: 'id=' + sendallproperty });

    Read the article

  • How to change a table row color when clicked and back to what it was originally when another row clicked?

    - by user1277222
    As the title explains, I wish to change the color of a row when it is clicked then revert the color when another is clicked, however still change the color of the newly clicked row. A resolution in JQuery would be much appreciated. I just can't crack this one. What I have so far but it's not working for me. function loadjob(jobIDincoming, currentID){ $("#joblistingDetail").load('jobview.php' , {jobID: jobIDincoming}).hide().fadeIn('100'); var last = new Array(); last.push(currentID); $(last[last.length-1]).closest('tr').css('background-color', 'white'); $(currentID).closest('tr').css('background-color', 'red');};

    Read the article

  • Why can't I configure my touchpad?

    - by Jorge Castro
    I want to disable my touchpad's "tap to click" feature. Searching for this on the internet comes up with suggestions to shut it off in the "Mouse" preferences, however I am missing the touchpad tab that people keep talking about: The closest official documentation I've been able to find is here. The touchpad also doesn't show up in gpointing-device-settings. Unchecking tap_to_click in the /desktop/gnome/peripherals/touchpad/ gconf key doesn't seem to do anything.

    Read the article

  • Libgdx Palette Swap

    - by Haedrian
    I'm developing a game using the Libgdx library. I'm trying to implement a very simple palette swap functionality (basically just complete recolouring of some areas, I don't even need to have various shades), but I don't have any idea where to begin. The closest I've come is trying to draw the picture myself using a Pixmap, but that appears to be horrible unmaintainable and produces oodles of code.

    Read the article

  • How to support email subscriptions to many rss feeds

    - by peter
    I am interested in having the option to be able to subscribe to any of my RSS feeds by email, without having to manage any of the email lists. Are there any email delivery services that allow easy subscription to arbitrary feeds? MailChimp's api doesn't allow list creation. The closest I can come up with is linking people to a google alert: http://www.google.com/alerts?q=site:mysite.com/category/food http://www.google.com/alerts?q=site:mysite.com/category/drinks

    Read the article

  • Samsung Color Laser printer CLP-365W: all printout condensed into left half?

    - by ajo
    After installing the Samsung Color Laser Printer CLP-365W in 12.04, the printout is condensed into the left half of the A4 page (regardless whether 'fit to page' on or off). This happens both with the automatically recognised Ubuntu driver and the 'Unified Linux driver' from the Samsung website. (The 300.ppd (as per 'Unified driver' install) or 360.ppd are the closest matches to '365'.) Any help?? Test page printout Test page printout closeup

    Read the article

  • Making large scale changes to an economy in a social game

    - by Zach
    Are there any examples or case studies of social games, specifically on Facebook, where the developer has made drastic changes to the economy? I'm specifically interested in examples where the old economy was based off of purchasing items with Facebook credits then moving to a new model where the same inventory or similar inventory is sold with a soft currency. The closest comparisons I've been able to find so far are looking at iOS games that have gone from purchase models to freemium models, but haven't found a comparable scenario in a social game besides larger scale MMO's.

    Read the article

  • Circle-Rectangle collision in a tile map game

    - by furiousd
    I am making a 2D tile map based putt-putt game. I have collision detection working between the ball and the walls of the map, although when the ball collides at the meeting point between 2 tiles I offset it by 0.5 so that it doesn't get stuck in the wall. This aint a huge issue though. if(y % 20 == 0) { y+=0.5; } if(x % 20 == 0) { x+=0.5; } Collisions work as follows Find the closest point between each tile and the center of the ball If distance(ball_x, ball_y, close_x, close_y) <= ball_radius and the closest point belongs to a solid object, collision has occured Invert X/Y speed according to side of object collided with The next thing I tried to do was implement floating blocks in the middle of the map for the ball to bounce off of. When a ball collides with a corner of the block, it gets stuck in it. So I changed my determineRebound() function to treat corners as if they were circles. Here's that functon: `i and j are indexes of the solid object in the 2d map array. x & y are centre point of ball.` void determineRebound(int _i, int _j) { if(y > _i*tile_w && y < _i*tile_w + tile_w) { //Not a corner xs*=-1; } else if(x > _j*tile_w && x < _j*tile_w + tile_w) { //Not a corner ys*=-1; } else { //Corner float nx = x - close_x; float ny = y - close_y; float len = sqrt(nx * nx + ny * ny); nx /= len; ny /= len; float projection = xs * nx + ys * ny; xs -= 2 * projection * nx; ys -= 2 * projection * ny; } } This is where things have gotten messy. Collisions with 'floating' corners work fine, but now when the ball collides near the meeting point of 2 tiles, it detects a corner collision and does not rebound as expected. I'm a bit in over my head at this point. I guess I'm wondering if I'm going about making this sort of game in the right way. Is a 2d tile map the way to go? If so, is there a problem with my collision logic and where am I going wrong? Any advice/feedback would be great.

    Read the article

  • Real-Time Multi-User Gaming Platform

    - by Victor Engel
    I asked this question at Stack Overflow but was told it's more appropriate here, so I'm posting it again here. I'm considering developing a real-time multi-user game, and I want to gather some information about possibilities before I do some real development. I've thought about how best to ask the question, and for simplicity, the best way that occurred to me was to make an analogy to the field (or playground) game darebase. In the field game of darebase, there are two or more bases. To start, there is one team on each base. The game is a fancy game of tag. When two people meet out in the field, the person who left his base most recently timewise captures the other person. They then return to that person's base. Play continues until everyone is part of the same team. So, analogizing this to an online computer game, let's suppose there are an indefinite number of bases. When a person starts up the game, he has a team that is located at, for example, his current GPS coordinates. It could be a virtual world, but for sake of argument, let's suppose the virtual world corresponds to the player's actual GPS coordinates. The game software then consults the database to see where the closest other base is that is online, and the two teams play their game of virtual tag. Note that the user of the other base could have a different base than the one run by the current user as the closest base to him, in which case, he would be in two simultaneous battles, one with each base. When they go offline, the state of their players is saved on a server somewhere. Game logic calls for the players to have some automaton-logic of some sort, so they can fend for themselves in a limited way using basic rules, until their user goes online again. The user doesn't control the players' movements directly, but issues general directives that influence the players' movement logic. I think this analogy is good enough to frame my question. What sort of platforms are available to develop this sort of game? I've been looking at smartfoxserver, but I'm not convinced yet that it is the best option or even that it will work at all. One possibility, of course, would be to roll out my own web server, but I'd rather not do that if there is an existing service out there already that I could tap into. I will be developing for iOS devices at first. So any suggestions would be greatly appreciated. I think I need to establish the architecture first before proceeding with this project. Note that darbase is not the game I intend to implement, but, upon reflection, that might not be a bad idea either.

    Read the article

  • All printouts condensed into left half on a Samsung Color Laser printer CLP-365W

    - by ajo
    After installing the Samsung Color Laser Printer CLP-365W in 12.04, the printout is condensed into the left half of the A4 page (regardless whether 'fit to page' on or off). This happens both with the automatically recognised Ubuntu driver and the 'Unified Linux driver' from the Samsung website. (The 300.ppd (as per 'Unified driver' install) or 360.ppd are the closest matches to '365'.) Any help?? Test page printout Test page printout closeup

    Read the article

  • Empirical evidence regarding testability

    - by Xodarap
    A google scholar search turns up numerous papers on testability, including models for computing testability, recommendations for how ones code can be more testable, etc. They all come with the assertion that more testable code is more stable, but I can't find any studies which actually demonstrate this. Can someone link me to a study evaluating the effect of testable code vs. quality? The closest I can find is Improving the Testability of Object Oriented Systems, which discusses the relationship between design flaws and testability.

    Read the article

  • Will New Horizons have to bailout?

    - by TATWORTH
    At http://pluto.jhuapl.edu/news_center/news/20121016.php, there is an interesting post about the challenge facing the New Horizons as to whether to allow the spacecraft to remain on the current trajectory which will take it between Pluto and the orbit of Charon, the closest in known moon of Pluto. Given that the current round-trip light time is 6 hrs 53 minutes, a decision to go for a bail-out fly-past must be taken some 10 days in advance of the actual fly-past.

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >