# Tag Info

3

Considering the usual 2D represention (example with zyx): 000 001 002 003 004 010 011 012 013 014 020 021 022 023 024 you could consider extending the scheme to 3D, if the 3rd dimension is not too deep (e.g. 2 or 3): 000 001 002 003 004 100 101 102 103 104 200 201 202 203 204 010 011 012 013 014 110 111 112 113 114 210 211 212 213 214 020 ...

2

I had faced this same situation many many years back while learning graphics programming using Borland C++ on Windows95. I had to know the co ordinates of the cube points. This is something like what I did and it worked. Assuming the Z axis stretches in front of you and the XY plane faces you, Y being vertical, I split the cube into a series XZ 'L' shapes. ...

0

This will be from a kind of OOP and/or enterprisey/application point of view and might not be applicable in certain fields/domains, but I kind of wanna bring up the concept of primitive obsession. It IS a good idea to use different data types for different kinds of information in your application. However, it's probably NOT good idea to use the built-in ...

3

You could declare a typeclass for objects that know their location and shape, and create an instance for Object. Then your draw would accept any instance of that typeclass, but wouldn't be able to find out about any other fields in Object.

4

Besides using tuples or wrapping Object in a new datatype, another option is to parameterize Object with a type variable: data Object v = Object { location :: (Double, Double) , shape :: Shape , velocity :: v } deriving (Functor) When passing an object to the renderer, you could "mute" the velocity by storing a (), using void ...

1

A couple of possibilities: The vector form of the equation for a straight line in 2 dimensions is n.x + s = 0, where 'n' is a vector normal (or perpendicular) to the line "." is the vector dot product operation, and s is a scalar constant. This allows you to represent arbitrary lines with two integers and a double. (note that the same representation in 3 ...

2

For three dimensions, I'd show two dimensions and a depth. Consider this 5 deep tensor 5 (top) [1, 2, 3 5, 6, 7] Hit + zooms in 1 4 [10, 11, 12 13, 14, 15] Hitting - brings you back to the top, etc. I think you could possibly handle 4 dimensions by adding color. But beyond 4 is difficult enough in a graphics library! But one could show multiple ...

0

A single bit saying if the line is closer to horizontal or vertical. If closer to horizontal, slope + Y-intercept. If closer to vertical, inverse slope + X-intercept. That's two doubles, plus a bit. Equality testing is trivial.

9

The equations can be all rewritten into form : a*X + b*Y + c = 0 That means you can store three doubles a, b and c. This doesn't have a problem in representing an arbitrary slope. You can also calculate slope as a/b (or b/a). Two lines are equal if there exists k where a1*k = a2, b1*k=b2, c1*k = c2.

2

Possible methods For convenience of expression, this class will be used to represent any real points in a coordinate system in code snippets below: public class Point{ public double x, y; @Override public boolean equals(Object other){ if(!(other instanceof Point)) return false; Point point = (Point) other; return point.x == ...

0

We use the first method because it produces the correct list. The second produces a reversed list. The nil very clearly shows which element must be the last. The order matters! See this trivial example in Common Lisp: (reduce #'expt (cons 1 (cons 2 (cons 3 nil)))) 1 (reduce #'expt (cons 3 (cons 2 (cons 1 nil)))) 9 You could use the second method if you ...

0

This website provides a really clear explanation. http://pages.cs.wisc.edu/~vernon/cs367/notes/11.PRIORITY-Q.html In short, a priority queue can be implemented using many of the data structures that we've already studied (an array, a linked list, or a binary search tree). However, those data structures do not provide the most efficient operations. To make ...

7

according to Clean Code, is it okay to add a single constructor to a plain data structure? Yes. Constructors are not functions in this context since they're not something that operates on data. They don't hide the data. And if the data changes, they'll need to change, but that's no different from any other initialization strategy.

0

wigy posted a link to some stuff that is highly relevant but I think there are a few simple things that can help here. I'll offer some suggestions that are probably not optimal but might help you move forward. The first thing I would suggest is to avoid iterating over every other user for one user. I would instead iterate through the songs that user has ...

Top 50 recent answers are included