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 ColorMapEdit(float domainMin, float domainMax, float knobWidth, float minVisualLength, ColorMap <Vec3> colorMap, Reaction <ColorMap <Vec3> > changed) : base(VisualDirection.Horizontal, HAlign.Left, VAlign.Top, false, false, Enumerable.Empty <Control> ()) { _bar = new ColorMapBar(domainMin, domainMax, knobWidth, minVisualLength, colorMap, changed, React.By <int?> (ItemSelected)); _picker = new ColorPicker(VisualDirection.Vertical, knobWidth, minVisualLength - (3f * knobWidth), Color.Black, true, React.By <Color> (ColorChanged)); Controls.AddRange(EnumerableExt.Enumerate <Control> (_bar, _picker) .Select(c => new Tuple <Control, Reaction <Control> > (c, null))); }
/* * The only thing left is to define the implementation for * `IArbitrary<Command>`. We register it in the static constructor. We can * use the `Arbitrary<T>` wrapper class as a helper. */ static Command() { Arbitrary.Register(new Arbitrary <Command> ( /* * The generator consist of two branches. We will use the `OneOf` * combinator to first randomly chooses whether we push a digit * button or an operator button. */ Gen.OneOf( /* * If the digit button is selected, then we choose a random * number from the range of 0 to 9, and create a `Digit` * command for the chosen number. */ from i in Gen.ChooseInt(0, 10) select Digit(i), /* * If the winner was the other branch, then we choose a random * command from the set of operators. */ Gen.ChooseFrom(Add, Subtract, Multiply, Divide, Equals) ), /* * How to implement shrinking is a bit harder to figure out. * Shrinking of operators is not something we can easily define, * so we will be content with shrinking just the digit command * utilizing the shrinking defined for integers. We achieve the * true power of shrinking by reducing the lists of commands to * shorter examples when LinqCheck finds a failing sequence. This * functionality we get out-of-the-box without any additional code. */ com => com is _Digit n ? Arbitrary.Shrink(n.Value).Select(Digit) : EnumerableExt.Enumerate(com) )); }
public ColorPicker(VisualDirection direction, float knobWidth, float minVisualLength, Color color, bool preview, Reaction <Color> changed) : base(preview ? direction : direction.Opposite(), HAlign.Left, VAlign.Top, true, false, Enumerable.Empty <Control> ()) { Changed = changed; _hue = ColorSlider.Hue(direction, knobWidth, minVisualLength, color, React.By <float> (ChangeHue)); _saturation = ColorSlider.Saturation(direction, knobWidth, minVisualLength, color, React.By <float> (ChangeSaturation)); _brightness = ColorSlider.Brightness(direction, knobWidth, minVisualLength, color, React.By <float> (ChangeBrightness)); var controls = EnumerableExt.Enumerate <Control> (_hue, _saturation, _brightness); var contents = preview ? EnumerableExt.Enumerate( new Container(direction, HAlign.Center, VAlign.Center, false, false, new Container(direction.Opposite(), HAlign.Left, VAlign.Top, false, false, controls), Label.ColorPreview(() => _value, new SizeF(3.5f * knobWidth, 3.5f * knobWidth)))) : controls; Controls.AddRange(contents.Select(c => new Tuple <Control, Reaction <Control> > (c, null))); }
public EngineIntake(CockpitFuselage cockpitFuselage) { var startNode = cockpitFuselage.XSectionStart; XSection = CrossSection(startNode.position, -cockpitFuselage.XSection.Vertices.Furthest(Dir3D.Up).First().position.Y, 20); var transforms = from s in EnumerableExt.Range(0.25f, 2f, 0.25f) let scaleFactor = 1f + (0.2f * s.Pow(0.5f)) select Mat.Translation <Mat4> (0f, 0f, -s) * Mat.Scaling <Mat4> (scaleFactor, scaleFactor, 1f) .RelativeTo(new Vec3(0f, startNode.position.Y, 0f)); Intake = XSection .Inset <P, V> (0.9f, 0.9f) .Stretch(transforms, true, false) .Color(_color); RearXSection = XSection.Transform(transforms.Last()); BellyXSection = Path <P, Vec3> .FromVecs( from v in cockpitFuselage.Fuselage.Vertices.Furthest (Dir3D.Back) where v.position.Y < -0.1f select v.position); var scalePoint = new Vec3(0f, BellyXSection.Vertices.First().position.Y, 0f); Belly = EnumerableExt.Enumerate(BellyXSection, BellyXSection.Transform(Mat.Translation <Mat4> (0f, 0f, -1f) * Mat.Scaling <Mat4> (1.45f, 1f, 1f).RelativeTo(scalePoint)), BellyXSection.Transform(Mat.Translation <Mat4> (0f, 0f, -2f) * Mat.Scaling <Mat4> (1.9f, 1.25f, 1f).RelativeTo(scalePoint)), BellyXSection.Transform(Mat.Translation <Mat4> (0f, 0f, -3f) * Mat.Scaling <Mat4> (1.9f, 1.3f, 1f).RelativeTo(scalePoint))) .Extrude <V, P> (false, false) .Color(_color); }
public void TestMin() { /* * The first method we test is the `Math.Min`. It returns the * minimum of two numbers. So, let's generate two random integers * to test it. We do this by writing a LINQ expression which * calls the `Prop.ForAll` method twice. The random integers are * assigned to the variables `x` and `y`. */ (from x in Prop.ForAll <int> () from y in Prop.ForAll <int> () /* * Now we can call `Math.Min` to calculate the minimum of `x` * and `y`. We assign the result to the variable `minxy`. Notice that * this time we are not generating a random value but just evaluating * an expression, so we use the `let` clause instead of `from`. */ let minxy = Math.Min(x, y) /* * Let's still generate a third arbitrary integer `z` and calculate * the minimum of `x`, `y`, and `z`. */ from z in Prop.ForAll <int> () let minxyz = Math.Min(minxy, z) /* * We now got all the values we need, so we complete the LINQ * expression with the `select` clause that returns our values to the * next phase. */ select new { x, y, z, minxy, minxyz }) /* * Essentially, we have set up a test case dispenser that produces * three random integers and calculates their minima. Now we can * start checking the properties these values should have. The first * property is obvious: `minxy` should contain the minimum of `x` * and `y`. Let's check that this is true. */ .Check(t => t.minxy == (t.x < t.y ? t.x : t.y)) /* * The previous line defines a property that should hold for all input * values. The `Prop.Check` extension method takes a lambda expression * to which the randomly generated test cases are fed, and the * expression should evaluate to true, if the property holds. If it * returns false or throws an exception, the property fails. The input * values are wrapped in anonymous object that we assign to parameter * `t`. The actual values are in the fields of this object. * * Naturally we should not use the `Math.Min` function to check our * property, since that is the function we are testing. Instead we * use the ternary `?` operator to do this. * * We don't need to stop here. Let's check that the Min method is * symmetric, that is, the order of the arguments should not matter. */ .Check(t => t.minxy == Math.Min(t.y, t.x)) /* * Lastly we check that the minimum operation is transitive as the * `<=` operator is. For this we need the third random value `z`. We * check that the minimum of `x`, `y`, `z` is the smallest of them. For * that we utilize the `Enumerable.Min` function and a helper function * from the ExtensionCord library. */ .Check(t => t.minxyz == EnumerableExt.Enumerate(t.x, t.y, t.z).Min()); }
public virtual IEnumerable <SceneNode> Traverse() { return(EnumerableExt.Enumerate(this)); }