private void AlternatesFileShouldHaveGitObjectsRoot(ScalarFunctionalTestEnlistment enlistment) { string objectsRoot = ScalarHelpers.GetObjectsRootFromGitConfig(enlistment.RepoRoot); string alternatesFileContents = Path.Combine(enlistment.RepoRoot, ".git", "objects", "info", "alternates").ShouldBeAFile(this.fileSystem).WithContents(); alternatesFileContents.ShouldEqual(objectsRoot); }
public void CloneWithDefaultLocalCacheLocation() { FileSystemRunner fileSystem = FileSystemRunner.DefaultRunner; string homeDirectory = Environment.GetEnvironmentVariable("HOME"); homeDirectory.ShouldBeADirectory(fileSystem); string newEnlistmentRoot = ScalarFunctionalTestEnlistment.GetUniqueEnlistmentRoot(); ProcessStartInfo processInfo = new ProcessStartInfo(ScalarTestConfig.PathToScalar); processInfo.Arguments = $"clone {Properties.Settings.Default.RepoToClone} {newEnlistmentRoot} --no-fetch-commits-and-trees"; processInfo.WindowStyle = ProcessWindowStyle.Hidden; processInfo.CreateNoWindow = true; processInfo.UseShellExecute = false; processInfo.RedirectStandardOutput = true; processInfo.WorkingDirectory = Properties.Settings.Default.EnlistmentRoot; ProcessResult result = ProcessHelper.Run(processInfo); result.ExitCode.ShouldEqual(0, result.Errors); string gitObjectsRoot = ScalarHelpers.GetObjectsRootFromGitConfig(Path.Combine(newEnlistmentRoot, "src")); string defaultScalarCacheRoot = Path.Combine(homeDirectory, ".scalarCache"); gitObjectsRoot.StartsWith(defaultScalarCacheRoot, StringComparison.Ordinal).ShouldBeTrue($"Git objects root did not default to using {homeDirectory}"); RepositoryHelpers.DeleteTestDirectory(newEnlistmentRoot); }
private string GetLooseObjectPath(string fileGitPath, out string sha) { ProcessResult revParseResult = GitProcess.InvokeProcess(this.Enlistment.RepoRoot, $"rev-parse :{fileGitPath}"); sha = revParseResult.Output.Trim(); sha.Length.ShouldEqual(40); string objectPath = Path.Combine(ScalarHelpers.GetObjectsRootFromGitConfig(this.Enlistment.RepoRoot), sha.Substring(0, 2), sha.Substring(2, 38)); return(objectPath); }
public float this[Vector2d p] { get { return(_values[ScalarHelpers.Round(p.Y), ScalarHelpers.Round(p.X)]); } set { _values[ScalarHelpers.Round(p.Y), ScalarHelpers.Round(p.X)] = value; } }
public void GitObjectsRecreatedWhenDownloadingObjects() { ScalarFunctionalTestEnlistment enlistment = this.CloneEnlistment(); // Find the current git objects root and ensure it's on disk string objectsRoot = ScalarHelpers.GetObjectsRootFromGitConfig(enlistment.RepoRoot); objectsRoot.ShouldBeADirectory(this.fileSystem); RepositoryHelpers.DeleteTestDirectory(objectsRoot); ScalarHelpers.GetObjectsRootFromGitConfig(enlistment.RepoRoot).ShouldEqual(objectsRoot); // Downloading objects should recreate the objects directory this.LoadBlobsViaGit(enlistment); objectsRoot.ShouldBeADirectory(this.fileSystem); // The alternates file shouldn't have changed this.AlternatesFileShouldHaveGitObjectsRoot(enlistment); }
public void FetchStepCleansUpStaleFetchLock() { this.Enlistment.RunVerb("fetch"); string fetchCommitsLockFile = Path.Combine( ScalarHelpers.GetObjectsRootFromGitConfig(this.Enlistment.RepoRoot), "pack", FetchCommitsAndTreesLock); fetchCommitsLockFile.ShouldNotExistOnDisk(this.fileSystem); this.fileSystem.WriteAllText(fetchCommitsLockFile, this.Enlistment.EnlistmentRoot); fetchCommitsLockFile.ShouldBeAFile(this.fileSystem); this.fileSystem .EnumerateDirectory(this.Enlistment.GetPackRoot(this.fileSystem)) .Split() .Where(file => string.Equals(Path.GetExtension(file), ".keep", StringComparison.OrdinalIgnoreCase)) .Count() .ShouldEqual(1, "Incorrect number of .keep files in pack directory"); this.Enlistment.RunVerb("fetch"); fetchCommitsLockFile.ShouldNotExistOnDisk(this.fileSystem); }
public unsafe Bitmap Render() { int width = _renderTarget.ColorBuffer.Bitmap.Width; int height = _renderTarget.ColorBuffer.Bitmap.Height; Rectangle imageRectangle = new Rectangle(new Point { X = 0, Y = 0 }, _renderTarget.ColorBuffer.Bitmap.Size); Bitmap result = new Bitmap(width, height, PixelFormat.Format24bppRgb); BitmapData bitmapData = _renderTarget.ColorBuffer.Bitmap.LockBits(imageRectangle, ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb); BitmapData resultBitmapData = result.LockBits(imageRectangle, ImageLockMode.WriteOnly, PixelFormat.Format24bppRgb); byte *bitmapScan0 = (byte *)bitmapData.Scan0.ToPointer(); byte *resultScan0 = (byte *)resultBitmapData.Scan0.ToPointer(); byte *bitmapPixelPointer; byte *resultPixelPointer; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { double pixelDepth = _renderTarget.DepthBuffer[y, x]; bitmapPixelPointer = bitmapScan0 + y * bitmapData.Stride + x * 3; resultPixelPointer = resultScan0 + y * resultBitmapData.Stride + x * 3; if (pixelDepth >= _focalLengthMin && pixelDepth <= _focalLengthMax) { resultPixelPointer[0] = bitmapPixelPointer[0]; resultPixelPointer[1] = bitmapPixelPointer[1]; resultPixelPointer[2] = bitmapPixelPointer[2]; } else { AverageColor3b color = new AverageColor3b(); int kernelSize = (int)(ScalarHelpers.Saturate(System.Math.Abs(pixelDepth - _focalLength) / 8.0) * _maxKernelSize); if ((kernelSize % 2) == 0) { if (kernelSize > 0) { kernelSize = kernelSize - 1; } else { kernelSize = 1; } } int halfKernelSize = (kernelSize - 1) / 2; Rectangle kernelRectangle = new Rectangle(x - halfKernelSize, y - halfKernelSize, kernelSize, kernelSize); Rectangle intersection = Rectangle.Intersect(imageRectangle, kernelRectangle); for (int yy = intersection.Y; yy < intersection.Bottom; yy++) { for (int xx = intersection.X; xx < intersection.Right; xx++) { bitmapPixelPointer = bitmapScan0 + yy * bitmapData.Stride + xx * 3; color.Add(bitmapPixelPointer); } } resultPixelPointer[0] = color.B; resultPixelPointer[1] = color.G; resultPixelPointer[2] = color.R; } } } _renderTarget.ColorBuffer.Bitmap.UnlockBits(bitmapData); result.UnlockBits(resultBitmapData); return(result); }
public virtual Color GetColor(Vector3d direction, IIntersectionResult intersectionResult, Scene scene) { Color3f result = new Color3f(); Color3f surfaceColor = Material.Texture != null?Material.Texture.GetColor(GetUVCoordinates(intersectionResult), 0) : Material.Color; Color3f reflectionColor = new Color3f(); if (Material.Reflection > 0.0f) { // Reflection Vector3d reflectionVector = VectorHelpers.GetReflectionVector(direction, GetNormal(intersectionResult)); IIntersectionResult reflectionIntersectionResult = scene.GetNearestObjectIntersection(reflectionVector, intersectionResult.Intersection, this); if (reflectionIntersectionResult != null) { reflectionColor = new Color3f(reflectionIntersectionResult.Object.GetColor(direction, reflectionIntersectionResult, scene)); } } if (scene.Lights.Count == 0) { return(surfaceColor.ToColor()); } foreach (AbstractLight light in scene.Lights) { bool lightVisible = true; if (light.Position != null) { Vector3d lightDistanceVector = light.Position - intersectionResult.Intersection; double lightDistance = lightDistanceVector.Length(); foreach (AbstractObject3d o in scene.Objects) { if (o.GetTopParent() == this.GetTopParent()) { continue; } IIntersectionResult lightIntersectionResult = o.Intersection(Vector3d.Normalize(lightDistanceVector), intersectionResult.Intersection); if (lightIntersectionResult != null) { if (lightIntersectionResult.IntersectionDistance < lightDistance) { lightVisible = false; break; } } } } if (!lightVisible) { continue; } Vector3d normal = GetNormal(intersectionResult); Vector3d lightDirection = -light.GetDirection(intersectionResult.Intersection); double distanceSquared = light.GetDistance(intersectionResult.Intersection); distanceSquared *= distanceSquared; double normalDotLightDirection = normal.Dot(lightDirection); double diffuseIntensity = ScalarHelpers.Saturate(normalDotLightDirection); Color3f diffuse = diffuseIntensity * light.DiffuseColor * light.DiffusePower / distanceSquared; Vector3d halfwayVector = (lightDirection - direction).Normalize(); double normalDotHalfwayVector = normal.Dot(halfwayVector); double specularIntensity = System.Math.Pow(ScalarHelpers.Saturate(normalDotHalfwayVector), 16f); Color3f specular = specularIntensity * light.SpecularColor * light.SpecularPower / distanceSquared; //return (surfaceColor * (diffuse + specular)).ToColor(); result += diffuse + specular; } return((((surfaceColor * result) * (1.0 - Material.Reflection)) + (reflectionColor * Material.Reflection)).ToColor()); }