Created with <3 with dartpad.dev.
Last active
September 5, 2023 01:30
-
-
Save mcavalcantib/0a594f0165d7dd155d9444412529a76e to your computer and use it in GitHub Desktop.
Spatial Hash Study
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'package:flutter/material.dart'; | |
| const Color darkBlue = Color.fromARGB(255, 18, 32, 47); | |
| void main() { | |
| runApp(MyApp()); | |
| } | |
| class Client { | |
| late List<int> position = List<int>.empty(), dimentions = List<int>.empty(); | |
| contructor(position, dementions) { | |
| position = List.from(position); | |
| dimentions = List.from(dimentions); | |
| } | |
| getPosition() { | |
| return position; | |
| } | |
| getDimentions() { | |
| return dimentions; | |
| } | |
| } | |
| class SpatialHash { | |
| var _bounds = (); | |
| var _dimentions = (); | |
| var _cells = Map(); | |
| constructor(bounds, dimentions) { | |
| _bounds = bounds; | |
| _dimentions = dimentions; | |
| } | |
| _getCellIndexes(position){ | |
| var xi = Math.floor(px / spacing); | |
| var yi = Math.floor(py / spacing); | |
| } | |
| // NewClient(var position, var dimentions) { | |
| // const client = Client(position, dimentions); | |
| // } | |
| } | |
| class MyApp extends StatelessWidget { | |
| @override | |
| Widget build(BuildContext context) { | |
| return MaterialApp( | |
| theme: ThemeData.dark().copyWith( | |
| scaffoldBackgroundColor: darkBlue, | |
| ), | |
| debugShowCheckedModeBanner: false, | |
| home: Scaffold( | |
| body: Center( | |
| child: MyWidget(), | |
| ), | |
| ), | |
| ); | |
| } | |
| } | |
| class MyWidget extends StatelessWidget { | |
| @override | |
| Widget build(BuildContext context) { | |
| return GridView.count( | |
| // Create a grid with 2 columns. If you change the scrollDirection to | |
| // horizontal, this produces 2 rows. | |
| crossAxisCount: 10, | |
| // Generate 100 widgets that display their index in the List. | |
| children: List.generate(100, (index) { | |
| return Center( | |
| child: Container( | |
| margin: const EdgeInsets.all(3.0), | |
| color: Colors.red[600], | |
| width: 48.0, | |
| height: 48.0, | |
| ), | |
| ); | |
| }), | |
| ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment