/// <summary> /// Returns true if the given <see cref="Vec2D"/> is within this <see cref="Viewport"/>'s bounds. /// </summary> /// <param name="vec">The vec.</param> /// <returns>True if within, else false.</returns> public bool Contains(Vec2D vec) { return ((vec - Position) / Radius).LengthSq() <= 1; }
/// <summary> /// Multiplies the given view's size by the given value, about the given vector. /// </summary> /// <param name="val">The value.</param> /// <param name="vec">The anchor vec.</param> /// <returns>The resized view.</returns> public Viewport ResizeAbout(double val, Vec2D vec) { Viewport view = this; view.Min -= vec; view.Min *= val; view.Min += vec; view.Max -= vec; view.Max *= val; view.Max += vec; return view; }
/// <summary> /// Ensures this <see cref="Viewport"/> is at least the given size. /// </summary> /// <param name="size">The min allowed size.</param> public void EnsureSize(Vec2D size) { Size = VectorUtil.Max(Size, size); }
/// <summary> /// Returns true if the given <see cref="Vec2D"/> is within this <see cref="Viewport"/>'s bounds. /// </summary> /// <param name="vec">The vec.</param> /// <returns>True if within, else false.</returns> public bool Contains(Vec2D vec) { return ContainsX(vec.X) && ContainsY(vec.Y); }
/// <summary> /// Performs the dot product of two vectors. /// </summary> /// <param name="vec">The first vector.</param> /// <param name="vec2">The second vector.</param> /// <returns>The dot product.</returns> public static double Dot(Vec2D vec, Vec2D vec2) { return vec.X * vec2.X + vec.Y * vec2.Y; }
private void ScanLine(Scanner scanner, Vec2D v1, Vec2D v2) { if((int)v1.Y == (int)v2.Y) { int ly = (int)v1.Y; if(ly > scanner.yMin && ly < scanner.yMax) { double minX = Math.Min(v1.X, v2.X); double maxX = Math.Max(v1.X, v2.X); Scanner.Scan scan = scanner[ly]; scan.min = Math.Min(scan.min, (float)minX); scan.max = Math.Max(scan.max, (float)maxX); scanner[ly] = scan; } return; } //v1.Y always less than v2.Y if(v1.Y > v2.Y) { Util.Swap(ref v1, ref v2); } //skip if out of bounds if(v2.Y < scanner.yMin || v1.Y > scanner.yMax) return; double x = v1.X; double dx = (v2.X - v1.X) / ((int)v2.Y - (int)v1.Y); int y = (int)v1.Y; int maxY = Math.Min((int)v2.Y, scanner.yMax); //start at beginning if(y < scanner.yMin) { x += dx * (scanner.yMin - y); y = scanner.yMin; } for(; y <= maxY; y++, x += dx) { Scanner.Scan scan = scanner[y]; scan.min = Math.Min(scan.min, (float)x); scan.max = Math.Max(scan.max, (float)x); scanner[y] = scan; } }