首页 \ 问答 \ 如何确定适合固定尺寸2D空间的任意数量的等方的大小?(How do I determine the size of an arbitrary number of equal squares to be fit into an fixed size 2D space?)

如何确定适合固定尺寸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
更新时间:2023-09-05 21:09

最满意答案

啊,我发现了问题。

问题是当我需要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.

相关问答

更多
  • 啊,我发现了问题。 问题是当我需要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显示这个。 最初绑定了三个 ...
  • 您遇到的问题是您使用函数参数覆盖成员名称。 您可以使用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 ...
  • 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. ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)