public static Vector2D? IntersectLineLine( Vector2D s1, Vector2D e1, Vector2D s2, Vector2D e2 ) { Rect2D aabb1 = new Rect2D( s1, e1 ); Rect2D aabb2 = new Rect2D( s2, e2 ); if ( !aabb1.IntersectsWith( aabb2 ) ) return null; double x1 = s1.X; double x2 = e1.X; double x3 = s2.X; double x4 = e2.X; double y1 = s1.Y; double y2 = e1.Y; double y3 = s2.Y; double y4 = e2.Y; double denom = ( x1 - x2 ) * ( y3 - y4 ) - ( y1 - y2 ) * ( x3 - x4 ); if ( Math.Abs( denom ) < 1e-4 ) return null; double px = ( ( x1 * y2 - y1 * x2 ) * ( x3 - x4 ) - ( x1 - x2 ) * ( x3 * y4 - y3 * x4 ) ) / denom; double py = ( ( x1 * y2 - y1 * x2 ) * ( y3 - y4 ) - ( y1 - y2 ) * ( x3 * y4 - y3 * x4 ) ) / denom; Vector2D p = new Vector2D( px, py ); double l1 = ( p - s1 ).Length; double l2 = ( p - e1 ).Length; if ( l1 + l2 > ( s1 - e1 ).Length + 1e-3 ) return null; return p; }
private void btnScreenShot_Click(object sender, RoutedEventArgs e) { int maxsize = 3000; Geometry geometry = Tree.picActiveLinks.Clip; Rect2D contentBounds = Tree.picActiveLinks.ContentBounds; contentBounds *= 1.2; double aspect = contentBounds.Width / contentBounds.Height; double xmax = contentBounds.Width; double ymax = contentBounds.Height; if (aspect > 1 && xmax > maxsize) { xmax = maxsize; ymax = xmax / aspect; } if (aspect <1 & ymax> maxsize) { ymax = maxsize; xmax = ymax * aspect; } ClipboardBmp = new RenderTargetBitmap((int)xmax, (int)ymax, 96, 96, PixelFormats.Pbgra32); VisualBrush db = new VisualBrush(Tree.SkillTreeVisual); db.ViewboxUnits = BrushMappingMode.Absolute; db.Viewbox = contentBounds; DrawingVisual dw = new DrawingVisual(); using (DrawingContext dc = dw.RenderOpen()) { dc.DrawRectangle(db, null, new Rect(0, 0, xmax, ymax)); } ClipboardBmp.Render(dw); ClipboardBmp.Freeze(); Clipboard.SetImage(ClipboardBmp); image1.Fill = new VisualBrush(Tree.SkillTreeVisual); }
public static Vector2D?IntersectLineLine(Vector2D s1, Vector2D e1, Vector2D s2, Vector2D e2) { Rect2D aabb1 = new Rect2D(s1, e1); Rect2D aabb2 = new Rect2D(s2, e2); if (!aabb1.IntersectsWith(aabb2)) { return(null); } double x1 = s1.X; double x2 = e1.X; double x3 = s2.X; double x4 = e2.X; double y1 = s1.Y; double y2 = e1.Y; double y3 = s2.Y; double y4 = e2.Y; double denom = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4); if (Math.Abs(denom) < 1e-4) { return(null); } double px = ((x1 * y2 - y1 * x2) * (x3 - x4) - (x1 - x2) * (x3 * y4 - y3 * x4)) / denom; double py = ((x1 * y2 - y1 * x2) * (y3 - y4) - (y1 - y2) * (x3 * y4 - y3 * x4)) / denom; Vector2D p = new Vector2D(px, py); double l1 = (p - s1).Length; double l2 = (p - e1).Length; if (l1 + l2 > (s1 - e1).Length + 1e-3) { return(null); } return(p); }
public SkillTree(String treestring, startLoadingWindow start = null, UpdateLoadingWindow update = null, closeLoadingWindow finish = null) { bool displayProgress = (start != null && update != null && finish != null); // RavenJObject jObject = RavenJObject.Parse( treestring.Replace( "Additional " , "" ) ); JsonSerializerSettings jss = new JsonSerializerSettings { Error = delegate(object sender, Newtonsoft.Json.Serialization.ErrorEventArgs args) { Debug.WriteLine(args.ErrorContext.Error.Message); args.ErrorContext.Handled = true; } }; var inTree = JsonConvert.DeserializeObject <PoEClasses.PoESkillTree>(treestring.Replace("Additional ", ""), jss); foreach (var obj in inTree.skillSprites) { if (obj.Key.Contains("inactive")) { continue; } iconActiveSkills.Images[obj.Value[3].filename] = null; foreach (var o in obj.Value[3].coords) { iconActiveSkills.SkillPositions[o.Key] = new KeyValuePair <Rect, string>(new Rect(o.Value.x, o.Value.y, o.Value.w, o.Value.h), obj.Value[3].filename); } } foreach (var obj in inTree.skillSprites) { if (obj.Key.Contains("active")) { continue; } iconActiveSkills.Images[obj.Value[3].filename] = null; foreach (var o in obj.Value[3].coords) { iconActiveSkills.SkillPositions[o.Key] = new KeyValuePair <Rect, string>(new Rect(o.Value.x, o.Value.y, o.Value.w, o.Value.h), obj.Value[3].filename); } } foreach (var ass in inTree.assets) { assets[ass.Key] = new Asset(ass.Key, ass.Value.ContainsKey(0.3835f)?ass.Value[0.3835f]:ass.Value.Values.First()); } if (displayProgress) { start( ); } iconActiveSkills.OpenOrDownloadImages(update); iconInActiveSkills.OpenOrDownloadImages(update); if (displayProgress) { finish( ); } foreach (var c in inTree.characterData) { CharBaseAttributes[c.Key] = new Dictionary <string, float>() { { "+# to Strength", c.Value.base_str }, { "+# to Dexterity", c.Value.base_dex }, { "+# to Intelligence", c.Value.base_int } }; } foreach (var nd in inTree.nodes) { Skillnodes.Add(nd.id, new SkillTree.SkillNode() { id = nd.id, name = nd.dn, attributes = nd.sd, orbit = nd.o, orbitIndex = nd.oidx, icon = nd.icon, linkID = nd.ot, g = nd.g, da = nd.da, ia = nd.ia, ks = nd.ks, not = nd.not, sa = nd.sa, Mastery = nd.m, spc = nd.spc.Count() > 0?(int?)nd.spc[0]:null }); } List <ushort[]> links = new List <ushort[]>( ); foreach (var skillNode in Skillnodes) { foreach (ushort i in skillNode.Value.linkID) { if ( links.Count( nd => (nd[0] == i && nd[1] == skillNode.Key) || nd[0] == skillNode.Key && nd[1] == i) == 1) { continue; } links.Add(new ushort[] { skillNode.Key, i }); } } foreach (ushort[] ints in links) { if (!Skillnodes[ints[0]].Neighbor.Contains(Skillnodes[ints[1]])) { Skillnodes[ints[0]].Neighbor.Add(Skillnodes[ints[1]]); } if (!Skillnodes[ints[1]].Neighbor.Contains(Skillnodes[ints[0]])) { Skillnodes[ints[1]].Neighbor.Add(Skillnodes[ints[0]]); } } foreach (var gp in inTree.groups) { NodeGroup ng = new NodeGroup(); ng.OcpOrb = gp.Value.oo; ng.Position = new Vector2D(gp.Value.x, gp.Value.y); ng.Nodes = gp.Value.n; NodeGroups.Add(ng); } foreach (SkillTree.NodeGroup group in NodeGroups) { foreach (ushort node in group.Nodes) { Skillnodes[node].NodeGroup = group; } } TRect = new Rect2D(new Vector2D(inTree.min_x * 1.1, inTree.min_y * 1.1), new Vector2D(inTree.max_x * 1.1, inTree.max_y * 1.1)); InitNodeSurround( ); DrawNodeSurround( ); DrawNodeBaseSurround( ); DrawSkillIconLayer( ); DrawBackgroundLayer( ); InitFaceBrushesAndLayer( ); DrawLinkBackgroundLayer( ); InitOtherDynamicLayers( ); CreateCombineVisual( ); Regex regexAttrib = new Regex("[0-9]*\\.?[0-9]+"); foreach (var skillNode in Skillnodes) { skillNode.Value.Attributes = new Dictionary <string, List <float> >( ); foreach (string s in skillNode.Value.attributes) { List <float> values = new List <float>( ); foreach (Match m in regexAttrib.Matches(s)) { if (!AttributeTypes.Contains(regexAttrib.Replace(s, "#"))) { AttributeTypes.Add(regexAttrib.Replace(s, "#")); } if (m.Value == "") { values.Add(float.NaN); } else { values.Add(float.Parse(m.Value, System.Globalization.CultureInfo.InvariantCulture)); } } string cs = (regexAttrib.Replace(s, "#")); skillNode.Value.Attributes[cs] = values; } } Solver = new Solver(Skillnodes); }
public SkillTree(String treestring, startLoadingWindow start = null, UpdateLoadingWindow update = null, closeLoadingWindow finish = null) { bool displayProgress = ( start != null && update != null && finish != null ); // RavenJObject jObject = RavenJObject.Parse( treestring.Replace( "Additional " , "" ) ); JsonSerializerSettings jss = new JsonSerializerSettings { Error = delegate(object sender, Newtonsoft.Json.Serialization.ErrorEventArgs args) { Debug.WriteLine(args.ErrorContext.Error.Message); args.ErrorContext.Handled = true; } }; var inTree = JsonConvert.DeserializeObject<PoEClasses.PoESkillTree>(treestring.Replace("Additional ", ""), jss); int qindex = 0; foreach (var obj in inTree.skillSprites) { if (obj.Key.Contains("inactive")) continue; iconActiveSkills.Images[obj.Value[3].filename] = null; foreach (var o in obj.Value[3].coords) { iconActiveSkills.SkillPositions[o.Key] = new KeyValuePair<Rect, string>(new Rect(o.Value.x, o.Value.y, o.Value.w, o.Value.h), obj.Value[3].filename); } } foreach (var obj in inTree.skillSprites) { if (obj.Key.Contains("active")) continue; iconActiveSkills.Images[obj.Value[3].filename] = null; foreach (var o in obj.Value[3].coords) { iconActiveSkills.SkillPositions[o.Key] = new KeyValuePair<Rect, string>(new Rect(o.Value.x, o.Value.y, o.Value.w, o.Value.h), obj.Value[3].filename); } } qindex = 0; foreach(var ass in inTree.assets) { assets[ass.Key] = new Asset(ass.Key,ass.Value.ContainsKey(0.3835f)?ass.Value[0.3835f]:ass.Value.Values.First()); } if ( displayProgress ) start( ); iconActiveSkills.OpenOrDownloadImages(update ); iconInActiveSkills.OpenOrDownloadImages(update ); if ( displayProgress ) finish( ); foreach( var c in inTree.characterData) { CharBaseAttributes[c.Key] = new Dictionary<string, float>() { { "+# to Strength", c.Value.base_str }, { "+# to Dexterity", c.Value.base_dex }, { "+# to Intelligence", c.Value.base_int } }; } foreach (var nd in inTree.nodes) { Skillnodes.Add(nd.id, new SkillTree.SkillNode() { id = nd.id, name = nd.dn, attributes = nd.sd, orbit = nd.o, orbitIndex =nd.oidx, icon = nd.icon, linkID =nd.ot, g = nd.g, da = nd.da, ia = nd.ia, ks = nd.ks, not = nd.not, sa = nd.sa, Mastery = nd.m, spc=nd.spc.Count()>0?(int?)nd.spc[0]:null }); } List<ushort[]> links = new List<ushort[]>( ); foreach ( var skillNode in Skillnodes ) { foreach ( ushort i in skillNode.Value.linkID ) { if ( links.Count( nd => ( nd[ 0 ] == i && nd[ 1 ] == skillNode.Key ) || nd[ 0 ] == skillNode.Key && nd[ 1 ] == i ) == 1 ) { continue; } links.Add( new ushort[] { skillNode.Key , i } ); } } foreach ( ushort[] ints in links ) { if ( !Skillnodes[ ints[ 0 ] ].Neighbor.Contains( Skillnodes[ ints[ 1 ] ] ) ) Skillnodes[ ints[ 0 ] ].Neighbor.Add( Skillnodes[ ints[ 1 ] ] ); if ( !Skillnodes[ ints[ 1 ] ].Neighbor.Contains( Skillnodes[ ints[ 0 ] ] ) ) Skillnodes[ ints[ 1 ] ].Neighbor.Add( Skillnodes[ ints[ 0 ] ] ); } foreach(var gp in inTree.groups ) { NodeGroup ng = new NodeGroup(); ng.OcpOrb = gp.Value.oo; ng.Position = new Vector2D(gp.Value.x, gp.Value.y); ng.Nodes = gp.Value.n; NodeGroups.Add(ng); } foreach ( SkillTree.NodeGroup group in NodeGroups ) { foreach ( ushort node in group.Nodes ) { Skillnodes[ node ].NodeGroup = group; } } TRect = new Rect2D( new Vector2D( inTree.min_x * 1.1 , inTree.min_y * 1.1 ) , new Vector2D(inTree.max_x * 1.1, inTree.max_y * 1.1)); InitNodeSurround( ); DrawNodeSurround( ); DrawNodeBaseSurround( ); DrawSkillIconLayer( ); DrawBackgroundLayer( ); InitFaceBrushesAndLayer( ); DrawLinkBackgroundLayer( links ); InitOtherDynamicLayers( ); CreateCombineVisual( ); Regex regexAttrib = new Regex( "[0-9]*\\.?[0-9]+" ); foreach ( var skillNode in Skillnodes ) { skillNode.Value.Attributes = new Dictionary<string , List<float>>( ); foreach ( string s in skillNode.Value.attributes ) { List<float> values = new List<float>( ); foreach ( Match m in regexAttrib.Matches( s ) ) { if ( !AttributeTypes.Contains( regexAttrib.Replace( s , "#" ) ) ) AttributeTypes.Add( regexAttrib.Replace( s , "#" ) ); if ( m.Value == "" ) values.Add( float.NaN ); else values.Add( float.Parse( m.Value , System.Globalization.CultureInfo.InvariantCulture ) ); } string cs = ( regexAttrib.Replace( s , "#" ) ); skillNode.Value.Attributes[ cs ] = values; } } }
public bool Contains(Rect2D v) { return(v.Min.X >= Min.X && v.Min.Y >= Min.Y && v.Max.Y <= Max.Y && v.Max.X <= Max.X); }
public bool IntersectsWith(Rect2D r) { return(!(r.Max.X <= Min.X || r.Max.Y <= Min.Y || Max.Y <= r.Min.Y || Max.X <= r.Min.X)); }
public bool IntersectsWith( Rect2D r ) { return !( r.Max.X <= Min.X || r.Max.Y <= Min.Y || Max.Y <= r.Min.Y || Max.X <= r.Min.X ); }
public bool Contains( Rect2D v ) { return v.Min.X >= Min.X && v.Min.Y >= Min.Y && v.Max.Y <= Max.Y && v.Max.X <= Max.X; }