Skip to content

Commit

Permalink
Simplify documentation
Browse files Browse the repository at this point in the history
Don't document obvious return types. Rely on YARD to  find how default values are defined.
  • Loading branch information
Eneroth3 committed Nov 17, 2017
1 parent 7e22d33 commit 4d97dff
Showing 1 changed file with 19 additions and 26 deletions.
45 changes: 19 additions & 26 deletions face_shader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,12 @@ module FaceShading
# Determine the (unshaded) color of the viewed side of a face.
# If face is textured the average color of the texture will be used.
# A custom plane can be supplied when previewing as if it has been moved.
#
# @param [Sketchup::Face]
# @param [Array(Geom::Point3d, Geom::vector3d), Array(Float, Float, Float, Float)] plane
# Defaults to the plane of the face.
# @param [Sketchup::Camera] camera
# Defaults to the camera of the same model as the face.
# @param [Array(Geom::Point3d, Geom::Vector3d), Array(Float, Float, Float, Float)]
# @param [Sketchup::Camera]
# @returns [Sketchup::Color]
def self.face_color(face, plane = nil, camera = nil)
plane ||= face.plane
camera ||= face.model.active_view.camera

def self.face_color(face, plane = face.plane, camera = face.model.active_view.camera)
if back_of_plane?(plane, camera.eye)
if face.back_material
face.back_material.color
Expand All @@ -34,8 +30,9 @@ def self.face_color(face, plane = nil, camera = nil)

# Shade a color as it would be shaded if drawn to a face at a certain plane
# and displayed in a certain view.
#
# @param [Sketchup::Color]
# @param [Array(Geom::Point3d, Geom::vector3d), Array(Float, Float, Float, Float)]
# @param [Array(Geom::Point3d, Geom::Vector3d), Array(Float, Float, Float, Float)]
# @param [Sketchup::view]
# @return [Sketchup::Color]
def self.shade_color(color, plane, view)
Expand All @@ -50,42 +47,37 @@ def self.shade_color(color, plane, view)

# Compute the shaded color for the viewed side of a face.
# A custom plane can be supplied when previewing as if it has been moved.
#
# @param [Sketchup::Face]
# @param [Array(Geom::Point3d, Geom::vector3d), Array(Float, Float, Float, Float)] plane
# Defaults to the plane of the face.
def self.shaded_face_color(face, plane = nil)
plane ||= face.plane

# @param [Array(Geom::Point3d, Geom::Vector3d), Array(Float, Float, Float, Float)]
def self.shaded_face_color(face, plane = face.plane)
shade_color(face_color(face, plane), plane, face.model.active_view)
end

# Check what side of a face is being viewed.
# Assume face is in the same coordinate system as camera.
#
# @param [Sketchup::Face]
# @param [Sketchup::Camera]
# @return [Boolean] status
# +true+ if the camera is on the back side of the face,
# +false+ if it's on the front side.
def self.view_back_face?(face, camera = nil)
camera ||= face.model.active_view.camera

# @return [Boolean]
def self.view_back_face?(face, camera = face.model.active_view.camera)
back_of_plane?(face.plane, camera.eye)
end

private

# Check what side of a plane a point is.
# @param [Array(Geom::Point3d, Geom::vector3d), Array(Float, Float, Float, Float)]
#
# @param [Array(Geom::Point3d, Geom::Vector3d), Array(Float, Float, Float, Float)]
# @param [Geom::Point3d]
# @return [Boolean] status
# +true+ if the point is behind the plane (or on plane),
# +false+ if in front of the plane.
# @return [Boolean]
def self.back_of_plane?(plane, point)
(point - point.project_to_plane(plane)) % plane_normal(plane) < 0
end

# Determine the normal vector for a plane.
# @param [Array(Geom::Point3d, Geom::vector3d), Array(Float, Float, Float, Float)]
#
# @param [Array(Geom::Point3d, Geom::Vector3d), Array(Float, Float, Float, Float)]
# @return [Vector3d]
def self.plane_normal(plane)
return plane[1].clone if plane.size == 2
Expand All @@ -95,11 +87,12 @@ def self.plane_normal(plane)
end

# Compute how much a face at a certain plane would be shaded for a certain view.
#
# @example
# # Select a face in the model.
# model = Sketchup.active_model
# shade_value(model.selection.first.normal, model.active_view)
# @param [Array(Geom::Point3d, Geom::vector3d), Array(Float, Float, Float, Float)]
# @param [Array(Geom::Point3d, Geom::Vector3d), Array(Float, Float, Float, Float)]
# @param [Sketchup::view]
# @return [Float] shading
# Shading value between 0.0 (darkest) to 1.0 (lightest).
Expand Down

0 comments on commit 4d97dff

Please sign in to comment.