public void Tesselate_WithSingleTriangle_ProducesSameTriangle() { string data = "0,0,0\n0,1,0\n1,1,0"; var indices = new List <int>(); var expectedIndices = new int[] { 0, 1, 2 }; using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(data))) { var pset = DataLoader.LoadDat(stream); var tess = new Tess(); PolyConvert.ToTess(pset, tess); tess.Tessellate(WindingRule.EvenOdd, ElementType.Polygons, 3); indices.Clear(); for (int i = 0; i < tess.ElementCount; i++) { for (int j = 0; j < 3; j++) { int index = tess.Elements[i * 3 + j]; indices.Add(index); } } Assert.AreEqual(expectedIndices, indices.ToArray()); } }
// From https://github.com/speps/LibTessDotNet/issues/1 public void Tesselate_WithNoEmptyPolygonsTrue_RemovesEmptyPolygons() { string data = "2,0,4\n2,0,2\n4,0,2\n4,0,0\n0,0,0\n0,0,4"; var indices = new List <int>(); var expectedIndices = new int[] { 0, 1, 2, 2, 3, 4, 3, 1, 5 }; using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(data))) { var pset = DataLoader.LoadDat(stream); var tess = new Tess(); PolyConvert.ToTess(pset, tess); tess.NoEmptyPolygons = true; tess.Tessellate(WindingRule.EvenOdd, ElementType.Polygons, 3); indices.Clear(); for (int i = 0; i < tess.ElementCount; i++) { for (int j = 0; j < 3; j++) { int index = tess.Elements[i * 3 + j]; indices.Add(index); } } Assert.AreEqual(expectedIndices, indices.ToArray()); } }
// From https://github.com/memononen/libtess2/issues/14 public void Tesselate_WithThinQuad_DoesNotCrash() { string data = "9.5,7.5,-0.5\n9.5,2,-0.5\n9.5,2,-0.4999999701976776123\n9.5,7.5,-0.4999999701976776123"; using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(data))) { var pset = DataLoader.LoadDat(stream); var tess = new Tess(); PolyConvert.ToTess(pset, tess); tess.Tessellate(WindingRule.EvenOdd, ElementType.Polygons, 3); } }
// From https://github.com/speps/LibTessDotNet/issues/1 public void Tesselate_WithIssue1Quad_ReturnsSameResultAsLibtess2() { string data = "50,50\n300,50\n300,200\n50,200"; var indices = new List <int>(); var expectedIndices = new int[] { 0, 1, 2, 1, 0, 3 }; using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(data))) { var pset = DataLoader.LoadDat(stream); var tess = new Tess(); PolyConvert.ToTess(pset, tess); tess.Tessellate(WindingRule.EvenOdd, ElementType.Polygons, 3); indices.Clear(); for (int i = 0; i < tess.ElementCount; i++) { for (int j = 0; j < 3; j++) { int index = tess.Elements[i * 3 + j]; indices.Add(index); } } Assert.AreEqual(expectedIndices, indices.ToArray()); } }
public MainForm() { InitializeComponent(); _canvas = new Canvas(); _canvas.Dock = DockStyle.Fill; panel.Controls.Add(_canvas); _assets = _data.AssetNames; Array.Sort(_assets); foreach (var asset in _assets) { toolStripAssets.Items.Add(asset); } toolStripAssets.SelectedIndexChanged += delegate(object sender, EventArgs e) { RefreshAsset(toolStripAssets.SelectedIndex); }; _windingRules = Enum.GetNames(typeof(WindingRule)); foreach (var windingRule in _windingRules) { toolStripWinding.Items.Add(windingRule); } toolStripWinding.SelectedIndexChanged += delegate(object sender, EventArgs e) { _windingRule = (WindingRule)toolStripWinding.SelectedIndex; if (toolStripAssets.SelectedIndex >= 0) { RefreshAsset(toolStripAssets.SelectedIndex); } }; toolStripPolySize.KeyDown += delegate(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { PolySizeEvent(); } }; toolStripPolySize.Leave += delegate(object sender, EventArgs e) { PolySizeEvent(); }; toolStripButtonShowInput.CheckedChanged += delegate(object sender, EventArgs e) { _canvas.ShowInput = toolStripButtonShowInput.Checked; toolStripButtonShowWinding.Enabled = _canvas.ShowInput; RefreshAsset(toolStripAssets.SelectedIndex); }; toolStripButtonShowWinding.CheckedChanged += delegate(object sender, EventArgs e) { _canvas.ShowWinding = toolStripButtonShowWinding.Checked; RefreshAsset(toolStripAssets.SelectedIndex); }; toolStripButtonNoEmpty.CheckedChanged += delegate(object sender, EventArgs e) { _tess.NoEmptyPolygons = toolStripButtonNoEmpty.Checked; RefreshAsset(toolStripAssets.SelectedIndex); }; toolStripButtonBench.Click += delegate(object sender, EventArgs e) { new BenchForm().ShowDialog(this); }; toolStripButtonOpen.Click += delegate(object sender, EventArgs e) { var dialog = new OpenFileDialog(); dialog.Filter = "Test Files (*.dat)|*.dat|All Files (*.*)|*.*"; dialog.FilterIndex = 1; dialog.RestoreDirectory = true; if (dialog.ShowDialog() == DialogResult.OK) { var polygons = DataLoader.LoadDat(dialog.OpenFile()); RefreshAsset(polygons); toolStripAssets.SelectedIndex = -1; } }; SetAsset("redbook-winding"); SetShowInput(true); SetShowWinding(false); SetPolySize(3); SetWindingRule(WindingRule.EvenOdd); }
public MainForm() { InitializeComponent(); _canvas = new Canvas(); _canvas.Dock = DockStyle.Fill; panel.Controls.Add(_canvas); foreach (var asset in _data.Assets) { toolStripAssets.Items.Add(asset); } toolStripAssets.SelectedIndexChanged += delegate(object sender, EventArgs e) { if (toolStripAssets.SelectedIndex >= 0) { var asset = toolStripAssets.SelectedItem as DataLoader.Asset; _polys = asset.Polygons; RefreshCanvas(); } }; _windingRules = Enum.GetNames(typeof(WindingRule)); foreach (var windingRule in _windingRules) { toolStripWinding.Items.Add(windingRule); } toolStripWinding.SelectedIndexChanged += delegate(object sender, EventArgs e) { _windingRule = (WindingRule)toolStripWinding.SelectedIndex; RefreshCanvas(); }; toolStripPolySize.KeyDown += delegate(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { PolySizeEvent(); } }; toolStripPolySize.Leave += delegate(object sender, EventArgs e) { PolySizeEvent(); }; toolStripButtonShowInput.CheckedChanged += delegate(object sender, EventArgs e) { _canvas.ShowInput = toolStripButtonShowInput.Checked; toolStripButtonShowWinding.Enabled = _canvas.ShowInput; RefreshCanvas(); }; toolStripButtonShowWinding.CheckedChanged += delegate(object sender, EventArgs e) { _canvas.ShowWinding = toolStripButtonShowWinding.Checked; RefreshCanvas(); }; toolStripButtonNoEmpty.CheckedChanged += delegate(object sender, EventArgs e) { _tess.NoEmptyPolygons = toolStripButtonNoEmpty.Checked; RefreshCanvas(); }; toolStripButtonBench.Click += delegate(object sender, EventArgs e) { new BenchForm().ShowDialog(this); }; toolStripButtonFile.Click += delegate(object sender, EventArgs e) { var dialog = new OpenFileDialog(); dialog.Filter = "Test Files (*.dat)|*.dat|All Files (*.*)|*.*"; dialog.FilterIndex = 1; dialog.RestoreDirectory = true; if (dialog.ShowDialog() == DialogResult.OK) { var polygons = DataLoader.LoadDat(dialog.OpenFile()); _polys = polygons; RefreshCanvas(); toolStripAssets.SelectedIndex = -1; } }; toolStripButtonFolder.Click += delegate(object sender, EventArgs e) { var dialog = new FolderBrowserDialog(); if (dialog.ShowDialog() == DialogResult.OK) { var files = Directory.GetFiles(dialog.SelectedPath, "*.dat"); if (files.Length > 0) { toolStripAssets.Items.Clear(); _polys = null; foreach (var file in files) { using (var stream = new FileStream(file, FileMode.Open)) { var polygons = DataLoader.LoadDat(stream); if (_polys == null) { _polys = polygons; } toolStripAssets.Items.Add(new DataLoader.Asset() { Name = Path.GetFileName(file), Polygons = polygons }); } } toolStripAssets.SelectedIndex = 0; RefreshCanvas(); } } }; SetAsset("redbook-winding"); SetShowInput(true); SetShowWinding(false); SetPolySize(3); SetWindingRule(WindingRule.EvenOdd); }