Hit-Testing Problem in Ink API

G

Guest

I am not sure if this is too-granular a question to post to this group;
however, I did not see a Tablet-specific group. I am experiencing a problem
with the Microsoft.Ink.Ink.HitTest(Point [], float) method in the Tablet SDK.
I have pasted code below that verifies the problem using NUnit. In short,
performing a hit-test on a Stroke that I have manually created with a set of
input points is generating inconsistent results between
Ink.HitTest(Rectangle, float) and Ink.HitTest(Point [], float).

using System;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;

using Microsoft.Ink;

using NUnit.Framework;

namespace HitTestError
{
[TestFixture]
public class Error
{
#region Data Members

private Ink ink;
private Stroke lineStroke;

#endregion


/// <summary>
/// Set up the test fixture.
/// </summary>
[TestFixtureSetUp]
public void SetUp()
{
ink = new Ink();

// Create a stroke on the overlay
Point[] points = new Point[2];
points[0] = new Point(10, 10);
points[1] = new Point(30, 30);

// Create the stroke from the points
lineStroke = ink.CreateStroke(points);
}

/// <summary>
/// Tear down the test fixture.
/// </summary>
[TestFixtureTearDown]
public void TearDown()
{
ink.Dispose();
}

[Test]
public void Test()
{
// Create the rectangle to hit-test with
Rectangle rectangle = new Rectangle(new Point(9, 15), new
Size(10, 10));

/*
* X AXIS
* 10 20 30 40
* |---------------------------------->
* |
* |
* Y 10 | \
* | \
* A | XXXX\XXXX
* X | X \ X
* I 20 | X \
* S | X X \
* | XXXXXXXXX \
* | \
* 30 | \
* |
* |
* |
* 40 |
* |
* |
* |
* \/
*
* The stroke, initialized in the test fixture's set up method,
is described above by the slashes.
* The hit-rectangle is described by the Xs.
*
*/

// Perform a hit-test using the rectangle
Strokes strokes = ink.HitTest(rectangle, 100.0f);

// The hit-testing functions correctly here, returning an empty
Strokes object
Assert.AreEqual(0, strokes.Count);
Assert.IsFalse(strokes.Contains(lineStroke));

// Now, unpack the rectangle's points into a Point array and
feed them into the
// Ink objects hit-testing method

GraphicsPath path = new GraphicsPath();
path.AddRectangle(rectangle);

// Convert the path's points from float to int
PointF [] pathPoints = path.PathPoints;
Point[] points = new Point[pathPoints.Length];

for(int i=0; i < pathPoints.Length; ++i)
{
points.X = (int)pathPoints.X;
points.Y = (int)pathPoints.Y;
}

// Verify that the points match what is in the source rectangle
Assert.IsTrue(4 == points.Length);

Assert.AreEqual(points[0], rectangle.Location);

Assert.AreEqual(points[1].X, rectangle.X + rectangle.Width);
Assert.AreEqual(points[1].Y, rectangle.Y);

Assert.AreEqual(points[2].X, rectangle.X + rectangle.Width);
Assert.AreEqual(points[2].Y, rectangle.Y + rectangle.Height);

Assert.AreEqual(points[3].X, rectangle.X);
Assert.AreEqual(points[3].Y, rectangle.Y + rectangle.Height);

// Perform a hit-test using the points extracted from the
rectangle. The input points
// will be closed by the hit-testing method

/*
http://msdn.microsoft.com/library/d...icrosoft.ink/Classes/ink/Methods/hittest2.asp
*
* "If the selection boundary does not intersect itself, the
HitTest method adds a point to the end
* of the array to create a straight line from the first point
to the last point. If the boundary
* is a straight line with no area within the selection
boundary, no Stroke objects are selected."
*/

strokes = ink.HitTest(points, 100.0f);

// The returned Strokes object will incorrectly generate a hit
Assert.AreEqual(1, strokes.Count);
Assert.IsTrue(strokes.Contains(lineStroke));
}
}
}
 
G

Gary Chang[MSFT]

Hi,

I am afraid we don't support tabletpc issues in this newsgroup. I suggest
you can consult it in a more appropriate newsgroup, you may get better and
quicker help there:

microsoft.public.windows.tabletpc.developer


Thanks for your understanding!

Best regards,

Gary Chang
Microsoft Community Support
======================================================
PLEASE NOTE the newsgroup SECURE CODE and PASSWORD will be updated at 9:00
AM PST, February 14, 2006. Please complete a re-registration process by
entering the secure code mmpng06 when prompted. Once you have entered the
secure code mmpng06, you will be able to update your profile and access the
partner newsgroups.
======================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from this issue.
======================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
======================================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top