private static CsgObject MakeThisSymmetric(CsgObject o) { Union u = new Union(); u.Add(o); u.Add(o.NewMirrorAccrossX()); return(u); }
private static CsgObject DoSomethingSymmetric() { CsgObject o = GimmeACompositionSpheresOnly(); Union u = new Union(); u.Add(o); u.Add(o.NewMirrorAccrossX()); return(u); }
private static CsgObject StringEmUp() { /* * Pick a primitive type (or a pattern or random) * Pick a start and end size (or go up and down...) * Pick a distance? * Pick a line/parabola/periodic function * Go for it */ Union u = new Union(); double start = GimmeABoundedDouble(5, 50); double end = GimmeABoundedDouble(60, 200); int howMany = _rand.Next(5, 20); double sizeIncrement = (start - end) / (double)howMany; double z = 0; List <double> radii = GimmeSomeBoundedDoubles(start, end, howMany); for (int i = 0; i < howMany; i++) { double radius = radii[i] * (end - start); Sphere awe = new Sphere(radius); Translate t = new Translate(awe as CsgObject, new Vector3(0, 0, z)); u.Add(t); z += radius; } return(u); }
private static CsgObject MakeRandomSpheres() { int makeThisMany = _rand.Next(20); Union u = new Union(); Sphere[] spheres = new Sphere[makeThisMany]; Vector3[] translations = new Vector3[makeThisMany]; for (int i = 0; i < makeThisMany; i++) { Sphere newS = null; Sphere attachToMe = null; int whichToAttachTo = -1; if (i > 0) { whichToAttachTo = _rand.Next(i); attachToMe = spheres[whichToAttachTo]; } newS = new Sphere(GimmeABoundedDouble(_smallest, _largest)); Translate t = null; Vector3 translation = Vector3.NegativeInfinity; if (attachToMe != null) { double aRadius = attachToMe.Radius; double bRadius = newS.Radius; double overlap = GimmeABoundedDouble(0.05, 0.95); Vector3 direction = GimmeADirection(); double maxLength = aRadius + bRadius; double minLength = Math.Abs(aRadius - bRadius); double range = maxLength - minLength; double goThisFar = range * overlap; translation = translations[whichToAttachTo] + direction * goThisFar; t = new Translate(newS, translation); } else { translation = new Vector3(GimmeABoundedDouble(0, _xMax), GimmeABoundedDouble(0, _yMax), GimmeABoundedDouble(0, _zMax)); t = new Translate(newS, translation); } translations[i] = translation; spheres[i] = newS; double diffMe = GimmeABoundedDouble(0, 1); if (diffMe >= 0.75) { Difference d = new Difference(u, new Translate(newS, translation)); u = new Union(); u.Add(d); } else { u.Add(new Translate(newS, translation)); } } return(u); }
private static CsgObject SphereWithSurfaceSpheres() { Union u = new Union(); Sphere mainSphere = new Sphere(GimmeABoundedDouble(_smallest, _largest)); u.Add(mainSphere); int howManyBumps = _rand.Next(20); //size range is 0.25-0.75 of main sphere's radius //double howMuchToUse = GimmeABoundedDouble(0.1, 1); for (int i = 0; i < howManyBumps; i++) { Vector3 direction = GimmeADirection(); double radius = GimmeABoundedDouble(0.25, 0.75) * mainSphere.Radius; Sphere bump = new Sphere(radius); Translate t = new Translate(bump, mainSphere.GetCenter() + direction * mainSphere.Radius); u.Add(t); } return(u); }
private static CsgObject SphereWithInnerSpheres() { int howMany = _rand.Next(2, 5); double mainRadius = 200; double thickness = 10; double overlap = 1.1; Union u = new Union(); for (int i = 0; i < howMany; i++) { var newSphere = HollowSphereWithHoles(mainRadius - thickness * i, thickness * overlap); u.Add(newSphere); } return(u); }
public RangeSetHandle Simplify() { switch (this.handles.Count) { case 0: return(new Static(RangeSet <Codepoint> .Empty, this.Negate)); case 1: var union = this.handles[0] as Union; if (union != null) { var result = new Union(union.Negate ^ this.Negate); foreach (var handle in union.handles) { result.Add(handle); } return(result.Simplify()); } if (!this.Negate) { return(this.handles[0]); } var stat = this.handles[0] as Static; if (stat != null) { return(new Static(stat.Charset, !stat.Negate)); } var named = this.handles[0] as Named; if (named != null) { return(new Named(named.Name, !named.Negate)); } var cls = this.handles[0] as Class; if (cls != null) { return(new Class(cls.CharSetClass, !cls.Negate)); } break; } return(this); }
internal static string[] MergeConstantFields(string[] ConstantFields1, string[] ConstantFields2) { if (ConstantFields1 == null) { return(ConstantFields2); } else if (ConstantFields2 == null) { return(ConstantFields1); } else { List <string> Union = null; foreach (string s in ConstantFields2) { if (Array.IndexOf <string>(ConstantFields1, s) >= 0) { continue; } if (Union == null) { Union = new List <string>(); Union.AddRange(ConstantFields1); } Union.Add(s); } if (Union == null) { return(ConstantFields1); } else { return(Union.ToArray()); } } }
//private static CsgObject SphereDecisions() //{ // //I have a sphere. I'll do something to it. Then I'll make another sphere. Maybe I'll come back to this one. Maybe I"ll keep going. I don't know... //} private static CsgObject VaryOnlyXYorZ() { Union u = new Union(); int howMany = _rand.Next(5, 20); double radius = GimmeABoundedDouble(_smallest, _largest); Vector3 center = Vector3.Zero; List <double> radii = GimmeSomeBoundedDoubles(0, 100, howMany); for (int i = 0; i < howMany; i++) { Vector3 direction = GimmeAnAxisDirection(); Vector3 translation = center + direction * radius; center = center + direction * radius; double percentChange = GimmeABoundedDouble(0, 2) * radii[i]; double biggerOrSmaller = GimmeABoundedDouble(0, 1); radius = biggerOrSmaller >= 0.5 ? radius + radius * percentChange : radius - radius * percentChange; Sphere awe = new Sphere(radius); Translate t = new Translate(awe, translation); u.Add(t); } return(u); }
internal void ChangeRelation(Guild guild, GuildUnionRequestType requestType, GuildRelationShipType relationShipType) { switch (requestType) { case GuildUnionRequestType.Join: switch (relationShipType) { case GuildRelationShipType.Union: if (Union.Count == 0) { Union.Add(this); } Union.Add(guild); guild.Union = Union; break; case GuildRelationShipType.Rivals: Rival.Add(guild); guild.Rival.Add(this); break; } break; case GuildUnionRequestType.BreakOff: switch (relationShipType) { case GuildRelationShipType.Union: if (this == guild) { Union[0].ChangeRelation(this, requestType, relationShipType); return; } Union.Remove(guild); if (Union.Count == 1) { Union.Remove(this); } guild.Union = new List <Guild>(); break; case GuildRelationShipType.Rivals: Rival.Remove(guild); guild.Rival.Remove(this); break; } break; } using (var game = new GameContext()) { var guildDtoA = (from g in game.Guilds where g.GuildId == Index select g).Single(); var guildDtoB = (from g in game.Guilds where g.GuildId == guild.Index select g).Single(); guildDtoA.AllianceId = Union.FirstOrDefault()?.Index ?? null; guildDtoB.AllianceId = Union.FirstOrDefault()?.Index ?? null; for (var i = 0; i < 5; i++) { var rivA = Rival.Count > i ? (int?)Rival[i].Index : null; var rivB = guild.Rival.Count > i ? (int?)guild.Rival[i].Index : null; guildDtoA.Set("Rival" + (i + 1), rivA); guildDtoB.Set("Rival" + (i + 1), rivB); } game.Update(guildDtoA); game.Update(guildDtoB); game.SaveChanges(); } }
public MatterCadGuiWidget() { //rootUnion.Add(DemoProjects.PowerSupply()); //works but cutout is not working rootUnion.Add(SimplePartTester.Assembly()); //rootUnion.Add(new BoxPrimitive(8, 20, 10)); //rootUnion.Add(new LinearExtrude(new double[] { 1.1, 2.2, 3.3, 6.3 }, 7)); //rootUnion.Add( // new Difference (new Translate(new Cylinder(10, 40), 5, 10, 5), new Translate(new BoxPrimitive(10, 10, 20,"test",true), 5, 20, 5))); SuspendLayout(); verticleSpliter = new Splitter(); // pannel 1 stuff textSide = new FlowLayoutWidget(FlowDirection.TopToBottom); objectEditorView = new GuiWidget(300, 500); objectEditorList = new FlowLayoutWidget(); textEdit = new TextEditWidget("test", 300, 400); textEdit.HAnchor = HAnchor.ParentLeftRight; // textEdit.MinimumSize = new Vector2(Math.Max(textEdit.MinimumSize.x, pixelWidth), Math.Max(textEdit.MinimumSize.y, pixelHeight)); textEdit.VAnchor = VAnchor.ParentBottomTop; textEdit.Multiline = true; textEdit.BackgroundColor = RGBA_Bytes.Yellow; // objectEditorList.AddChild(textEdit);//CsgEditorBase.CreateEditorForCsg(rootUnion)); // objectEditorView.AddChild(objectEditorList); // objectEditorView.BackgroundColor = RGBA_Bytes.Orange; // objectEditorView.Text = "Hello World!"; objectEditorView.LocalBounds = new RectangleDouble(0, 0, 200, 300); textSide.LocalBounds = new RectangleDouble(0, 0, 200, 300); // objectEditorView.DebugShowBounds = true; textSide.AddChild(textEdit); textSide.BoundsChanged += new EventHandler(textSide_BoundsChanged); FlowLayoutWidget topButtonBar = new FlowLayoutWidget(); Button loadMatterScript = new Button("Load Matter Script"); loadMatterScript.Click += loadMatterScript_Click; topButtonBar.AddChild(loadMatterScript); outputScad = new Button("Output SCAD"); outputScad.Click += OutputScad_Click; topButtonBar.AddChild(outputScad); textSide.AddChild(topButtonBar); FlowLayoutWidget bottomButtonBar = new FlowLayoutWidget(); Button loadStl = new Button("Load STL"); loadStl.Click += LoadStl_Click; bottomButtonBar.AddChild(loadStl); textSide.AddChild(bottomButtonBar); // // pannel 2 stuff FlowLayoutWidget renderSide = new FlowLayoutWidget(FlowDirection.TopToBottom); renderSide.AnchorAll(); trackBallWidget = new TrackballTumbleWidget(); trackBallWidget.DrawGlContent += new EventHandler(glLightedView_DrawGlContent); renderSide.AddChild(trackBallWidget); verticleSpliter.Panel2.AddChild(renderSide); verticleSpliter.Panel1.AddChild(textSide); ResumeLayout(); objectEditorView.AnchorAll(); AnchorAll(); verticleSpliter.AnchorAll(); textSide.AnchorAll(); trackBallWidget.AnchorAll(); AddChild(verticleSpliter); BackgroundColor = RGBA_Bytes.White; }
private static CsgObject SphereWithSmartSurfaceSpheres() { Union u = new Union(); Sphere mainSphere = new Sphere(GimmeABoundedDouble(_smallest, _largest)); u.Add(mainSphere); int howManyBumps = _rand.Next(5) + 2; for (int i = 0; i < howManyBumps; i++) { Vector3 direction = GimmeADirection(); double radius = GimmeABoundedDouble(0.25, 0.75) * mainSphere.Radius; Sphere bump = new Sphere(radius); Translate t = new Translate(bump, mainSphere.GetCenter() + direction * mainSphere.Radius); u.Add(t); double doOpposite = GimmeABoundedDouble(0, 1); double doOneAxis = GimmeABoundedDouble(0, 1); double doOtherAxis = GimmeABoundedDouble(0, 1); Vector3 orthogonalOne = CrossProduct(direction, new Vector3(direction.z, direction.x, direction.y)); Vector3 orthogonalTwo = CrossProduct(direction, orthogonalOne); if (doOpposite >= 0.25) { double diff = GimmeABoundedDouble(0, 1); Sphere opposite = new Sphere(radius); Translate to = new Translate(opposite, mainSphere.GetCenter() - direction * mainSphere.Radius); if (diff >= 0.75) { Difference d = new Difference(u, to); u = new Union(); u.Add(d); } else { u.Add(to); } } if (doOneAxis >= 0.66) { double diff = GimmeABoundedDouble(0, 1); Sphere oneOne = new Sphere(radius); Sphere oneTwo = new Sphere(radius); Translate tOne = new Translate(oneOne, mainSphere.GetCenter() + orthogonalOne * mainSphere.Radius); Translate tTwo = new Translate(oneOne, mainSphere.GetCenter() - orthogonalOne * mainSphere.Radius); if (diff >= 0.75) { Difference d = new Difference(u, tOne); Difference d2 = new Difference(d, tTwo); u = new Union(); u.Add(d2); } else { u.Add(tOne); u.Add(tTwo); } } if (doOtherAxis >= 0.66) { double diff = GimmeABoundedDouble(0, 1); Sphere oneOne = new Sphere(radius); Sphere oneTwo = new Sphere(radius); Translate tOne = new Translate(oneOne, mainSphere.GetCenter() + orthogonalTwo * mainSphere.Radius); Translate tTwo = new Translate(oneOne, mainSphere.GetCenter() - orthogonalTwo * mainSphere.Radius); if (diff >= 0.5) { Difference d = new Difference(u, tOne); Difference d2 = new Difference(d, tTwo); u = new Union(); u.Add(d2); } else { u.Add(tOne); u.Add(tTwo); } } } return(u); }
//private static CsgObject AtomDiagram() //{ //} private static CsgObject SingleComposition() { //TODO: make some bounds on how crazy or tame this goes with relative sizes...IE does the main thing //get more or less emphasis? CsgObject returnMe = null; Union u = new Union(); CsgObject box = new Box(new Vector3(150, 150, 150)); int whichOne = _rand.Next(2); List <CsgObject> unions = new List <CsgObject>(); List <CsgObject> differences = new List <CsgObject>(); //TODO: Order prolly matters here? Maybe? So right now we're gonna build lists, do unions, then //do differences. Maybe later we should do it in whatever order they happen in, or at least //consider it... //foreach (Vector3 corner in ) //{ //int which = _rand.Next(2); //switch (which) //{ // case 0: // solid = new Box(new Vector3(150, 150, 150)); // break; // case 1: // solid = new Sphere(150); // break; // default: // solid = new Box(new Vector3(150, 150, 150)); // break; //} //} u.Add(box as CsgObject); double averageSize = (box.XSize + box.YSize + box.ZSize) / 3.0; List <Vector3> boxVertexes = new List <Vector3>(); Vector3 boxCenter = box.GetCenter(); double halfX = box.XSize / 2; double halfY = box.YSize / 2; double halfZ = box.ZSize / 2; for (int i = 0; i < 2; i++) { double x = -1 * halfX + i * box.XSize; for (int j = 0; j < 2; j++) { double y = -1 * halfY + j * box.YSize; for (int k = 0; k < 2; k++) { double z = -1 * halfZ + k * box.ZSize; Vector3 newVertex = new Vector3(x, y, z); boxVertexes.Add(newVertex); } } } foreach (Vector3 attachPoint in boxVertexes) { CsgObject joinThis = null; double doWhat = _rand.NextDouble(); if (doWhat < 0.33) { joinThis = GimmeAPrimitive(GimmeABoundedDouble(averageSize * 0.25, averageSize * 0.75), attachPoint); differences.Add(joinThis); } else if (doWhat < 0.85) { joinThis = GimmeAPrimitive(GimmeABoundedDouble(averageSize * 0.25, averageSize * 0.75), attachPoint); unions.Add(joinThis); } else { joinThis = null; } } foreach (var thing in unions) { u.Add(thing); returnMe = u; } if (differences.Count > 0) { Difference d = new Difference(returnMe, differences[0]); for (int i = 1; i < differences.Count; i++) { d.AddToSubtractList(differences[i]); } returnMe = d; } return(returnMe); }
private static void DoABunchOneMethod(int howMany, Func <CsgObject> method) { for (int i = 0; i < howMany; i++) { //Console.Out.WriteLine(i); try { CsgObject theThing = null; double moreThanOne = _rand.NextDouble(); if (moreThanOne >= 0) { Union u = new Union(); int howManyMethods = _rand.Next(5); List <CsgObject> unions = new List <CsgObject>(); List <CsgObject> differences = new List <CsgObject>(); for (int j = 0; j < howManyMethods; j++) { double addOrRemove = _rand.NextDouble(); if (addOrRemove <= 0.75 || j == 0) { var addMe = method(); unions.Add(addMe); } else { var diffMe = method(); differences.Add(diffMe); } } foreach (var thing in unions) { u.Add(thing); } theThing = u; if (differences.Count > 0) { Difference d = new Difference(theThing, differences[0]); for (int j = 1; j < differences.Count; j++) { d.AddToSubtractList(differences[j]); } theThing = d; } } else { theThing = method(); } DateTime now = DateTime.Now; if (theThing == null) { theThing = method(); } //Console.Out.WriteLine("Writing file {0}", i); //OpenSCadOutput.Save(theThing, string.Format("{0}.scad", now.ToString("yyMMddHHmmssff"))); MoveAndScaleAndWriteToFile(theThing, string.Format("{0}.scad", now.ToString("yyMMddHHmmssff"))); } catch (Exception e) { //DON'T CARE!!! HAHAHA Console.Out.WriteLine("EXCEPTION: {0}", e.Message); } } }
private static void DoABunchSpheresOnly(int howMany) { for (int i = 0; i < howMany; i++) { //Console.Out.WriteLine(i); try { CsgObject theThing = null; double moreThanOne = _rand.NextDouble(); if (moreThanOne >= 0) { Union u = new Union(); int howManyMethods = _rand.Next(5); List <CsgObject> unions = new List <CsgObject>(); List <CsgObject> differences = new List <CsgObject>(); for (int j = 0; j < howManyMethods; j++) { double addOrRemove = _rand.NextDouble(); if (addOrRemove <= 0.75 || j == 0) { var addMe = GimmeACompositionSpheresOnly(); unions.Add(addMe); } else { var diffMe = GimmeACompositionSpheresOnly(); differences.Add(diffMe); } } foreach (var thing in unions) { u.Add(thing); } theThing = u; if (differences.Count > 0) { Difference d = new Difference(theThing, differences[0]); for (int j = 1; j < differences.Count; j++) { d.AddToSubtractList(differences[j]); } theThing = d; } } else { theThing = GimmeACompositionSpheresOnly(); } DateTime now = DateTime.Now; if (theThing == null) { theThing = GimmeACompositionSpheresOnly(); } var symmetry = _rand.NextDouble(); if (symmetry >= _symmetryLikelihood) { theThing = MakeThisSymmetric(theThing); } //Console.Out.WriteLine("Writing file {0}", i); MoveAndScaleAndWriteToFile(theThing, string.Format("{0}.scad", "image-" + i)); } catch (Exception e) { //DON'T CARE!!! HAHAHA Console.Out.WriteLine("EXCEPTION: {0}", e.Message); } } }
public static void Box(this Union rootUnion, double sizeX, double sizeY, double sizeZ) { rootUnion.Add(new Box(sizeX, sizeY, sizeZ)); }