Prefer bracket notation for vector

This commit is contained in:
Alex Clink 2022-01-25 00:14:53 -05:00
parent 15929e4bb1
commit 60a9254583
6 changed files with 14 additions and 14 deletions

View file

@ -31,10 +31,10 @@ module PF
end end
def add_ball def add_ball
position = Vector2(Float64).new(rand(0.0_f64..@width.to_f64), rand(0.0_f64..@height.to_f64)) position = Vector[rand(0.0_f64..@width.to_f64), rand(0.0_f64..@height.to_f64)]
ball = Ball.new(rand(10.0..30.0)) ball = Ball.new(rand(10.0..30.0))
ball.position = position ball.position = position
ball.velocity = Vector2(Float64).new(rand(-50.0..50.0), rand(-50.0..50.0)) ball.velocity = Vector[rand(-50.0..50.0), rand(-50.0..50.0)]
@balls << ball @balls << ball
end end

View file

@ -34,7 +34,7 @@ class Wind
while y < @height while y < @height
x = step / 2 x = step / 2
while x < @width while x < @width
@gusts << Gust.new(PF::Vector2(Float64).new(x, y), PF::Vector2(Float64).new(rand(-1.0..1.0), rand(-1.0..1.0))) @gusts << Gust.new(PF::Vector[x, y], PF::Vector[rand(-1.0..1.0), rand(-1.0..1.0)])
x += step x += step
end end
y += step y += step
@ -49,7 +49,7 @@ class Flake
property velocity : PF::Vector2(Float64) property velocity : PF::Vector2(Float64)
def initialize(@position, @shape = rand(0_u8..2_u8), @z_pos = rand(0.0..1.0), velocity : PF::Vector2(Float64)? = nil) def initialize(@position, @shape = rand(0_u8..2_u8), @z_pos = rand(0.0..1.0), velocity : PF::Vector2(Float64)? = nil)
@velocity = velocity || PF::Vector2(Float64).new(rand(-2.0..2.0), rand(0.0..20.0)) @velocity = velocity || PF::Vector[rand(-2.0..2.0), rand(0.0..20.0)]
end end
def update(dt) def update(dt)

View file

@ -8,7 +8,7 @@ describe Vector do
it "multiplies 2 vectors" do it "multiplies 2 vectors" do
v1 = Vector[1, 2] v1 = Vector[1, 2]
v2 = Vector[2, 2] v2 = Vector[2, 2]
(v1 * v2).should eq(Vector2(Int32).new(2, 4)) (v1 * v2).should eq(Vector[2, 4])
end end
end end

View file

@ -1,9 +1,9 @@
module PF module PF
class Mesh class Mesh
setter tris = [] of Tri setter tris = [] of Tri
property origin = Vector3(Float64).new(0.0, 0.0, 0.0) property origin : Vector3(Float64) = Vector[0.0, 0.0, 0.0]
property rotation = Vector3(Float64).new(0.0, 0.0, 0.0) property rotation : Vector3(Float64) = Vector[0.0, 0.0, 0.0]
property position = Vector3(Float64).new(0.0, 0.0, 0.0) property position : Vector3(Float64) = Vector[0.0, 0.0, 0.0]
# Load an obj file # Load an obj file
def self.load_obj(path, use_normals : Bool = false) def self.load_obj(path, use_normals : Bool = false)

View file

@ -15,9 +15,9 @@ module PF
end end
def initialize(p1x : Float64, p1y : Float64, p1z : Float64, p2x : Float64, p2y : Float64, p2z : Float64, p3x : Float64, p3y : Float64, p3z : Float64, @color = PF::Pixel.white) def initialize(p1x : Float64, p1y : Float64, p1z : Float64, p2x : Float64, p2y : Float64, p2z : Float64, p3x : Float64, p3y : Float64, p3z : Float64, @color = PF::Pixel.white)
@p1 = Vector3(Float64).new(p1x, p1y, p1z) @p1 = Vector[p1x, p1y, p1z]
@p2 = Vector3(Float64).new(p2x, p2y, p2z) @p2 = Vector[p2x, p2y, p2z]
@p3 = Vector3(Float64).new(p3x, p3y, p3z) @p3 = Vector[p3x, p3y, p3z]
end end
# Return the normal assuming clockwise pointing winding # Return the normal assuming clockwise pointing winding
@ -61,9 +61,9 @@ module PF
plane_normal = plane_normal.normalized plane_normal = plane_normal.normalized
# Create two temporary storage arrays to classify points either side of plane # Create two temporary storage arrays to classify points either side of plane
inside_points = StaticArray(Vector3(Float64), 3).new(Vector3(Float64).new(0.0, 0.0, 0.0)) inside_points = StaticArray(Vector3(Float64), 3).new(Vector[0.0, 0.0, 0.0])
inside_count = 0 inside_count = 0
outside_points = StaticArray(Vector3(Float64), 3).new(Vector3(Float64).new(0.0, 0.0, 0.0)) outside_points = StaticArray(Vector3(Float64), 3).new(Vector[0.0, 0.0, 0.0])
outside_count = 0 outside_count = 0
# Classify each point as inside or outside of the plane # Classify each point as inside or outside of the plane

View file

@ -28,7 +28,7 @@ module PF
# Calculate the new velocities # Calculate the new velocities
normal_vec = (position - other.position) / d normal_vec = (position - other.position) / d
tangental_vec = Vector2(Float64).new(-normal_vec.y, normal_vec.x) tangental_vec = Vector[-normal_vec.y, normal_vec.x]
# Dot product of velocity with the tangent # Dot product of velocity with the tangent
# (the direction in which to bounce towards) # (the direction in which to bounce towards)