public void LazyInputTest() { var obj = Composite.Create(new[] { Composite.CreateValue(new Simple { Number = 1, }), Composite.Create(new[] { Composite.CreateValue(new Simple { Number = 6, }), Composite.CreateValue(new Simple { Number = 7, }), }.AllowTake(1)), Composite.CreateValue(new Simple { Number = 8, }), }); var baseQuery = obj.Select(x => x.Number == 1 ? 4 : x.Number == 6 ? 5 : x.Number); var result = baseQuery.AsEnumerable() .Take(2) .ToArray(); Assert.Equal(4, result[0]); Assert.Equal(5, result[1]); Assert.Throws <InvalidOperationException>(() => baseQuery.AsEnumerable().Take(3).ToArray()); }
public FighterGeometry() { var nose = new Nose(0.5f, 0.6f, 26, 0.4f); var cockpitFuselage = new CockpitFuselage(nose, 1.2f, 1.2f, 3f); var mainFuselage = new MainFuselage(cockpitFuselage); var intake = new EngineIntake(cockpitFuselage); var underside = new Underside(intake); var canopy = new Canopy(0.65f, 0.5f, 3f, 16); var wing = new Wing(4.5f, 4.5f); var rear = new Rear(mainFuselage, underside); var tailFin = new TailFin(); var stabilizer = new Stabilizer(); var exhaust = new Exhaust(rear, 0.6f); var bottomFin = new BottomFin(); var path = exhaust.FlangeEndXSection; var graySlide = new Vec3(1f).Interpolate(new Vec3(0f), path.Vertices.Length); path.Vertices.Color(graySlide); Paths = EnumerableExt.Enumerate(path); Fighter = Composite.Create(Stacking.StackBackward(cockpitFuselage.Fuselage, mainFuselage.Fuselage) .Concat(EnumerableExt.Enumerate(intake.Intake, intake.Belly, underside.Geometry, canopy.Geometry, wing.Geometry, wing.Geometry.ReflectX(), rear.Geometry, exhaust.Geometry, exhaust.StabilizerFlange, exhaust.StabilizerFlange.ReflectX(), tailFin.Geometry, stabilizer.Geometry, stabilizer.Geometry.ReflectX(), bottomFin.Geometry, bottomFin.Geometry.ReflectX()))) .Smoothen(0.85f) .Center(); }
public void TransformationTest() { var obj = Composite.Create(new[] { Composite.CreateValue(new Simple { Number = 1, }), Composite.CreateValue(new Simple { Number = 6, }), Composite.Create(new[] { Composite.CreateValue(new Simple { Number = 1, }), Composite.CreateValue(new Simple { Number = 7, }), }), Composite.CreateValue(new Simple { Number = 8, }), }); var result = obj.Select(x => x.Number == 1 ? 4 : x.Number == 6 ? 5 : x.Number); Assert.Equal("[ 4, 5, [ 4, 7 ], 8 ]", result.ToStringShort()); }
public void LazyOutputTest() { var obj = Composite.Create(new[] { Composite.CreateValue(new Simple { Number = 1, }), Composite.CreateValue(new Simple { Number = 6, }), }); var forked = obj.Fork( x => x.Number == 1, _ => new[] { new Simple { Number = 4, }, new Simple { Number = 5, }, new Simple { Number = 6, } }.AllowTake(2)); var result = forked.AsEnumerable() .Take(2) .ToArray(); Assert.Equal(4, result[0].Number); Assert.Equal(5, result[1].Number); Assert.Throws <InvalidOperationException>(() => forked.AsEnumerable().Take(3).ToArray()); }
public void LazyOutputTest() { var obj = Composite.Create(new [] { Composite.CreateValue(new Simple { Number = 2, }), Composite.Create(new [] { Composite.CreateValue(new Simple { Number = 1, }), Composite.CreateValue(new Simple { Number = 6, }), }), Composite.CreateValue(new Simple { Number = 2, }), }.AllowTake(2)); obj.ToComponents().Take(2).ToArray(); Assert.Throws <InvalidOperationException>(() => { obj.ToComponents().Take(3).ToArray(); }); }
public static Geometry <EntityVertex> House() { var roof = Roof(out Vec3 roofSnapTag); var gables = Gables(roof, out Vec3 gableTopTag); var wallsAndGables = WallsAndGables(roof, gables, roofSnapTag, gableTopTag); return(Composite.Create(Aligning.AlignZ(Alignment.Center, roof, wallsAndGables)).Center() .Color(VertexColor <Vec3> .Bronze)); }
public static Geometry <EntityVertex> Hammer() { var cube1 = Extrusion.Cube <EntityVertex> (1f, 1.5f, 2f).RotateY(MathHelper.PiOver2); var cube2 = Extrusion.Cube <EntityVertex> (1f, 1f, 1f).Scale(0.8f, 0.8f, 0.8f); var cube3 = Extrusion.Cube <EntityVertex> (1f, 1f, 2f); return(Composite.Create(Stacking.StackRight(cube1, cube2, cube3) .Align(Alignment.None, Alignment.Center, Alignment.Center)).Center()); }
public void InvalidParametersTest() { var obj = Composite.Create(new[] { Composite.CreateValue(new Simple()), Composite.CreateValue(new Simple()), }); Assert.Throws <ArgumentNullException>(() => obj.Fork(null, null)); Assert.Throws <ArgumentNullException>(() => obj.Fork(null, (_) => Enumerable.Empty <Simple>())); }
private static Geometry <EntityVertex> Gables(Geometry <EntityVertex> roof, out Vec3 tag) { var gableHeight = roof.BoundingBox.Size.Y * 0.85f; var frontGable = Triangle <EntityVertex> .Isosceles(2 *gableHeight, gableHeight); tag = frontGable.Vertices.Furthest(Dir3D.Up).Single().position; var backGable = frontGable.ReflectZ().Translate(0f, 0f, -roof.BoundingBox.Size.Z * 0.9f); return(Composite.Create(frontGable, backGable)); }
private static Geometry <EntityVertex> Roof(out Vec3 tag) { var trapezoid = Quadrilateral <EntityVertex> .Trapezoid(20f, 1f, 0f, 1f); tag = trapezoid.Vertices.Furthest(Dir3D.Down).Furthest(Dir3D.Right).Single().position; var leftPane = trapezoid.Extrude(30f).RotateZ(MathHelper.PiOver4); var rightPane = leftPane.ReflectX(); return(Composite.Create(Stacking.StackRight(leftPane, rightPane))); }
public void TrivialParametersTest() { var inputComposite = Composite.Create(new Composite <int>[] {}); Assert.Equal("[ ]", inputComposite.ToStringShort()); inputComposite = Composite.Create(new[] { Composite.CreateValue(1) }); Assert.Equal("[ 1 ]", inputComposite.ToStringShort()); inputComposite = Composite.CreateValue(1); Assert.Equal("1", inputComposite.ToStringShort()); }
private static Geometry <EntityVertex> WallsAndGables(Geometry <EntityVertex> roof, Geometry <EntityVertex> gables, Vec3 roofSnapTag, Vec3 gableTopTag) { var walls = Quadrilateral <EntityVertex> .Rectangle(gables.BoundingBox.Size.X, gables.BoundingBox.Size.Z) .Extrude(12f, false).RotateX(MathHelper.PiOver2); var wallsAndGables = Composite.Create(Stacking.StackUp(walls, gables) .Align(Alignment.Center, Alignment.None, Alignment.Center)); return(wallsAndGables.SnapTo(gableTopTag, roofSnapTag, Axes.All)); }
public Exhaust(Rear rear, float length) { var plateSide = Quadrilateral <V> .Trapezoid(0.38f, length, 0f, -0.1f); //var nozzlePlate = Composite.Create (plateSide, plateSide.ReflectZ ()); var nozzlePlate = plateSide.Extrude(0.05f); var plateCnt = 12; var plates = new Geometry <V> [plateCnt]; var angle = 0f; for (int i = 0; i < plateCnt; i++, angle += MathHelper.TwoPi / plateCnt) { plates[i] = nozzlePlate .Translate(0f, length / 2f, 0f) .RotateX(-105f.Radians()) .Translate(0f, 0.62f, 0f) .RotateZ(angle); } var snapToVertex = rear.Geometry.Vertices.Furthest(Dir3D.Back).Furthest(Dir3D.Up).First(); var exhaust = Composite.Create(plates); Geometry = exhaust .SnapTo(exhaust.Vertices.Furthest(Dir3D.Up).First().position, snapToVertex.position, Axes.Y | Axes.Z) .Translate(0f, -0.02f, 0.02f) .Color(VertexColor <Vec3> .BlackPlastic); FlangeXSection = new Path <P, Vec3> ( from n in rear.RearXSection.Vertices where n.position.X < -0.65f && n.position.Y < 0.4f select n) .Close(); FlangeEndXSection = new Path <P, Vec3> ( from n in FlangeXSection.Vertices select new P() { position = new Vec3(n.position.X, n.position.Y.Clamp(-0.2f, 0.1f), n.position.Z) }); var center = FlangeEndXSection.Vertices.Center <P, Vec3> (); StabilizerFlange = FlangeXSection.MorphTo(FlangeEndXSection, EnumerableExt.Range(0f, -1.25f, -0.25f).Select(s => Mat.Translation <Mat4> (0f, 0f, s) * Mat.Scaling <Mat4> (1f, 1f - (s * 0.3f).Pow(2f)).RelativeTo(center))) .Extrude <V, P> (false, true) .Color(_color); }
public void PredicateCallTest() { var obj = Composite.Create(new[] { Composite.CreateValue(new Simple { Number = 1, }), Composite.CreateValue(new Simple { Number = 6, }), }); var forked = obj.Fork( x => x.Number == 1 ? true : throw new InvalidOperationException(), _ => new[] { new Simple(), new Simple(), }); forked.AsEnumerable().Take(2).ToArray(); Assert.Throws <InvalidOperationException>(() => forked.AsEnumerable().Take(3).ToArray()); }
public void TransformationTest() { var obj = Composite.Create(new[] { Composite.CreateValue(new Simple { Number = 1, }), Composite.CreateValue(new Simple { Number = 6, }), }); var result = obj.Fork(x => x.Number == 1, _ => new[] { new Simple { Number = 4, }, new Simple { Number = 5, } }); Assert.Equal("[ [ 4, 5 ], 6 ]", result.ToStringShort()); }
public Wing(float width, float length) { var botHalf = Quadrilateral <V> .Trapezoid(length, width, length * 0.75f, 0f) .ExtrudeToScale( depth: 0.1f, targetScale: 0.5f, steepness: 3f, numSteps: 5, includeFrontFace: false, scaleAround: new Vec3(length / 4f, -width / 2f, 0f)) .FilterVertices(v => !v.Facing(Dir3D.Down)); Geometry = Composite.Create( Stacking.StackForward(botHalf, botHalf.ReflectZ())) .RotateX(-MathHelper.PiOver2) .RotateY(MathHelper.PiOver2) .Translate(-2.7f, -0.25f, -7f) .Color(_color); }
public Rear(MainFuselage fuselage, Underside underside) { var pos1 = new P() { position = fuselage.RearXSection.Vertices.First().position + new Vec3(0f, -0.1f, 0f) }; var pos2 = new P() { position = fuselage.RearXSection.Vertices.Last().position + new Vec3(0f, -0.1f, 0f) }; XSection = +(fuselage.RearXSection + pos2 + underside.RearXSection + pos1); RearXSection = +(fuselage.RearXSection.Scale(1f, 0.9f) + pos2 + BottomXSection(underside.RearXSection) + pos1); var transforms = from s in EnumerableExt.Range(0f, 2.5f, 0.5f) select Mat.Translation <Mat4> (0f, s / 25f, -s); var paths = XSection.MorphTo(RearXSection, transforms); var rear = paths.Extrude <V, P> (false, false); RearXSection = paths.Last(); EngineXSection = new Path <P, Vec3> ( from n in RearXSection.Vertices where n.position.X >= -0.9f && n.position.X <= 0.9f select new P() { position = new Vec3(n.position.X.Clamp(-0.75f, 0.75f), n.position.Y, n.position.Z) }) .Close(); ExhaustXSection = EngineXSection.Scale(0.8f, 0.7f); transforms = from s in EnumerableExt.Range(0f, 1f, 0.5f) select Mat.Translation <Mat4> (0f, s / 10f, -s); var engine = EngineXSection.MorphTo(ExhaustXSection, transforms) .Extrude <V, P> (false, true); Geometry = Composite.Create(rear, engine) .Color(_color); }
public CockpitFuselage(Nose nose, float length, float baseScale, float bend) { Fuselage = Extrusion.Extrude <V, P> (false, false, nose.XSection, nose.XSection.Transform(Mat.Translation <Mat4> (0f, 0, -length) * Mat.Scaling <Mat4> (1f, baseScale, baseScale))); Fuselage = Composite.Create(Stacking.StackBackward(nose.Cone, Fuselage)); XSection = Path <P, Vec3> .FromVecs( from v in Fuselage.Vertices.Furthest (Dir3D.Back) where v.position.Y >= -0.2f select v.position).Close(); var pivotPoint = XSection.Vertices.Furthest(Dir3D.Up).First().position; Fuselage = Fuselage.ManipulateVertices( Manipulators.Transform <V> (Mat.RotationX <Mat4> (bend.Radians()).RelativeTo(pivotPoint)) .Where(v => v.position.Z > pivotPoint.Z), true) .Color(_color); XSectionStart = XSection.Vertices.Furthest(Dir3D.Down + Dir3D.Left).Single(); XSection = XSection.RenumberNodes(XSection.Vertices.IndexOf(XSectionStart)).Open(); }
public void TransformationTest() { var inputComposite = Composite.Create(new[] { Composite.Create(new[] { Composite.CreateValue(new Simple { Number = 1, }), Composite.CreateValue(new Simple { Number = 2, }), Composite.CreateValue(new Simple { Number = 3, }) }), Composite.CreateValue(new Simple { Number = 6, }), }); Assert.Equal("[ [ 1, 2, 3 ], 6 ]", inputComposite.ToStringShort()); }
public Stabilizer() { var half = Polygon <V> .FromVec2s( new Vec2 (-2f, 0.5f), new Vec2 (0f, 2f), new Vec2 (0f, -0.5f), new Vec2 (-1.75f, -0.5f), new Vec2 (-2f, -0.25f)) .ExtrudeToScale( depth: 0.07f, targetScale: 0.5f, steepness: 3f, numSteps: 5, includeFrontFace: false); Geometry = Composite.Create( Stacking.StackForward(half, half.ReflectZ())) .RotateX(MathHelper.PiOver2) .RotateZ(5f.Radians()) .Translate(-1.1f, -0.1f, -12.8f) .Color(_color); }
public TailFin() { var half = Polygon <V> .FromVec2s( new Vec2 (-4f, 0f), new Vec2 (-1.75f, 0.5f), new Vec2 (0f, 3f), new Vec2 (1.25f, 3f), new Vec2 (0.5f, 0.5f), new Vec2 (0.5f, 0f)) .ExtrudeToScale( depth: 0.1f, targetScale: 0.5f, steepness: 3f, numSteps: 5, includeFrontFace: false); Geometry = Composite.Create( Stacking.StackForward(half, half.ReflectZ())) .RotateY(MathHelper.PiOver2) .Translate(0f, 0.9f, -12.5f) .Color(_color); }
public void AsEnumerableTest() { var obj = Composite.Create(new[] { Composite.CreateValue(new Simple { Number = 1, }), Composite.Create(new [] { Composite.CreateValue(new Simple { Number = 2, }), Composite.CreateValue(new Simple { Number = 3, }), Composite.Create(new [] { Composite.CreateValue(new Simple { Number = 4, }), Composite.CreateValue(new Simple { Number = 5, }), }.AllowTake(1)), }), Composite.CreateValue(new Simple { Number = 6, }), }.AllowTake(2)); var result = obj.AsEnumerable().Take(4).ToArray(); for (int i = 1; i <= 4; i++) { Assert.Equal(i, result[i - 1].Number); } Assert.Throws <InvalidOperationException>(() => { obj.AsEnumerable().Take(5).ToArray(); }); }
public BottomFin() { var half = Polygon <V> .FromVec2s( new Vec2 (-0.8f, 0f), new Vec2 (0.8f, 0f), new Vec2 (0.6f, -0.5f), new Vec2 (-0f, -0.6f)) .ExtrudeToScale( depth: 0.05f, targetScale: 0.7f, steepness: 3f, numSteps: 2, includeFrontFace: false) .FilterVertices(v => !v.Facing(Dir3D.Up)); Geometry = Composite.Create( Stacking.StackForward(half, half.ReflectZ())) .RotateY(MathHelper.PiOver2) .RotateZ(15f.Radians()) .RotateX(6f.Radians()) .Translate(0.5f, -0.6f, -10.25f) .Color(_color); }
public void InvalidParametersTest() { var obj = Composite.Create(new[] { Composite.CreateValue(new Simple()), }); Assert.Throws <ArgumentNullException>(() => obj.Select <Simple, int>(null)); }