public static ClosestPtOnLine ( System.Point lineStart, System.Point lineEnd, System.Point p ) : System.Point | ||
lineStart | System.Point | |
lineEnd | System.Point | |
p | System.Point | |
Résultat | System.Point |
public static uint GetClosestPtOnBox(BoxCoords box, Point pIn, out Point pOut) { Point tmp; uint dist; uint bestdist = 0xFFFFFF; pOut = new Point(); tmp = ScummMath.ClosestPtOnLine(box.UpperLeft, box.UpperRight, pIn); dist = pIn.SquareDistance(tmp); if (dist < bestdist) { bestdist = dist; pOut = tmp; } tmp = ScummMath.ClosestPtOnLine(box.UpperRight, box.LowerRight, pIn); dist = pIn.SquareDistance(tmp); if (dist < bestdist) { bestdist = dist; pOut = tmp; } tmp = ScummMath.ClosestPtOnLine(box.LowerRight, box.LowerLeft, pIn); dist = pIn.SquareDistance(tmp); if (dist < bestdist) { bestdist = dist; pOut = tmp; } tmp = ScummMath.ClosestPtOnLine(box.LowerLeft, box.UpperLeft, pIn); dist = pIn.SquareDistance(tmp); if (dist < bestdist) { bestdist = dist; pOut = tmp; } return(bestdist); }
void FindPathTowardsOld(byte box1, byte box2, byte finalBox, out Point p2, out Point p3) { var gateA = new Point[2]; var gateB = new Point[2]; p2 = new Point(); p3 = new Point(); GetGates(_scumm.GetBoxCoordinates(box1), _scumm.GetBoxCoordinates(box2), gateA, gateB); p2.X = 32000; p3.X = 32000; // TODO: // next box (box2) = final box? // if (box2 == finalBox) // { // // In Indy3, the masks (= z-level) have to match, too -- needed for the // // 'maze' in the zeppelin (see bug #1032964). // if (_scumm.Game.Id != GID_INDY3 || _vm->getMaskFromBox(box1) == _vm->getMaskFromBox(box2)) // { // // Is the actor (x,y) between both gates? // if (compareSlope(_pos, _walkdata.dest, gateA[0]) != // compareSlope(_pos, _walkdata.dest, gateB[0]) && // compareSlope(_pos, _walkdata.dest, gateA[1]) != // compareSlope(_pos, _walkdata.dest, gateB[1])) // { // return; // } // } // } p3 = ScummMath.ClosestPtOnLine(gateA[1], gateB[1], Position); if (ScummMath.CompareSlope(Position, p3, gateA[0]) == ScummMath.CompareSlope(Position, p3, gateB[0])) { p2 = ScummMath.ClosestPtOnLine(gateA[0], gateB[0], Position); } }
internal bool CheckXYInBoxBounds(int boxnum, Point p) { // Since this method is called by many other methods that take params // from e.g. script opcodes, but do not validate the boxnum, we // make a check here to filter out invalid boxes. // See also bug #1599113. if (boxnum < 0 || boxnum == InvalidBox) { return(false); } var box = GetBoxCoordinates(boxnum); // Quick check: If the x (resp. y) coordinate of the point is // strictly smaller (bigger) than the x (y) coordinates of all // corners of the quadrangle, then it certainly is *not* contained // inside the quadrangle. if (p.X < box.UpperLeft.X && p.X < box.UpperRight.X && p.X < box.LowerRight.X && p.X < box.LowerLeft.X) { return(false); } if (p.X > box.UpperLeft.X && p.X > box.UpperRight.X && p.X > box.LowerRight.X && p.X > box.LowerLeft.X) { return(false); } if (p.Y < box.UpperLeft.Y && p.Y < box.UpperRight.Y && p.Y < box.LowerRight.Y && p.Y < box.LowerLeft.Y) { return(false); } if (p.Y > box.UpperLeft.Y && p.Y > box.UpperRight.Y && p.Y > box.LowerRight.Y && p.Y > box.LowerLeft.Y) { return(false); } // Corner case: If the box is a simple line segment, we consider the // point to be contained "in" (or rather, lying on) the line if it // is very close to its projection to the line segment. if ((box.UpperLeft == box.UpperRight && box.LowerRight == box.LowerLeft) || (box.UpperLeft == box.LowerLeft && box.UpperRight == box.LowerRight)) { Point tmp; tmp = ScummMath.ClosestPtOnLine(box.UpperLeft, box.LowerRight, p); if (p.SquareDistance(tmp) <= 4) { return(true); } } // Finally, fall back to the classic algorithm to compute containment // in a convex polygon: For each (oriented) side of the polygon // (quadrangle in this case), compute whether p is "left" or "right" // from it. if (!ScummMath.CompareSlope(box.UpperLeft, box.UpperRight, p)) { return(false); } if (!ScummMath.CompareSlope(box.UpperRight, box.LowerRight, p)) { return(false); } if (!ScummMath.CompareSlope(box.LowerRight, box.LowerLeft, p)) { return(false); } if (!ScummMath.CompareSlope(box.LowerLeft, box.UpperLeft, p)) { return(false); } return(true); }