public virtual void LongPointEqualsAndHashCodeToAnotherNotEqualPointTest() { IntPoint first = new IntPoint(1, 5); IntPoint second = new IntPoint(0, 5); NUnit.Framework.Assert.IsFalse(first.Equals(second)); NUnit.Framework.Assert.IsFalse(second.Equals(first)); second = new IntPoint(1, 0); NUnit.Framework.Assert.IsFalse(first.Equals(second)); NUnit.Framework.Assert.IsFalse(second.Equals(first)); // Do not check the hash code method, because it works differently depending on the framework }
public virtual void LongPointEqualsAndHashCodeItselfTest() { IntPoint lp = new IntPoint(1, 5); NUnit.Framework.Assert.IsTrue(lp.Equals(lp)); NUnit.Framework.Assert.AreEqual(lp.GetHashCode(), lp.GetHashCode()); }
public bool Equals(EditPictureProperties other) { return(wannaOffset.Equals(other.wannaOffset) && FlipX == other.FlipX && FlipY == other.FlipY && ModeType == other.ModeType && ReferencePositionType == other.ReferencePositionType); }
public virtual void LongPointEqualsAndHashCodeToAnotherEqualPointTest() { IntPoint first = new IntPoint(1, 5); IntPoint second = new IntPoint(1, 5); NUnit.Framework.Assert.IsTrue(first.Equals(second)); NUnit.Framework.Assert.IsTrue(second.Equals(first)); NUnit.Framework.Assert.AreEqual(first.GetHashCode(), second.GetHashCode()); }
public int ComparePoints(IntPoint a, IntPoint b) { if (a.Equals(b)) { return(0); } // use longs to guard against int-underflow double thetaA = Math.Atan2((long)a.Y - lowestPoint.Y, (long)a.X - lowestPoint.X); double thetaB = Math.Atan2((long)b.Y - lowestPoint.Y, (long)b.X - lowestPoint.X); if (thetaA < thetaB) { return(-1); } else if (thetaA > thetaB) { return(1); } else { // collinear with the 'lowest' point, let the point closest to it come first // use longs to guard against int-over/underflow double distanceA = Math.Sqrt((((long)lowestPoint.X - a.X) * ((long)lowestPoint.X - a.X)) + (((long)lowestPoint.Y - a.Y) * ((long)lowestPoint.Y - a.Y))); double distanceB = Math.Sqrt((((long)lowestPoint.X - b.X) * ((long)lowestPoint.X - b.X)) + (((long)lowestPoint.Y - b.Y) * ((long)lowestPoint.Y - b.Y))); if (distanceA < distanceB) { return(-1); } else { return(1); } } }
public virtual void LongPointEqualsToAnotherClassTest() { IntPoint lp = new IntPoint(1, 5); NUnit.Framework.Assert.IsFalse(lp.Equals("")); }
public virtual void LongPointEqualsToNullTest() { IntPoint lp = new IntPoint(1, 5); NUnit.Framework.Assert.IsFalse(lp.Equals(null)); }
private void AddOutPt(TEdge e, IntPoint pt) { Contract.Requires(e != null); Contract.Requires(e.OutIdx < 0 || e.OutIdx < _polyOuts.Count); var toFront = e.Side == EdgeSide.Left; if (e.OutIdx < 0) { var outRec = CreateOutRec(); e.OutIdx = outRec.Idx; var op = new OutPt(); outRec.Pts = op; op.Pt = pt; op.Next = op; op.Prev = op; SetHoleState(e, outRec); } else { var outRec = _polyOuts[e.OutIdx]; var op = outRec.Pts; if (toFront && pt.Equals(op.Pt) || (!toFront && pt.Equals(op.Prev.Pt))) return; var op2 = new OutPt { Pt = pt, Next = op, Prev = op.Prev }; op2.Prev.Next = op2; op.Prev = op2; if (toFront) outRec.Pts = op2; } }
private static bool Pt3IsBetweenPt1AndPt2(IntPoint pt1, IntPoint pt2, IntPoint pt3) { if (pt1.Equals(pt3) || pt2.Equals(pt3)) return true; else if (pt1.X != pt2.X) return pt1.X < pt3.X == pt3.X < pt2.X; else return pt1.Y < pt3.Y == pt3.Y < pt2.Y; }
/// <summary> /// This method generates move commands ehich try to get from a given point to another whilst staying on the outline /// of an island /// </summary>s /// <param name="p1">The starting point</param> /// <param name="p2">The ending point</param> /// <param name="zPos">The z position of the layer</param> /// <param name="outlineLines">The outline linesegments of the island</param> private static void generateMovesBetweenPoints(IntPoint p1, IntPoint p2, long zPos, List <List <LineSegment> > outlineLines, int moveSpeed, ref Queue <MoveSegment> moveQueue) { //TODO: sometimes it appears as if though when there are two points on the smae line a move if first genertated from p1 to the end (or start) of the //line and then back, there sould instead be a direct move from p1 to p2 //If the two points are already equal then a move between them is not neccesary if (p1.Equals(p2)) { return; } /*//If we are in plotting mode then we only need to lift up the pen and create a direct move * if (Global.Values.materialType == MaterialType.Pen) * { * //Retract / lift up the pen * Global.Values.MoveSegmentList.Add(new MoveSegment()); * * //Make a direct move * var vec1 = new Vector3(p1.X, p1.Y, zPos + 1); * var vec2 = new Vector3(p2.X, p2.Y, zPos + 1); * Global.Values.MoveSegmentList.Add(new MoveSegment(vec1, vec2, moveSpeed)); * * //Move the pen down again * vec1 = new Vector3(p2.X, p2.Y, zPos + 1); * vec2 = new Vector3(p2.X, p2.Y, zPos); * Global.Values.MoveSegmentList.Add(new MoveSegment(vec1, vec2, moveSpeed)); * * return; * }*/ //If there are no outline linesegments then we need to generate a direct move if (outlineLines.Count < 1) { var vec1 = new Vector3(p1.X, p1.Y, zPos + 1); //); var vec2 = new Vector3(p2.X, p2.Y, zPos + 1); //); moveQueue.Enqueue(new MoveSegment(vec1, vec2, moveSpeed)); return; } //First find out which point on which polygon is closest to the first point List <LineSegment> closestOutline = new List <LineSegment>(); IntPoint closestPoint = new IntPoint(); LineSegment closestLine = new LineSegment(new IntPoint(), new IntPoint()); double closesDistance = double.MaxValue; foreach (List <LineSegment> lines in outlineLines) { foreach (LineSegment line in lines) { IntPoint newPoint; var distance = distanceToLine(line, p1, out newPoint); if (distance < closesDistance) { closesDistance = distance; closestPoint = newPoint; closestOutline = lines; closestLine = line; } } } //We now need to create a move from the first point to the closest point on the polygon var v1 = new Vector3(p1.X, p1.Y, zPos); var v2 = new Vector3(closestPoint.X, closestPoint.Y, zPos); moveQueue.Enqueue(new MoveSegment(v1, v2, moveSpeed)); //Next we need to determine which point point on the above determined polygon is closest to the second IntPoint closestPoint2 = new IntPoint(); LineSegment closestLine2 = new LineSegment(new IntPoint(), new IntPoint()); closesDistance = double.MaxValue; foreach (LineSegment line in closestOutline) { IntPoint newPoint; var distance = distanceToLine(line, p2, out newPoint); if (distance < closesDistance) { closesDistance = distance; closestPoint2 = newPoint; closestLine2 = line; } } //Create an endless looping warpper for the list LoopingList <LineSegment> loopingList = new LoopingList <LineSegment>(ref closestOutline); //We now need to determine the index of the two lines int lineIndex = closestOutline.IndexOf(closestLine); int lineIndex2;// = closestOutline.IndexOf(closestLine2); //We now need to add move segments for each line on the outline between the two closest points //A while ago we moved to closestPoint so it is now our last point IntPoint lastPoint = closestPoint; //For each line between the two points we have to move from the last point to the second point on the list int indexDiff = loopingList.distanceBetweenElements(closestLine, closestLine2, out lineIndex2); //lineIndex2 - lineIndex; if (indexDiff > 0) { for (int i = lineIndex; i < lineIndex2; i++) { v1 = new Vector3(lastPoint.X, lastPoint.Y, zPos); var point2 = loopingList.elementAtIndex(i).Point2; v2 = new Vector3(point2.X, point2.Y, zPos); moveQueue.Enqueue(new MoveSegment(v1, v2, moveSpeed)); lastPoint = point2;//closestOutline[i].Point2; } } else if (indexDiff < 0) { for (int i = lineIndex; i > lineIndex2; i--) { v1 = new Vector3(lastPoint.X, lastPoint.Y, zPos); var point1 = loopingList.elementAtIndex(i).Point1; //v2 = new Vector3(closestOutline[i].Point1.X, closestOutline[i].Point1.Y, zPos); v2 = new Vector3(point1.X, point1.Y, zPos); moveQueue.Enqueue(new MoveSegment(v1, v2, moveSpeed)); //Global.Values.MoveSegmentList.Add(new MoveSegment(v1, v2, moveSpeed)); lastPoint = point1;//closestOutline[i].Point1; } } //Next we have to move from the last point to the closest point 2 v1 = new Vector3(lastPoint.X, lastPoint.Y, zPos); v2 = new Vector3(closestPoint2.X, closestPoint2.Y, zPos); moveQueue.Enqueue(new MoveSegment(v1, v2, moveSpeed)); //We then finally have to move from the last point 2 to the closest point 2 v1 = new Vector3(closestPoint2.X, closestPoint2.Y, zPos); v2 = new Vector3(p2.X, p2.Y, zPos); moveQueue.Enqueue(new MoveSegment(v1, v2, moveSpeed)); }