Any good data structure to perform efficient lookup and modification operations about what are the shapes containing the current cursor position

I think I’m facing a pretty common issue but cannot remember which solution is the most suitable one.

Let’s put it that way: I can, in a, certain, given, language get some events anytime the user is moving the mouse. I therefore get the position the current cursor position in let’s say in absolute coordinates based system.

Now considering that this system is also capable of containing up to thousands of thousands of shape objects (with a certain location point and size).
In a first rough approximation, we can think about them as their related bounding boxes in order to make the lookup operation and classification a bit more simpler, let’s also add another simplification by omitting the fact that shapes can overlap each other.

What can be the best data structures to retrieve the shape(s) under the cursor position and allow relative fast insertion / deletion / modification operations?

Thanks,

ps: I was thinking about some sort of sorted trees but I think they are pretty demanding when it comes about maintaining their internal sort.

Additional curiosity: how it works in Winforms? I mean the Control class in the .NET Framework is related to the underlying HWANDLE in windows and capable of firing events when cursor is entering or leaving a Control. I do not really think that there is a thread allocated to perform some dummy hit tests… and trigger the related events.

if space is not of concern and your application can afford to use as many space as you want, I’m thinking of 3-dimensional array (or to be more precise, 2-dimensional array of list) structure
2-dimensional array will represent the screen. Each pixel is an element in the array. Each location in array contains a pointer to a list of shape identifier

e.g. there are 2 shapes with id 4, 5 at location {10, 12}, so the element {10, 12} of the 2-dimensional array contains a list of 2 elements (4 and 5). Please note that shape id is a number that uniquely identify that shape instance. Even if 2 shapes are both square, they will have different shape id

  • To find at a specific mouse location, what shapes are present, just need 1 array lookup + list travel to get all shapes at that location
  • To insert: it will depend on how big is the shape, will need to go through all the pixels in the shape, add that shape id into the structure
  • To delete: for faster delete, I think can keep a lookup that has key is shape id, value is location of one pixel within that shape. when you want to delete the shape, look up the location of the pixel based on shape id, then use flood fill algorithm to remove the shape id from the structure

I hope I describe it well, here’s an example of the 3×3 array. There are 2 squares of size 2×2 in the array with id 1, 2. THese 2 squares overlapping in the middle of the array

[1] – [ 1 ] – []

[1] – [1,2] – [2]

[] – [ 2 ] – [2]

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa

Any good data structure to perform efficient lookup and modification operations about what are the shapes containing the current cursor position

I think I’m facing a pretty common issue but cannot remember which solution is the most suitable one.

Let’s put it that way: I can, in a, certain, given, language get some events anytime the user is moving the mouse. I therefore get the position the current cursor position in let’s say in absolute coordinates based system.

Now considering that this system is also capable of containing up to thousands of thousands of shape objects (with a certain location point and size).
In a first rough approximation, we can think about them as their related bounding boxes in order to make the lookup operation and classification a bit more simpler, let’s also add another simplification by omitting the fact that shapes can overlap each other.

What can be the best data structures to retrieve the shape(s) under the cursor position and allow relative fast insertion / deletion / modification operations?

Thanks,

ps: I was thinking about some sort of sorted trees but I think they are pretty demanding when it comes about maintaining their internal sort.

Additional curiosity: how it works in Winforms? I mean the Control class in the .NET Framework is related to the underlying HWANDLE in windows and capable of firing events when cursor is entering or leaving a Control. I do not really think that there is a thread allocated to perform some dummy hit tests… and trigger the related events.

if space is not of concern and your application can afford to use as many space as you want, I’m thinking of 3-dimensional array (or to be more precise, 2-dimensional array of list) structure
2-dimensional array will represent the screen. Each pixel is an element in the array. Each location in array contains a pointer to a list of shape identifier

e.g. there are 2 shapes with id 4, 5 at location {10, 12}, so the element {10, 12} of the 2-dimensional array contains a list of 2 elements (4 and 5). Please note that shape id is a number that uniquely identify that shape instance. Even if 2 shapes are both square, they will have different shape id

  • To find at a specific mouse location, what shapes are present, just need 1 array lookup + list travel to get all shapes at that location
  • To insert: it will depend on how big is the shape, will need to go through all the pixels in the shape, add that shape id into the structure
  • To delete: for faster delete, I think can keep a lookup that has key is shape id, value is location of one pixel within that shape. when you want to delete the shape, look up the location of the pixel based on shape id, then use flood fill algorithm to remove the shape id from the structure

I hope I describe it well, here’s an example of the 3×3 array. There are 2 squares of size 2×2 in the array with id 1, 2. THese 2 squares overlapping in the middle of the array

[1] – [ 1 ] – []

[1] – [1,2] – [2]

[] – [ 2 ] – [2]

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật