mirror of
https://github.com/fadden/6502bench.git
synced 2024-12-01 07:50:37 +00:00
Consolidate wireframe data validation
Some tests were duplicated between VisWireframe and the code that consumed the data. We now expose the Validate function as a public interface, and invoke it from WireframeObject. Failed validation results in a null object being returned, which was previously allowed but not actually checked for.
This commit is contained in:
parent
3820bfee8b
commit
ea379fce18
@ -369,6 +369,8 @@ namespace PluginCommon {
|
|||||||
IntPair[] GetEdgeFaces();
|
IntPair[] GetEdgeFaces();
|
||||||
int[] GetExcludedVertices();
|
int[] GetExcludedVertices();
|
||||||
int[] GetExcludedEdges();
|
int[] GetExcludedEdges();
|
||||||
|
|
||||||
|
bool Validate(out string msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -190,6 +190,10 @@ namespace PluginCommon {
|
|||||||
msg = "no vertices defined";
|
msg = "no vertices defined";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (mVerticesX.Count != mVerticesY.Count || mVerticesX.Count != mVerticesZ.Count) {
|
||||||
|
msg = "inconsistent vertex arrays";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// check points
|
// check points
|
||||||
foreach (int vi in mPoints) {
|
foreach (int vi in mPoints) {
|
||||||
@ -234,6 +238,10 @@ namespace PluginCommon {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (mNormalsX.Count != mNormalsY.Count || mNormalsX.Count != mNormalsZ.Count) {
|
||||||
|
msg = "inconsistent normal arrays";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// check excluded vertices
|
// check excluded vertices
|
||||||
for (int i = 0; i < mExcludedVertices.Count; i++) {
|
for (int i = 0; i < mExcludedVertices.Count; i++) {
|
||||||
|
@ -203,7 +203,11 @@ namespace SourceGen {
|
|||||||
} else {
|
} else {
|
||||||
Debug.Assert(parms != null);
|
Debug.Assert(parms != null);
|
||||||
WireframeObject wireObj = WireframeObject.Create(visWire);
|
WireframeObject wireObj = WireframeObject.Create(visWire);
|
||||||
CachedImage = GenerateWireframeImage(wireObj, THUMBNAIL_DIM, parms);
|
if (wireObj != null) {
|
||||||
|
CachedImage = GenerateWireframeImage(wireObj, THUMBNAIL_DIM, parms);
|
||||||
|
} else {
|
||||||
|
CachedImage = BROKEN_IMAGE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Debug.Assert(CachedImage.IsFrozen);
|
Debug.Assert(CachedImage.IsFrozen);
|
||||||
}
|
}
|
||||||
|
@ -105,8 +105,15 @@ namespace SourceGen {
|
|||||||
/// Creates a new object from a wireframe visualization.
|
/// Creates a new object from a wireframe visualization.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="visWire">Visualization object.</param>
|
/// <param name="visWire">Visualization object.</param>
|
||||||
/// <returns>New object.</returns>
|
/// <returns>New object, or null if visualization data fails validation.</returns>
|
||||||
public static WireframeObject Create(IVisualizationWireframe visWire) {
|
public static WireframeObject Create(IVisualizationWireframe visWire) {
|
||||||
|
if (!visWire.Validate(out string msg)) {
|
||||||
|
// Should not be here -- visualizer should have checked validation and
|
||||||
|
// reported an error.
|
||||||
|
Debug.WriteLine("Wireframe validation failed: " + msg);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
WireframeObject wireObj = new WireframeObject();
|
WireframeObject wireObj = new WireframeObject();
|
||||||
|
|
||||||
wireObj.mIs2d = visWire.Is2d;
|
wireObj.mIs2d = visWire.Is2d;
|
||||||
@ -125,11 +132,6 @@ namespace SourceGen {
|
|||||||
float[] normalsY = visWire.GetNormalsY();
|
float[] normalsY = visWire.GetNormalsY();
|
||||||
float[] normalsZ = visWire.GetNormalsZ();
|
float[] normalsZ = visWire.GetNormalsZ();
|
||||||
|
|
||||||
if (normalsX.Length != normalsY.Length || normalsX.Length != normalsZ.Length) {
|
|
||||||
Debug.Assert(false);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < normalsX.Length; i++) {
|
for (int i = 0; i < normalsX.Length; i++) {
|
||||||
wireObj.mFaces.Add(new Face(normalsX[i], normalsY[i], normalsZ[i]));
|
wireObj.mFaces.Add(new Face(normalsX[i], normalsY[i], normalsZ[i]));
|
||||||
}
|
}
|
||||||
@ -139,14 +141,6 @@ namespace SourceGen {
|
|||||||
float[] verticesY = visWire.GetVerticesY();
|
float[] verticesY = visWire.GetVerticesY();
|
||||||
float[] verticesZ = visWire.GetVerticesZ();
|
float[] verticesZ = visWire.GetVerticesZ();
|
||||||
int[] excludedVertices = visWire.GetExcludedVertices();
|
int[] excludedVertices = visWire.GetExcludedVertices();
|
||||||
if (verticesX.Length == 0) {
|
|
||||||
Debug.Assert(false);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
if (verticesX.Length != verticesY.Length || verticesX.Length != verticesZ.Length) {
|
|
||||||
Debug.Assert(false);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Compute min/max for X/Y for 2d re-centering. The trick is that we only want
|
// Compute min/max for X/Y for 2d re-centering. The trick is that we only want
|
||||||
// to use vertices that are visible. If the shape starts with a huge move off to
|
// to use vertices that are visible. If the shape starts with a huge move off to
|
||||||
@ -173,11 +167,11 @@ namespace SourceGen {
|
|||||||
int v0index = edges[i].Val0;
|
int v0index = edges[i].Val0;
|
||||||
int v1index = edges[i].Val1;
|
int v1index = edges[i].Val1;
|
||||||
|
|
||||||
if (v0index < 0 || v0index >= wireObj.mVertices.Count ||
|
//if (v0index < 0 || v0index >= wireObj.mVertices.Count ||
|
||||||
v1index < 0 || v1index >= wireObj.mVertices.Count) {
|
// v1index < 0 || v1index >= wireObj.mVertices.Count) {
|
||||||
Debug.Assert(false);
|
// Debug.Assert(false);
|
||||||
return null;
|
// return null;
|
||||||
}
|
//}
|
||||||
|
|
||||||
Vertex vert0 = wireObj.mVertices[v0index];
|
Vertex vert0 = wireObj.mVertices[v0index];
|
||||||
Vertex vert1 = wireObj.mVertices[v1index];
|
Vertex vert1 = wireObj.mVertices[v1index];
|
||||||
@ -192,11 +186,11 @@ namespace SourceGen {
|
|||||||
int vindex = vfaces[i].Val0;
|
int vindex = vfaces[i].Val0;
|
||||||
int findex = vfaces[i].Val1;
|
int findex = vfaces[i].Val1;
|
||||||
|
|
||||||
if (vindex < 0 || vindex >= wireObj.mVertices.Count ||
|
//if (vindex < 0 || vindex >= wireObj.mVertices.Count ||
|
||||||
findex < 0 || findex >= wireObj.mFaces.Count) {
|
// findex < 0 || findex >= wireObj.mFaces.Count) {
|
||||||
Debug.Assert(false);
|
// Debug.Assert(false);
|
||||||
return null;
|
// return null;
|
||||||
}
|
//}
|
||||||
|
|
||||||
Face face = wireObj.mFaces[findex];
|
Face face = wireObj.mFaces[findex];
|
||||||
wireObj.mVertices[vindex].Faces.Add(face);
|
wireObj.mVertices[vindex].Faces.Add(face);
|
||||||
@ -210,11 +204,11 @@ namespace SourceGen {
|
|||||||
int eindex = efaces[i].Val0;
|
int eindex = efaces[i].Val0;
|
||||||
int findex = efaces[i].Val1;
|
int findex = efaces[i].Val1;
|
||||||
|
|
||||||
if (eindex < 0 || eindex >= wireObj.mEdges.Count ||
|
//if (eindex < 0 || eindex >= wireObj.mEdges.Count ||
|
||||||
findex < 0 || findex >= wireObj.mFaces.Count) {
|
// findex < 0 || findex >= wireObj.mFaces.Count) {
|
||||||
Debug.Assert(false);
|
// Debug.Assert(false);
|
||||||
return null;
|
// return null;
|
||||||
}
|
//}
|
||||||
|
|
||||||
Face face = wireObj.mFaces[findex];
|
Face face = wireObj.mFaces[findex];
|
||||||
wireObj.mEdges[eindex].Faces.Add(face);
|
wireObj.mEdges[eindex].Faces.Add(face);
|
||||||
|
@ -591,15 +591,9 @@ namespace SourceGen.WpfGui {
|
|||||||
LastPluginMessage = ex.Message;
|
LastPluginMessage = ex.Message;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
bool failed = false;
|
||||||
if (vis2d == null && visWire == null) {
|
if (vis2d == null && visWire == null) {
|
||||||
previewImage.Source = sBadParamsImage;
|
failed = true;
|
||||||
if (!string.IsNullOrEmpty(LastPluginMessage)) {
|
|
||||||
// Report the last message we got as an error.
|
|
||||||
PluginErrMessage = LastPluginMessage;
|
|
||||||
} else {
|
|
||||||
PluginErrMessage = (string)FindResource("str_VisGenFailed");
|
|
||||||
}
|
|
||||||
IsValid = false;
|
|
||||||
} else if (vis2d != null) {
|
} else if (vis2d != null) {
|
||||||
previewGrid.Background = null;
|
previewGrid.Background = null;
|
||||||
previewImage.Source = Visualization.ConvertToBitmapSource(vis2d);
|
previewImage.Source = Visualization.ConvertToBitmapSource(vis2d);
|
||||||
@ -609,15 +603,31 @@ namespace SourceGen.WpfGui {
|
|||||||
|
|
||||||
mThumbnail = (BitmapSource)previewImage.Source;
|
mThumbnail = (BitmapSource)previewImage.Source;
|
||||||
} else {
|
} else {
|
||||||
previewGrid.Background = Brushes.Black;
|
|
||||||
previewImage.Source = Visualization.BLANK_IMAGE;
|
|
||||||
double dim = Math.Floor(
|
|
||||||
Math.Min(previewGrid.ActualWidth, previewGrid.ActualHeight));
|
|
||||||
WireframeObject wireObj = WireframeObject.Create(visWire);
|
WireframeObject wireObj = WireframeObject.Create(visWire);
|
||||||
wireframePath.Data = Visualization.GenerateWireframePath(wireObj, dim, parms);
|
if (wireObj != null) {
|
||||||
BitmapDimensions = "n/a";
|
previewGrid.Background = Brushes.Black;
|
||||||
|
previewImage.Source = Visualization.BLANK_IMAGE;
|
||||||
|
double dim = Math.Floor(
|
||||||
|
Math.Min(previewGrid.ActualWidth, previewGrid.ActualHeight));
|
||||||
|
wireframePath.Data =
|
||||||
|
Visualization.GenerateWireframePath(wireObj, dim, parms);
|
||||||
|
BitmapDimensions = "n/a";
|
||||||
|
|
||||||
mWireObj = wireObj;
|
mWireObj = wireObj;
|
||||||
|
} else {
|
||||||
|
failed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (failed) {
|
||||||
|
previewImage.Source = sBadParamsImage;
|
||||||
|
if (!string.IsNullOrEmpty(LastPluginMessage)) {
|
||||||
|
// Report the last message we got as an error.
|
||||||
|
PluginErrMessage = LastPluginMessage;
|
||||||
|
} else {
|
||||||
|
// Generic failure message.
|
||||||
|
PluginErrMessage = (string)FindResource("str_VisGenFailed");
|
||||||
|
}
|
||||||
|
IsValid = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user