C# :: Indexing Through Rectangle List?
Mar 11, 2014
I have having trouble looping through the list in the update section to update each object in the rectangleList. I am not sure how to format it because it is only drawing one and it does not move across the screen. I thought this section of code would work and loop through each object and make each one move but it does not.
for (int i = 0; i < rectangleList.Count; i++) {
enemyPosition = new Rectangle(rectangleList[i].X + 2, rectangleList[i].Y ,enemyPosition.Width,enemyPosition.Height);
} List<Rectangle> rectangleList;
protected override void Initialize() {
rectangleList = new List<Rectangle>();
[code].....
View 5 Replies
ADVERTISEMENT
May 13, 2014
Consider I have a rectangle like this:
Point p1(100,100);
Point p2(300,200);
Graph_lib::Rectangle r(p1,p2);
And also I have a function that takes a rectangle and returns a Point of that, say, top-left corner of that rectangle. For example:
Point N(Graph_lib::Rectangle R1);
My question is that, first, how to send that Rectangle r(p1,p2) to the Point N(Graph_lib::Rectangle R1) function? And then, how to return a Point from that function?
My IDE is visual studio 2012.
View 19 Replies
View Related
Sep 12, 2013
I would like to validate one of my approach.
I am creating a map like
std::map<unsigned int, double> key_value_pair;
I insert the value like as follows
1 25.0
0 30.0
5 90.0
2 22.0
Then i would like to read the value like as follows
double value = key_value_pair[0];
I am able to compile & there is no error.
question is does this will give 30.0 always.?
I am using VS2005.
View 7 Replies
View Related
Apr 22, 2014
I am trying to create a program that will read data from a text file into a string. Afterwards I need to sort the data in ascending order and print it. So far my program reads the data but I'm not sure how to go about indexing the array.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
[Code].....
View 3 Replies
View Related
Mar 6, 2015
For the past couple of weeks I have been working on a template to hold two-dimensional arrays. Right now I am puzzling over an indexing question.
There are many places in the template where I would like to use initializer_lists to refer to user-specified row and column ranges, particularly in member function arguments. A typical example would be a member function whose declaration would be along the lines of:
Code:
Array<Type>::some_function(std::initializer_list<int> columns, std::initializer_list<int> rows); which could get called via
Code:
arrayInstance.some_function({3:4}, {5:8});
It would be really nice to be able to use Matlab-style indexing to specify the last column, or the last row, in the Array object -- along the lines of
Code:
arrayInstance.some_function({3:4}, {5:END}); where END takes the value -1, and can be defined in Array, or somewhere else.
The way I have tackled this so far was to write myself an Indices PODS class with two elements to hold start and finish values, and a constructor-from-initializer_list that looks something like this:
Code:
Indices::Indices(std::initializer_list<int> range, int replace_value) {
int const *it = range.begin();
start = (*it == END) ? replace_value : *it ; ++it;
finish = (*it == END) ? replace_value : *it ;
...
}
So the elements of "range" give the values of Indices::start and Indices::finish -- but if either of them are entered as END by the user, they will be replaced by replace_value. (The default value of replace_value is END, so Indices::start and Indices::finish will never change if it is omitted.)
I also defined an Indices::endset(int) function to do the same thing for existing Indices objects:
Code:
Indices::endset(int replace_value) {
if (start == END) start = replace_value;
if (finish == END) finish = replace_value;
} Using Indices::endset, you can code up Array::some_function by modifying the above signature to something like
Code:
Array<Type>::some_function(Indices columns, Indices rows) {
columns.endset(this->M);
rows.endset(this->N);
...
}
This does work, and I've been able to use it in practice. However, it is klutzy. What I would really like to be able to do is have the Indices constructor handle value-replacements in "columns" and "rows", instead of needing to put calls to Indices::endset in every single Array<Type> member function that uses this approach.
The basic problem is that, when Array<Type>::some_function is called, there is no easy way of inserting Array<Type>::M and Array<Type>::N into the optional argument of the Indices constructor when "columns" and "rows" are being built.
The Indices class needs somehow to get access to these, and know which one is being used, M or N. So it needs to have some sort of deeper connection to Array<Type>, but I don't know what that connection should be.
View 2 Replies
View Related
Jun 14, 2013
I've spent some time trying to performance test various methods of loading / accessing a file, either into memory or through a memory mapped file, but I am having some trouble.
FILE * pFile;
std::ifstream ifs;
MapViewOfFile
I'm have trouble because Windows appears to cache the file, so I am getting very mixed results. Sometimes a huge file (100's MB's) will load quickly, other times almost instantly.
How to stop Windows from doing whatever it's doing, so I can see the real time taken to load/access a file from disk?
View 8 Replies
View Related
Nov 1, 2013
My below code is createing databases(database here is a kd tree) and indexing one image per database. I have two classes LastDatabaseTndexingPolicy and another forwardingDatabaseaccessor.cpp .
I am calling the GetDatabaseToAccess() function from forwardingDatabaseAccessor.cpp class .GetDatabaseToAccess() function is present in LastDatabaseTndexingPolicy class and it returns the database created as a pointer and using that database pointer we call another function which actually indexes the image to the database .
Now my issue is i am not able to have multiple threads act on the following functions as DatabaseAccessor_ptr db which is in the following file is coupled with two functions and however i put locks in the LastDatabaseTndexingPolicy file as below i end up getting synchronization issue ..........
Hence now i am using a single lock in forwardingDatabaseAccessor.cpp and serializing the code,. How can i change my design to parallelize this code .........
In ForwardingDatabaseAccessor.cpp we are calling function from LastDatabaseTndexingPolicy as shown below:-
DatabaseAccessor_ptr db is something which needs to be synchroinized. I tried createing 256 databases with one image each and when i run this code i ended up creating 175 databses and though i was restricting in code with locks that every database has only one image i ended up having two images in single database ..... ideally i had to get only one image per database but i got two images in few of them hence instead of 256 database this code created 175 or so databases.
indexing::IndexReturnValue ForwardDatabaseAccessor::index(cv::Mat image,
const std::string& imageName, features::Camera::Type indexCameraType,
features::Camera::Type recogCameraType) {
DatabaseAccessor_ptr db = this->IndexingPolicy_ptr->GetDBToIndex();
[Code] .....
View 1 Replies
View Related
Oct 4, 2014
the code draws rectangle or square it depends on you (column,row) then, put number in the center of the rectangle i don't want to extra space after putting one,two,three or four digits number in the center of the rectangle
#include <stdio.h>
int main(){
int i,j;
[Code]....
View 3 Replies
View Related
Sep 17, 2014
I'm trying to draw and pivot a rectangle. How to get the new coordinates if I turn it 90 degree for example?
From this:
To this:
This is not good because it will reduce it in size.
Code:
int size = 50;
if(b) // draw rectangle
{
POINT points[4] =
{{xCoord, yCoord},
[Code] ....
View 7 Replies
View Related
Jan 27, 2015
I'm trying to make a program that prints a rectangle using "*" asterisks. I am only allowed to use "for loops" and I simply cannot get this to work properly. Here is my code so far...
Code:
int main(void)
{
//RectangleSize represents the area of the rectangle(width*length)
int length, width, RectangleSize;
[Code].....
View 5 Replies
View Related
Nov 2, 2013
I am trying to create a rectangle with 3*5 dimension which would look like:
#####
#####
#####
I wanted to use for, and do while loop for that programming. I couldn't been able to create my desired dimension of 3*5.
//complier directives
#include<iostream>
#include<cstdlib>
using namespace std;
//main body
int main () {
//local identifiers
//complier directives
[Code] .....
View 5 Replies
View Related
Apr 6, 2013
how to use 3 variables to represent a rectangle in a grid instead of using 4. The traditional way is to use (x,y) (x2,y2). I propose using (x,l,h).In the traditional way as you probably know, (x,y) is the left op most corner, and (x2,y2) is the bottom right most corner. In the way I am proposing X is the left side, l is the length of the top side, and also the length of the bottom. 'h' is the height of the left and right. I think it's obvious how these three can define a rectangle same as the four.
View 2 Replies
View Related
Apr 26, 2012
I am making a game Pong, and have been struggling with the collision aspect between the baal hitting off the paddle. I have created a Class, to draw a rectangle, to work with collision however I dont know how to assign the rectangle to the images of the ball and paddle.
#include "stdafx.h"
#include <iostream>
#include <time.h>
#include <vector>
#include <cmath>
#include "gwin.h"
const int NUMBEROFBALLS = 1;
[Code] .....
View 1 Replies
View Related
Jan 30, 2015
I am new to C and am unfortunately racking my brain against this simple assignment. I believe the task is to produce a rectangle out of asterisks using while loops, yet I can only produce an "L" shape. We were given a code, with syntax errors included.We are to correct the errors and test.
Code:
#include <stdio.h>
/*Houghton, Micah*/
/*ET2560 - Cordova*/
/*Unit 5 Lab - Programming Loops*/
int main(void) {
int length, width;
int lcount, wcount;
[code]....
View 3 Replies
View Related
Feb 17, 2014
#include <iostream>
#include <cmath>
using namespace std;
//prototypes for all separate functions
int chooseFunc(int);
int chooseMethod(int);
int numRect(int);
[Code] .....
It seems that my program will ask the user for the number of rectangles and trapezoids but will fail to compute the area under the curve from the user input. Therefore, I believe I have a logical error somewhere or I'm forgetting to call something somewhere.
View 1 Replies
View Related
Oct 5, 2013
I want to detect colors that in the black rectangle. [URL] How can I do? What library should I use?
View 7 Replies
View Related
Oct 23, 2013
write a code that draw a block and diamond each in a single run by using '*' in recursion.
Below are one 10X10 rectangle and 6X4 diamond.
**********
**********
**********
**********
**********
**********
**********
**********
**********
**********
**
* *
* *
* *
* *
* *
* *
* *
**
Note: I couldn't write the diamond here appropriately somehow.
View 1 Replies
View Related
Mar 31, 2015
[URL] .... This is what I have so far, and it isn't incorrect, but how to improve this or make it more accurate?
// subtracting the area of two circles from a rectangle
#include <iostream>
using namespace std;
int main() {
cout << "This program is designed to calculate the area of a rectangle, to exclude the area of 2 circles that have been placed inside of the rectangle." << endl << endl;
[Code] .....
View 12 Replies
View Related
May 13, 2014
The problem says:
Define functions n(), s(), e(), w(), center(), ne(), se(), sw() and nw(). Each takes a Rectangle argument and returns a Point. These functions define connection points on and in the rectangle. For example, nw® is the northwest (top-left corner) of a rectangle called r.
I wrote below code for that:
#include <Simple_window.h>
Point n(const Graph_lib::Rectangle& r);
Point s(const Graph_lib::Rectangle& r);
Point e(const Graph_lib::Rectangle& r);
Point w(const Graph_lib::Rectangle& r);
Point ne(const Graph_lib::Rectangle& r);
Point se(const Graph_lib::Rectangle& r);
[Code]...
As you see, this just mark the top-left corner of the rectangle r. In other functions I need the specifications of that rectangle, for example its height and width. How to use these specs in those functions?
View 2 Replies
View Related
Nov 3, 2014
I've been given the task of converting a java application to a c# windows form application. The program displays a Mandelbrot which then allows the user to zoom into. I've managed to display the Mandelbrot and even zoom. However when dragging a box to zoom, the box its self doesn't show, meaning the user cannot see what area they will be zooming into.
I believe I need to call the update function which draws the rectangle as I drag however no matter what I try, I get errors from a red cross instead of the Mandelbrot to compile errors. Here is the code that I believe is relevant.
public void update(Graphics g) {
Color color = Color.White;
Pen myPen = new Pen(color);
g.DrawImage(myBitmap, 0, 0);
if (rectangle) {
[Code]....
View 3 Replies
View Related
Jul 5, 2013
Write a program using turbo c to draw a rectangle inside a circle..........
View 2 Replies
View Related
Apr 10, 2014
How to move a rectangle in TabPage ?
View 2 Replies
View Related
Jan 28, 2013
Write a program that prompts the user to input the length of a rectangle and the width of a rectangle and then displays the rectangle's area and perimeter. The program should be broken down in 3 parts:
1. Input the length and the width (two input statements)
2. Calculate the area & perimeter (results should be saved in variables
3. print results.
Format the output so the user can easily read the results. Use the tab escape so its easy to read.
---------------------------------------------------------------
So here's what I have so far. I have been stuck for two days
#include iostream
using namespace std;
int main () {
int double length;
int width;
int area;
int perimeter;
[Code] ....
I dont want to get a zero for not turning this in...
View 14 Replies
View Related
Mar 15, 2014
I am writing a program to calculate a rectangle's area.
Eg.
Enter top left point: 1 1 (User input)
Enter bottom right point: 2 -1 (User input)
Top Left x = 1.000000 y: 1.000000
Bottom Right x = 2.000000 y: -1.000000
Area = 2.000000 (Program output)
It keeps on prompting me my variable r is being used without being initialized, when I think I already did so.
Code:
typedef struct {
double x;
double y;
} Point;
[Code] ....
View 8 Replies
View Related
Oct 3, 2014
I want to put number in the center of the rectngle. Nonetheless, one space is residual.
Code:
#include <stdio.h>
nt main(){
int i,j;
int column,row;
int n;
printf("Enter column: ");
scanf("%d",&column);
[Code] .....
View 14 Replies
View Related
Mar 12, 2013
I'm trying to create a PPM image for a class assignment. A black rectangle with a circle at the point 225, 175 with a radius of 75. I have to use certain specific methods, so I can't use like Bresenham's really famous method for creating a circle.
The problem is that it compiles fine, and transfers to an image fine, but always says that I have a negative or zero image size.
Code:
#include "shapes.h"
int main () {
int i, j, x, y;
fprintf(stdout,"P6 width height 255
");
[Code] ....
And my header is:
Code:
#include <stdio.h>#include <math.h>
#define height 480
#define width 640
#define cy 175
#define cx 225
#define radius 75
The circle has to be filled in. I made it white. Also, i and j are unsused so far, so just ignore them.
View 1 Replies
View Related