Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 221 #295

Merged
merged 5 commits into from
Apr 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## 0.7.0
### Fixed
- #271
- #221

### Added
- `Transform.Move(double x, double y, double z)`
Expand Down
2 changes: 1 addition & 1 deletion src/Elements/Generate/GeometricElement.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public GeometricElement(Transform @transform, Material @material, Representation
[Newtonsoft.Json.JsonProperty("Representation", Required = Newtonsoft.Json.Required.AllowNull)]
public Representation Representation { get; set; }

/// <summary>When true, this element will act as the base defintion for element instances, and will not appear in visual output.</summary>
/// <summary>When true, this element will act as the base definition for element instances, and will not appear in visual output.</summary>
[Newtonsoft.Json.JsonProperty("IsElementDefinition", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public bool IsElementDefinition { get; set; } = false;

Expand Down
2 changes: 1 addition & 1 deletion src/Elements/Generate/Geometry/Profile.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public Profile(Polygon @perimeter, IList<Polygon> @voids, System.Guid @id, strin

this.Perimeter = @perimeter;
this.Voids = @voids;

if(validator != null)
{
validator.PostConstruct(this);
Expand Down
19 changes: 12 additions & 7 deletions src/Elements/Generate/Material.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public Material(Color @color, double @specularFactor, double @glossinessFactor,
this.Unlit = @unlit;
this.Texture = @texture;
this.DoubleSided = @doubleSided;

if(validator != null)
{
validator.PostConstruct(this);
Expand All @@ -60,14 +60,19 @@ public Material(Color @color, double @specularFactor, double @glossinessFactor,
[Newtonsoft.Json.JsonProperty("GlossinessFactor", Required = Newtonsoft.Json.Required.Always)]
[System.ComponentModel.DataAnnotations.Range(0.0D, 1.0D)]
public double GlossinessFactor { get; set; } = 0.1D;

[Newtonsoft.Json.JsonProperty("Unlit")]

/// <summary>Is this material affected by lights?</summary>
[Newtonsoft.Json.JsonProperty("Unlit", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public bool Unlit { get; set; } = false;

[Newtonsoft.Json.JsonProperty("Texture")]

/// <summary>A relative file path to an image file to be used as a texture.</summary>
[Newtonsoft.Json.JsonProperty("Texture", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public string Texture { get; set; }

[Newtonsoft.Json.JsonProperty("DoubleSided")]

/// <summary>Is this material to be rendered from both sides?</summary>
[Newtonsoft.Json.JsonProperty("DoubleSided", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public bool DoubleSided { get; set; } = false;


}
}
49 changes: 28 additions & 21 deletions src/Elements/Validators/Validators.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public void PreConstruct(object[] args)
var radius = (double)args[1];
var startAngle = (double)args[2];
var endAngle = (double)args[3];

if (endAngle > 360.0 || startAngle > 360.00)
{
throw new ArgumentOutOfRangeException("The arc could not be created. The start and end angles must be greater than -360.0");
Expand Down Expand Up @@ -52,7 +52,7 @@ public void PostConstruct(object obj)

public void PreConstruct(object[] args)
{
var start= (Vector3)args[0];
var start = (Vector3)args[0];
var end = (Vector3)args[1];

if (start.IsAlmostEqualTo(end))
Expand All @@ -68,7 +68,14 @@ public class ProfileValidator : IValidator

public void PostConstruct(object obj)
{
return;
// TODO: NJsonSchema does not have a way to specify that a property
// should have a default value, but also allow a null value. Remove
// this when we make Profile.Voids non nullable.
var profile = (Profile)obj;
if (profile.Voids == null)
{
profile.Voids = new List<Polygon>();
}
}

public void PreConstruct(object[] args)
Expand Down Expand Up @@ -101,17 +108,17 @@ public void PreConstruct(object[] args)
var id = (Guid)args[6];
var name = (string)args[7];

if(texture != null && !File.Exists(texture))
if (texture != null && !File.Exists(texture))
{
throw new FileNotFoundException("The material could not be created. The specified texture does not exist.");
}
if(specularFactor < 0.0 || glossinessFactor < 0.0)

if (specularFactor < 0.0 || glossinessFactor < 0.0)
{
throw new ArgumentOutOfRangeException("The material could not be created. Specular and glossiness values must be less greater than 0.0.");
}

if(specularFactor > 1.0 || glossinessFactor > 1.0)
if (specularFactor > 1.0 || glossinessFactor > 1.0)
{
throw new ArgumentOutOfRangeException("The material could not be created. Color, specular, and glossiness values must be less than 1.0.");
}
Expand All @@ -132,7 +139,7 @@ public void PreConstruct(object[] args)
var origin = (Vector3)args[0];
var normal = (Vector3)args[1];

if(normal.IsZero())
if (normal.IsZero())
{
throw new ArgumentException($"The plane could not be constructed. The normal, {normal}, has zero length.");
}
Expand All @@ -154,12 +161,12 @@ public void PreConstruct(object[] args)
var y = (double)args[1];
var z = (double)args[2];

if(Double.IsNaN(x) || Double.IsNaN(y) || Double.IsNaN(z))
if (Double.IsNaN(x) || Double.IsNaN(y) || Double.IsNaN(z))
{
throw new ArgumentOutOfRangeException("The vector could not be created. One or more of the components was NaN.");
}

if(Double.IsInfinity(x) || Double.IsInfinity(y) || Double.IsInfinity(z))
if (Double.IsInfinity(x) || Double.IsInfinity(y) || Double.IsInfinity(z))
{
throw new ArgumentOutOfRangeException("The vector could not be created. One or more of the components was infinity.");
}
Expand All @@ -182,12 +189,12 @@ public void PreConstruct(object[] args)
var blue = (double)args[2];
var alpha = (double)args[3];

if(red < 0.0 || green < 0.0 || blue < 0.0 || alpha < 0.0)
if (red < 0.0 || green < 0.0 || blue < 0.0 || alpha < 0.0)
{
throw new ArgumentOutOfRangeException("All components must have a value greater than 0.0.");
}

if(red > 1.0 || green > 1.0 || blue > 1.0 || alpha > 1.0)
if (red > 1.0 || green > 1.0 || blue > 1.0 || alpha > 1.0)
{
throw new ArgumentOutOfRangeException("All components must have a value less than or equal to 1.0.");
}
Expand All @@ -202,7 +209,7 @@ public void PostConstruct(object obj)
{
var extrude = (Extrude)obj;
extrude.PropertyChanged += (sender, args) => { extrude._solid = Kernel.Instance.CreateExtrude(extrude.Profile, extrude.Height, extrude.Direction); };
extrude._solid = Kernel.Instance.CreateExtrude(extrude.Profile, extrude.Height, extrude.Direction);;
extrude._solid = Kernel.Instance.CreateExtrude(extrude.Profile, extrude.Height, extrude.Direction); ;
}

public void PreConstruct(object[] args)
Expand All @@ -212,7 +219,7 @@ public void PreConstruct(object[] args)
var direction = (Vector3)args[2];
var isVoid = (bool)args[3];

if(direction.Length() == 0)
if (direction.Length() == 0)
{
throw new ArgumentException("The extrude cannot be created. The provided direction has zero length.");
}
Expand All @@ -226,8 +233,8 @@ public class SweepValidator : IValidator
public void PostConstruct(object obj)
{
var sweep = (Sweep)obj;
sweep.PropertyChanged += (sender, args) => { sweep._solid = Kernel.Instance.CreateSweepAlongCurve(sweep.Profile, sweep.Curve, sweep.StartSetback, sweep.EndSetback);; };
sweep._solid = Kernel.Instance.CreateSweepAlongCurve(sweep.Profile, sweep.Curve, sweep.StartSetback, sweep.EndSetback);;
sweep.PropertyChanged += (sender, args) => { sweep._solid = Kernel.Instance.CreateSweepAlongCurve(sweep.Profile, sweep.Curve, sweep.StartSetback, sweep.EndSetback); ; };
sweep._solid = Kernel.Instance.CreateSweepAlongCurve(sweep.Profile, sweep.Curve, sweep.StartSetback, sweep.EndSetback); ;
}

public void PreConstruct(object[] args)
Expand All @@ -243,8 +250,8 @@ public class LaminaValidator : IValidator
public void PostConstruct(object obj)
{
var lamina = (Lamina)obj;
lamina.PropertyChanged += (sender, args) => { lamina._solid = Kernel.Instance.CreateLamina(lamina.Perimeter);; };
lamina._solid = Kernel.Instance.CreateLamina(lamina.Perimeter);;
lamina.PropertyChanged += (sender, args) => { lamina._solid = Kernel.Instance.CreateLamina(lamina.Perimeter); ; };
lamina._solid = Kernel.Instance.CreateLamina(lamina.Perimeter); ;
}

public void PreConstruct(object[] args)
Expand All @@ -265,7 +272,7 @@ public void PostConstruct(object obj)
public void PreConstruct(object[] args)
{
var components = (IList<double>)args[0];
if(components.Count != 12)
if (components.Count != 12)
{
throw new ArgumentOutOfRangeException("The matrix could not be created. The component array must have 16 values.");
}
Expand All @@ -285,7 +292,7 @@ public void PreConstruct(object[] args)
{
var vertices = (IList<Vector3>)args[0];

if(!vertices.AreCoplanar())
if (!vertices.AreCoplanar())
{
throw new ArgumentException("The polygon could not be created. The provided vertices are not coplanar.");
}
Expand All @@ -308,7 +315,7 @@ public void PreConstruct(object[] args)
{
var vertices = (IList<Vector3>)args[0];

if(!vertices.AreCoplanar())
if (!vertices.AreCoplanar())
{
throw new ArgumentException("The polygon could not be created. The provided vertices are not coplanar.");
}
Expand Down
15 changes: 12 additions & 3 deletions test/Elements.Tests/ProfileTests.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
using System;
using System.Linq;
using Elements.Geometry;
using Xunit;
using System.Linq;
using System.Collections.Generic;
using Elements.Tests;

namespace Elements.Geometry.Tests
namespace Elements.Tests
{
public class ProfileTests : ModelTest
{
[Fact]
public void Profile()
{
// Use the generated constructor to test that voids will
// be set to a default in the validator.
var profile = new Profile(Polygon.Rectangle(1, 1), null, default(Guid), null);
Assert.NotNull(profile.Voids);
profile.Voids.Add(Polygon.Rectangle(0.5, 0.5));
}

public void ProfileMultipleUnion()
{
this.Name = "MultipleProfileUnion";
Expand Down