Skip to content

Commit 4b954fc

Browse files
authored
Merge pull request #105 from Azure-Samples/stringToPoints
String to points
2 parents c225e3e + ee0fd89 commit 4b954fc

File tree

7 files changed

+278
-324
lines changed

7 files changed

+278
-324
lines changed

dotnet/InkRecognition/uwp-app/cs/JSON/Converter/InkPointsToStringConverter.cs

Lines changed: 0 additions & 40 deletions
This file was deleted.

dotnet/InkRecognition/uwp-app/cs/JSON/Format/InkRecognizerStroke.cs

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,25 @@
88

99
namespace Contoso.NoteTaker.JSON.Format
1010
{
11+
public class InkRecognizerPoint
12+
{
13+
[JsonIgnore]
14+
private double x;
15+
[JsonIgnore]
16+
private double y;
17+
[JsonProperty(PropertyName = "x")]
18+
public double X { get { return x; } }
19+
20+
[JsonProperty(PropertyName = "y")]
21+
public double Y { get { return y; } }
22+
23+
public InkRecognizerPoint(double x, double y)
24+
{
25+
this.x = x;
26+
this.y = y;
27+
}
28+
}
29+
1130
public class InkRecognizerStroke
1231
{
1332
[JsonIgnore]
@@ -22,8 +41,8 @@ public class InkRecognizerStroke
2241
[JsonProperty(PropertyName ="kind", NullValueHandling = NullValueHandling.Ignore)]
2342
public StrokeKind? Kind { get; set; } = null;
2443

25-
[JsonProperty(PropertyName = "points"), JsonConverter(typeof(InkPointsToStringConverter))]
26-
public IReadOnlyList<InkPoint> Points { get; protected set; }
44+
[JsonProperty(PropertyName = "points", NullValueHandling = NullValueHandling.Ignore)]
45+
public IReadOnlyList<InkRecognizerPoint> Points { get; protected set; }
2746

2847
public InkRecognizerStroke(InkStroke stroke, float DpiX, float DpiY)
2948
{
@@ -33,18 +52,17 @@ public InkRecognizerStroke(InkStroke stroke, float DpiX, float DpiY)
3352
Points = ConvertPixelsToMillimeters(pointsInPixels, DpiX, DpiY).AsReadOnly();
3453
}
3554

36-
private List<InkPoint> ConvertPixelsToMillimeters(IReadOnlyList<InkPoint> pointsInPixels, float DpiX, float DpiY)
55+
private List<InkRecognizerPoint> ConvertPixelsToMillimeters(IReadOnlyList<InkPoint> pointsInPixels, float DpiX, float DpiY)
3756
{
38-
var transformedInkPoints = new List<InkPoint>();
57+
var transformedInkPoints = new List<InkRecognizerPoint>();
3958
const float inchToMillimeterFactor = 25.4f;
4059

4160

4261
foreach (var point in pointsInPixels)
4362
{
4463
var transformedX = (point.Position.X / DpiX) * inchToMillimeterFactor;
4564
var transformedY = (point.Position.Y / DpiY) * inchToMillimeterFactor;
46-
var transformedPoint = new Point(transformedX, transformedY);
47-
var transformedInkPoint = new InkPoint(transformedPoint, point.Pressure);
65+
var transformedInkPoint = new InkRecognizerPoint(transformedX, transformedY);
4866

4967
transformedInkPoints.Add(transformedInkPoint);
5068
}

dotnet/InkRecognition/uwp-app/cs/NoteTaker.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@
117117
</PropertyGroup>
118118
<ItemGroup>
119119
<Compile Include="JSON\Converter\InkRecognitionResponseConverter.cs" />
120-
<Compile Include="JSON\Converter\InkPointsToStringConverter.cs" />
121120
<Compile Include="JSON\Format\Alternates.cs" />
122121
<Compile Include="App.xaml.cs">
123122
<DependentUpon>App.xaml</DependentUpon>

dotnet/InkRecognition/wpf-app/src/JSON/Converter/InkPointsToStringConverter.cs

Lines changed: 0 additions & 40 deletions
This file was deleted.

dotnet/InkRecognition/wpf-app/src/JSON/Format/InkRecognizerStroke.cs

Lines changed: 61 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -8,49 +8,67 @@
88

99
namespace Contoso.NoteTaker.JSON.Format
1010
{
11-
public class InkRecognizerStroke
12-
{
13-
[JsonIgnore]
14-
private InkStroke inkStrokeInternal { get; set; }
15-
16-
[JsonProperty(PropertyName = "id")]
17-
public UInt64 Id { get { return inkStrokeInternal.Id; } }
18-
19-
[JsonProperty(PropertyName = "language", NullValueHandling = NullValueHandling.Ignore)]
20-
public string Language { get; set; } = null;
21-
22-
[JsonProperty(PropertyName ="kind", NullValueHandling = NullValueHandling.Ignore)]
23-
public StrokeKind? Kind { get; set; } = null;
24-
25-
[JsonProperty(PropertyName = "points"), JsonConverter(typeof(InkPointsToStringConverter))]
26-
public IReadOnlyList<InkPoint> Points { get; protected set; }
27-
28-
public InkRecognizerStroke(InkStroke stroke, float DpiX, float DpiY)
29-
{
30-
inkStrokeInternal = stroke;
31-
32-
var pointsInPixels = inkStrokeInternal.GetInkPoints();
33-
Points = ConvertPixelsToMillimeters(pointsInPixels, DpiX, DpiY).AsReadOnly();
34-
}
35-
36-
private List<InkPoint> ConvertPixelsToMillimeters(IReadOnlyList<InkPoint> pointsInPixels, float DpiX, float DpiY)
37-
{
38-
var transformedInkPoints = new List<InkPoint>();
39-
const float inchToMillimeterFactor = 25.4f;
40-
41-
42-
foreach (var point in pointsInPixels)
43-
{
44-
var transformedX = (point.Position.X / DpiX) * inchToMillimeterFactor;
45-
var transformedY = (point.Position.Y / DpiY) * inchToMillimeterFactor;
46-
var transformedPoint = new Point(transformedX, transformedY);
47-
var transformedInkPoint = new InkPoint(transformedPoint, point.Pressure);
48-
49-
transformedInkPoints.Add(transformedInkPoint);
50-
}
51-
52-
return transformedInkPoints;
53-
}
11+
public class InkRecognizerPoint
12+
{
13+
[JsonIgnore]
14+
private double x;
15+
[JsonIgnore]
16+
private double y;
17+
[JsonProperty(PropertyName = "x")]
18+
public double X { get { return x; } }
19+
20+
[JsonProperty(PropertyName = "y")]
21+
public double Y { get { return y; } }
22+
23+
public InkRecognizerPoint(double x, double y)
24+
{
25+
this.x = x;
26+
this.y = y;
27+
}
28+
}
29+
30+
public class InkRecognizerStroke
31+
{
32+
[JsonIgnore]
33+
private InkStroke inkStrokeInternal { get; set; }
34+
35+
[JsonProperty(PropertyName = "id")]
36+
public UInt64 Id { get { return inkStrokeInternal.Id; } }
37+
38+
[JsonProperty(PropertyName = "language", NullValueHandling = NullValueHandling.Ignore)]
39+
public string Language { get; set; } = null;
40+
41+
[JsonProperty(PropertyName = "kind", NullValueHandling = NullValueHandling.Ignore)]
42+
public StrokeKind? Kind { get; set; } = null;
43+
44+
[JsonProperty(PropertyName = "points", NullValueHandling = NullValueHandling.Ignore)]
45+
public IReadOnlyList<InkRecognizerPoint> Points { get; protected set; }
46+
47+
public InkRecognizerStroke(InkStroke stroke, float DpiX, float DpiY)
48+
{
49+
inkStrokeInternal = stroke;
50+
51+
var pointsInPixels = inkStrokeInternal.GetInkPoints();
52+
Points = ConvertPixelsToMillimeters(pointsInPixels, DpiX, DpiY).AsReadOnly();
53+
}
54+
55+
private List<InkRecognizerPoint> ConvertPixelsToMillimeters(IReadOnlyList<InkPoint> pointsInPixels, float DpiX, float DpiY)
56+
{
57+
var transformedInkPoints = new List<InkRecognizerPoint>();
58+
const float inchToMillimeterFactor = 25.4f;
59+
60+
61+
foreach (var point in pointsInPixels)
62+
{
63+
var transformedX = (point.Position.X / DpiX) * inchToMillimeterFactor;
64+
var transformedY = (point.Position.Y / DpiY) * inchToMillimeterFactor;
65+
var transformedInkPoint = new InkRecognizerPoint(transformedX, transformedY);
66+
67+
transformedInkPoints.Add(transformedInkPoint);
68+
}
69+
70+
return transformedInkPoints;
71+
}
5472
}
5573

5674
public enum StrokeKind

0 commit comments

Comments
 (0)