Unity3d Creating a text on mouse position - c#

In 9 line FIXME_VAR_TYPE text ="PUT TEXT HERE";
shows error which is in below image , Can anybody solve this issue?
This is the error .
I am trying to change it String and var but also give error.

This FIXME_VAR_TYPE does not exist currently.
The type or namespace name 'FIXME_VAR_TYPE'
as the error says...
So here's how you can fix it:
On lines 9 and 10 you seem to be trying to use the fields as strings.
This is how it should look like
string text = "PUT TEXT HERE" : line 9
private string currentToolTipText = "" : line 10
On lines 36 and 37 you're using Event.current.mousePosition that is a Vector2 that has two float components (X and Y).
This is how it should look like:
float x = Event.current.mousePosition.x : line 36
float y = Event.current.mousePosition.y : line 37

Related

How do I calculate correct with Modulus %? C# Console App

how do I get the correct output when doing equations with modulus?
This is made in a Console Application.
For example:
float equation = (35 + 5) % 3;
output: 1, when the correct answer should be 1.2.
I've tried
float equation = (35 + 5) % 3f;
or
Console.WriteLine((float)equation);
But I dont really know how to make it work. Super grateful for any response.
Modulus give you the rest of an integer division:
40/3 = 13
13 * 3 = 39
40 - 39 = 1
1 is the rest

Where is UWP MapControl antialiasing property?

I work with UWP MapControl and adding some MapPolylines.
And they looks ugly (see pic below)
I assume should be kind of antialiasing property but cannot find it here.
Please help and thank you!
C#
var mapPolyline = new MapPolyline();
var geoPositions = new List<BasicGeoposition>();
foreach (var vertex in polyLine.Vertex)
{
// adding BasicGeopositions...
};
mapPolyline.StrokeColor = Colors.Black;
mapPolyline.StrokeThickness = 1;
mapPolyline.Path = new Geopath(geoPositions);
((MapElementsLayer)impotMapLayer).MapElements.Add(mapPolyline);
UPDATE #1 based on the answer
I have investigated this article "Overlay tiled images on a map" and also
this one "MapTileBitmapRequestedEventArgs Class" and cannot get the clear definition of the X and Y of "MapTileBitmapRequestedEventArgs Class"
The article says
X Gets the X value of the requested tile.
Y Gets the Y value of the requested tile.
Using MSDN example from here I get following log for X, Y, Zoom
X 6073 Y 2617 Zoom 13
X 6072 Y 2616 Zoom 13
X 6071 Y 2615 Zoom 13
X 6071 Y 2617 Zoom 13
X 6072 Y 2614 Zoom 13
X 6073 Y 2615 Zoom 13
X 6071 Y 2616 Zoom 13
X 6073 Y 2614 Zoom 13
X 6072 Y 2615 Zoom 13
and etc
Would you mind clarify what those numbers are exactly and how I can associate it with geolocations set of vertices in memory if I want create tile-image only, please?
(My polylines set already calculated in geopoints.)
Thank you very much!
UPDATE #2 Here is the solution
First of all I read this article https://learn.microsoft.com/en-us/bingmaps/articles/bing-maps-tile-system?redirectedfrom=MSDN
So we need TileSystem to make series of convertions
namespace Microsoft.MapPoint
{
static class TileSystem
...
The X and Y of MapTileBitmapRequestedEventArgs are Tile's XY we have to pass to TileSystem.TileXYToPixelXY(args.X, args.Y, out int pixelX, out int pixelY);
The final code is following based on https://learn.microsoft.com/en-us/windows/uwp/maps-and-location/overlay-tiled-images
private async void customDataSource_BitmapRequestedAsync(CustomMapTileDataSource sender, MapTileBitmapRequestedEventArgs args)
{
var deferral = args.Request.GetDeferral();
TileSystem.TileXYToPixelXY(args.X, args.Y, out int pixelX, out int pixelY);
TileSystem.PixelXYToLatLong(pixelX, pixelY, args.ZoomLevel, out double lat, out double lng);
Debug.WriteLine($"lat {lat} lng {lng} Zoom {args.ZoomLevel}");
// next step is to extract from my custom array polylines accroding to TileSystem.PixelXYToLatLong
// and finally pass it inside of CreateBitmapAsStreamAsync(array to draw);
args.Request.PixelData = await CreateBitmapAsStreamAsync(array to draw);
deferral.Complete();
}
Currently MapPolylines are drawn without antialiasing and there is no setting to change that behavior.
Looking at your screenshot, you may be better served by using a custom tile layer. See CustoMapTileDatasource here: https://learn.microsoft.com/en-us/windows/uwp/maps-and-location/overlay-tiled-images
You can draw each tile in a callback using whatever method you like including antialiasing. It will also tend to perform better for a large collection of static lines like the topographic contours in your example

Combinations in n-dimensions - How determine if Points see each other (If they are on same axis) [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
In n-dimensional grid (Max. 10^7 dimensions) are two points. They have imaginary sensors on every axis.
I need algorithm what will calculate all possible options when these two points can spot themselves.
Formal written from my task document (translated to english):
Let A with the coordinates (a1, a2, ..., an) and B with the coordinates (b1, b2, ..., bn)
are two points in n-dimensional space and exists i ∈ 1, 2, ..., n such that ai = bi then A and B sees each other
Example:
In 1-dimensional space with length 10 is total 45 combinations how to put 2 points when they see each other (They see each other every time).
It is easy combination 10C2 (10 of 2) = 45
How to calculate it in 2,3,4,...,10^7 dimensions by program (I prefer C#)?
Proper test data what i have:
Input:
1
10
Output: 45
Input:
2
5 8
Output: 220
Input:
3
8 12 11
Output: 14784
More explanation:
Output is number of combinations when two points in space see each other (are on same axis). In 1 dimensional space is only one axis so they see each other always. In 2 dimensional space are 2 axis, so they can see each other only in some case
This image example explaining more than text i think
I'm sure it's correct.
C(x,y) is combination x of y.
Lets say we have one dimention, lets call it X of lenght 8. There are C(8,2) = 8*7/2 = 28 possibilities to see eachother.
When we add second dimention, named Y, of lenght 12 now we have 12 lines parallel to X. So we have 12*28=336 possibilities to being found on all the lines parallel to X. Now, on Y dimention we have C(12,2) = 66 possibilities. And there are 8 lines like that so 66*8=528.
In total: 336 +528= 846 possibilities
Now lets add another dimention, labeled as Z with lenght of 11. There are C(1,2) = 11*10/2 = 55 in one line and (atention) we have 8*12 lines like that. So is it's 55*8*12 = 5280 possibilities!
Now in total we have:
Paralel to X axis: C(8,2)*11*12 = 3696
Parallel to Y axis C(12,2)*8*11 = 5808
Parallel to Z axis C(11,2)*8*12 = 5280
TOTAL = 14784
In general the formula for n dimentions with n1,n2... nk lenghts is:
Sum of C(ni,2) * (n1*n2...*nk)/ni
Or shorter:
sum of (n1*n2*n3...nk)/2 * (ni-1)
example:
dimentions with 3,8,9,11:
(3*8*9*11)/2*(3-1) = 2376
(3*8*9*11)/2*(8-1) = 8316
(3*8*9*11)/2*(9-1) = 9504
(3*8*9*11)/2*(11-1) = 11880
Total = 32076
The easiest equasion:
(n1*n2*n3...ni)(n1+n2+...ni - k)/2, where ni are lenghs, and k is number of dimentions
I have create sample code so you can try it. i have check it's working fine.
Equation is : C(n,r)=n!/(r!(n−r)!)
Example:
1. 10C2=45
2. 10C3=120
public void Calc()
{
int result= nCr(10, 3);
}
public int nCr(int n,int r )
{
int nValue=1;
int rValue = 1;
for (int i = n-r+1; i <= n; i++)
{
nValue = nValue*i;
}
for (int i = 1; i <= r; i++)
{
rValue = rValue*i;
}
return nValue/rValue;
}

String to float C#, odd result [duplicate]

This question already has answers here:
C# String to Float Conversion
(5 answers)
Closed 7 years ago.
In my code I want to convert a string to a float. But when I conver something like 49.5 to a float, it gives the output 495 instead of 49.5 how can I solve this?
float.Parse, Single.Parse or Convert.ToSingle(); give all the same result...
String[] splittedLine = new String[25];
splittedLine = foundLine.Split('-');
float Z = float.Parse(splittedLine[2]);
float X = float.Parse(splittedLine[3]);
float Y = Single.Parse(splittedLine[4]);
PointF Center = new PointF(X /2, Y /2);
the values in the X & Y are or a full number (example 207 or 49.5);
foundLine is a line from a textdocument.
So how can I that the value from the text file (49.5) will stay 49.5 instead of 495?
Probably your system has a different format for fractional numbers than what your file was written with.
By default, float.Parse will use your system's locale settings to decide on this. To manually specify a format, you can use another overload:
float.Parse(splittedLine[2], CultureInfo.InvariantCulture);

Why is the barcode text value not printing beneath the barcode?

I am printing using the Windows Compact Framework to a Zebra belt printer using the OpenNetCF serial port class and CPCL. The printed label is pretty much as it should be, but the barcode value is not printing beneath the barcode as it should.
I create an ArrayList of commands to be sent the printer and then pass them one at a time to the serial port. If the controls that supply the values are empty, I use some dummy data, like so:
private void btnPrint_Click(object sender, System.EventArgs e)
{
string listPrice = txtList.Text;
if (listPrice.Trim() == string.Empty)
{
listPrice = "3.14";
}
string description = txtDesc.Text;
if (description.Trim() == string.Empty)
{
description = "The Life of Pi";
}
string barcode = txtUPC.Text;
if (barcode.Trim() == string.Empty)
{
barcode = "01701013992";
}
ArrayList arrList = new ArrayList();
arrList.Add("! 0 200 200 120 1\r\n"); // replace 120 with label height if different than 1.25"/120 pixels (at 96 pixels per inch)
arrList.Add("RIGHT\r\n");
arrList.Add(string.Format("TEXT 0 5 0 0 {0}\r\n", listPrice));
arrList.Add("LEFT\r\n");
arrList.Add(string.Format("TEXT 0 0 0 52 {0}\r\n", description));
arrList.Add("CENTER\r\n");
arrList.Add("BARCODE-TEXT 0 0 5\r\n");
arrList.Add(string.Format("BARCODE 128 1 1 50 0 77 {0}\r\n", barcode));
arrList.Add("FORM\r\n");
arrList.Add("PRINT\r\n");
PrintUtils pu = new PrintUtils();
pu.PrintLabel(arrList);
}
public void PrintLabel(ArrayList linesToSend)
{
using (SerialPort serialPort = new SerialPort())
{
serialPort.BaudRate = 19200;
serialPort.Handshake = Handshake.XOnXOff;
serialPort.DataBits = 8;
serialPort.Parity = Parity.None;
serialPort.StopBits = StopBits.One;
serialPort.PortName = "COM1:";
serialPort.Open();
Thread.Sleep(500); //this may not even be necessary and, if so, a different value may be better
foreach (string line in linesToSend)
{
serialPort.Write(line);
}
serialPort.Close();
}
}
...the problem is that the label (when I allow the dummy data to print) should be:
3.14
The Life of Pi
<barcode here>
01701013992
...and here's what is really printing:
3.14
The Life of Pi
<barcode here>
[blank]
So the problem is that the barcode as text ("01701013992") is not printing beneath the barcode.
Does anybody know why this is occurring even though I've got a BARCODE-TEXT command in there, and how to rectify it?
UPDATE
A key piece of info came my way, namely that the label height (in my case) should be 254, not 120 (for my 1.25" in height label, I was calculating based on 96 pixels == 1 inch, but in actuality this particular printer is 203 dpi, so 1.25 X == 254 (more precisely 253.75, but 254 is close enough).
So the code has changed to this:
// Command args (first line, prepended with a "!": horizontal (X) pos, resolution, resolution, label height, copies
// TEXT args are: fontNumber, fontSizeIdentifier, horizontal (X) pos, vertical (Y) pos
// BARCODE args are: barcodeType, unitWidthOfTheNarrowBar, ratioOfTheWideBarToTheNarrowBar, unitHeightOfTheBarCode,
// horizontal (X) pos, vertical (Y) pos, barcodeValue
// BARCODE-TEXT args are: fontNumber, fontSizeIdentifier, space between barcode and -text
// 1 inch = 203 dots (Zebra QL220 is a 203 dpi printer); font 4,3 == 90 pixels; font 2,0 == 12 pixels
arrList.Add("! 0 200 200 254 1\r\n"); // 203 dpi X 1.25 = 254
arrList.Add("RIGHT\r\n");
arrList.Add(string.Format("TEXT 4 3 0 0 {0}\r\n", listPrice));
arrList.Add("LEFT\r\n");
arrList.Add(string.Format("TEXT 2 0 0 100 {0}\r\n", description));
arrList.Add("BARCODE-TEXT 2 0 5\r\n");
arrList.Add("CENTER\r\n");
arrList.Add(string.Format("BARCODE 128 1 1 50 0 120 {0}\r\n", barcode));
arrList.Add("FORM\r\n");
arrList.Add("PRINT\r\n");
...but I'm STILL not seeing the description label - except for a lonely "P" below the "3" and the "." in the price.
Are my calculations wrong, or what?
Here's what I'm thinking I have:
Label is 254 dots/1.25" high.
First line starts at YPos 0 and prints "3.14" in a 90 pixel font, right-aligned. That prints fine.
Second line starts at YPos 100 (10 dots below the 90-dot first line), left-aligned. All I see is the aforementioned "P" in what seems to be the right size.
Third line is the barcode, at YPos (120), centered; prints fine
Fourth/final line is the barcode as text beneath the barcode proper, centered; prints fine.
NOTE: I can't put a bounty on this yet, but anybody who solves it I will award 100 points as soon as I'm able (in two days, I reckon).
It turns out that the problem was that I was using font # 2 in order to get a font size of 12 (it is the only font that provides that size). The problem with font # 2 is that it is "OCR-A" and as such only prints certain characters. In the string I was passing as a test ("The Life of Pi", to go along with the list price of 3.14), the only character it recognizes in that string is P. So that's why it's the only one I saw.
I had to increase my font size to the next available, namely 24, using font #5 (Manhattan) or 7 (Warwick).
"mk" from zebra provided me with this information ("The OCR font is a special font that doesn’t include all characters that you are trying to print.").
If you look at Appendix D in the CPCL programming manual, it does show font #2 as being "OCR-A," but it didn't dawn on me that that meant it's character set precluded most alpha characters. Even if that's obvious to some, it seems to me that should be emphasized in the manual: When printing text, don't use font #2!
Note: Font #6 (MICR) is also to be avoided for text.

Categories