如何确定适合固定尺寸2D空间的任意数量的等方的大小?(How do I determine the size of an arbitrary number of equal squares to be fit into an fixed size 2D space?)
我有一个固定大小的2D空间,我想用任意数量的相等大小的正方形填充。 我想要一个算法来确定这些方块的确切大小(一边的长度),以便完美地适应给定的空间。
I have a fixed size 2D space that I would like to fill with an arbitrary number of equal sized squares. I'd like an algorithm that determines the exact size (length of one side) that these squares should be in order to fit perfectly into the given space.
原文:https://stackoverflow.com/questions/6164214
最满意答案
啊,我发现了问题。
问题是当我需要
GebruikerIsIngelogd();
函数时,我创建了一个新的BLSecurity实例GebruikerIsIngelogd();
所以我在我的Load函数中设置了部分
protected void Page_Load(object sender, EventArgs e) { BLSecurity BLSecurity = new BLSecurity(); BLSecurity.Gebruiker = (wk_Gebruiker)Session["gebruiker"]; SomeFunction(); }
并在函数
SomeFunction();
我需要那些方法。SomeFunction();
private void SomeFunction(){ BLSecurity BLSecurity = new BLSecurity(); //here lies the problem if(BLSecurity.IsLoggedIn()){ ... } else { ... } }
所以问题是
DoSomething()
中BLSecurity的这个新实例解决方案是将实例移到Page_Load()之上
public partial class WineKeeper : System.Web.UI.MasterPage { private BLSecurity BLSecurity = new BLSecurity(); protected void Page_Load(object sender, EventArgs e) { BLSecurity.Gebruiker = (wk_Gebruiker)Session["gebruiker"]; SomeFunction(); } }
这样我就不会被覆盖,这会导致null。
Ah, I found the problem.
The problem was that I created a new instance of BLSecurity when I needed the function
GebruikerIsIngelogd();
So I had in my Load function the set part
protected void Page_Load(object sender, EventArgs e) { BLSecurity BLSecurity = new BLSecurity(); BLSecurity.Gebruiker = (wk_Gebruiker)Session["gebruiker"]; SomeFunction(); }
And in the function
SomeFunction();
I needed those methods.SomeFunction();
private void SomeFunction(){ BLSecurity BLSecurity = new BLSecurity(); //here lies the problem if(BLSecurity.IsLoggedIn()){ ... } else { ... } }
So the problem is this new instance of BLSecurity in
DoSomething()
The solution was to move the instance above the Page_Load()
public partial class WineKeeper : System.Web.UI.MasterPage { private BLSecurity BLSecurity = new BLSecurity(); protected void Page_Load(object sender, EventArgs e) { BLSecurity.Gebruiker = (wk_Gebruiker)Session["gebruiker"]; SomeFunction(); } }
This way I won't be overridden which would result in null.
相关问答
更多-
Getter和setter不工作,构造函数值保持空白 - ASP(Getter and setter not working, Constructor value stays empty - ASP)[2022-05-14]
啊,我发现了问题。 问题是当我需要GebruikerIsIngelogd();函数时,我创建了一个新的BLSecurity实例GebruikerIsIngelogd(); 所以我在我的Load函数中设置了部分 protected void Page_Load(object sender, EventArgs e) { BLSecurity BLSecurity = new BLSecurity(); BLSecurity.Gebruiker = (wk_Gebruiker)Session[ ... -
规则是:当你在.js文件中时,你应该总是使用.get()/.set() 。 当你在模板(.hbs或其他)中时,你不应该(你不能这样做)。 如果通过myObj.myProp访问属性,它将适用于常规属性,但计算属性不会。 如果通过myObj.myProp设置属性,您仍然可以返回值,但不会通知绑定和观察者它已更改并且无法正确更新。 这是Ember团队的一项设计决策,它允许有效的绑定/观察者,而不是对所有绑定/观察到的属性进行脏检查(这是Angular目前所做的)。 我做了一个小jsbin显示这个。 最初绑定了三个 ...
-
C ++:如何使getter和setter使用空构造函数(C++: how to make getters and setters work with an empty constructor)[2022-11-07]
您遇到的问题是您使用函数参数覆盖成员名称。 您可以使用this->使其明确或以不同方式命名成员。 例如: void Car::setBrand(string name) { this->name = name; } 要么: void Car::setBrand(string new_name) { name = new_name; } The problem you have is that you override the member names with function para ... -
这个问题通常是在创建项目时引起的,在你的情况下,你的members 。 如果您将这些项目创建为Http请求的一部分,如下所示: getMembers(): Observable
{ return this.http.get (this.Url); 然后你实际上并没有在你的数组中创建BasicSystemMember对象。 相反,Http请求创建的元素“看起来”像BasicSystemMember对象,但它们只具有Ht ... -
以下代码(您的子集)是编译错误: class HelloWorld { constructor(public name: string) { } set name(e: string) { this.name = e; } get name(): string { return this.name; } } 垃圾在=>垃圾出来 固定 不要使用具有相同名称的getter / setter和属性。 The following co ...
-
.NET中的大多数序列化方法(包括WCF)都需要可访问的getter和setter才能工作,因为它必须能够在将传入字段去离心化时将属性设置为值。 有一个解决方法,您可以将后备存储私有成员标记为序列化字段。 [DataContract] class Foo { [DataMember(Name="IsDeleted")] private bool _isDeleted; public bool IsDeleted { get { return _isDele ...
-
使用eclipse,将鼠标移动到1个参数变量名称,然后按ctrl + 1。 然后是一个小弹出窗口,您可以在其中选择“将所有参数分配给新字段”。 按下。 这解决了getter和setter的任务1和3.转向新生成的成员变量,然后再次将鼠标移动到变量名并再次按ctrl + 1并选择generate getter和setter。 getter和setter的另一种方式是alt + shift + s - > generate getter和setter并选择all with eclipse, move mouse ...
-
构造函数中的Object.defineProperty,getter和setter方法(Object.defineProperty in constructor, getter and setter method)[2022-07-09]
getter方法返回xname ,但xname后面的范围之外: var One = new Person("Mark"); 以后如何在代码对象的One getter中设法返回xname的值? 因为它仍然在使用它的范围内。 是的, Person函数已经返回,但是由于函数关闭了对Person调用的上下文,所以在这个上下文中定义的参数和变量仍然可以被这些函数访问。 当你调用一个函数时,以规范术语来说,一个对象被创建,它包含函数参数,调用中的局部变量等“绑定”(认为它们像属性)。在调用函数期间创建的任何函数保持对该 ... -
这三个问题的答案是相同的: Object.assign从源对象读取属性的值 ,它不复制getter / setter。 你可以看到,如果你看一下属性描述符: var source = { get prop() { }, set prop(v) { } }; console.log("descriptor on source", Object.getOwnPropertyDescriptor(source, "prop")); var target = Object.assign({}, s ...
-
KISS:定义一个defaults对象并迭代它的键以创建新属性: function myChart(){ // default properties var defaults = { svgWidth: 1000, svgHeight: 250 } function chart(selection){ // do something with the previous properties .... } Object. ...