## ----include = FALSE----------------------------------------------------------
knitr::opts_chunk$set(collapse = TRUE, comment = "#>", fig.width = 7, fig.height = 5.5,
                      dpi = 96, out.width = "100%")
# on Linux the default X11 png device cannot draw semi-transparent fills; use cairo there
if (Sys.info()[["sysname"]] == "Linux" && isTRUE(capabilities("cairo"))) knitr::opts_chunk$set(dev.args = list(png = list(type = "cairo")))
set.seed(2026)

## ----setup--------------------------------------------------------------------
library(forensicR)

## ----room---------------------------------------------------------------------
walls <- rbind(
  room_rect(x0 = 0, y0 = 0, width = 6, depth = 5),
  opening(2.5, 0, 3.5, 0, type = "door"),      # door in the south wall
  opening(0, 2.0, 0, 3.2, type = "window")     # window in the west wall
)

## ----points-------------------------------------------------------------------
evidence <- coords_baseline(
  along  = c(1.5, 4.8),          # distance from corner A along the south wall
  offset = c(0.9, 0.4),          # distance into the room
  origin = c(0, 0), end = c(6, 0),
  id = c("1 Cartridge case", "2 Firearm")
)
evidence

## ----defect-------------------------------------------------------------------
defect <- coords_triangulation(
  d1 = 2.0, d2 = 4.0,                      # distances to the two reference points
  p1 = c(0, 5), p2 = c(6, 5),              # north-west and north-east corners
  side = "right",                          # inside the room when walking p1 -> p2
  id = "3 Bullet defect", z = 1.35, type = "defect"
)
defect
scene <- rbind(evidence, defect)

## ----furniture----------------------------------------------------------------
furn <- rbind(
  along_wall(walls, "north", from = 3.4, length = 2.1, depth = 0.9, id = "Sofa", type = "sofa"),
  furniture("Coffee table", "table", x = 3.9, y = 2.6, width = 1.0, depth = 0.5,
            measured = FALSE),                      # estimated size: drawn dashed
  furniture("Stool", "chair", x = 1.6, y = 3.6, diameter = 0.4, shape = "circle")
)
furniture_table(furn)

## ----sketch-------------------------------------------------------------------
plot_scene(scene, walls = walls, furniture = furn)

## ----elevation, fig.height=3.8------------------------------------------------
plot_wall_elevation(wall_from_room(walls, "north"), scene, walls = walls, furniture = furn)

## ----trajectory---------------------------------------------------------------
t1 <- trajectory_from_angles(
  anchor = c(defect$x, defect$y, defect$z),   # where the bullet struck
  azimuth_deg = 352, vertical_deg = -3,       # direction of flight
  se_azimuth = 5, se_vertical = 5,            # angular uncertainty
  id = "D1"
)
t1

## ----origin-------------------------------------------------------------------
origin_zone(t1, heights = c(standing = 1.5, kneeling = 1.0), max_distance = 6,
            furniture = furn)

## ----plan---------------------------------------------------------------------
plot_trajectories(t1, view = "plan", points = scene, walls = walls, furniture = furn,
                  back = 5)

## ----elev, fig.height=3.2-----------------------------------------------------
plot_trajectories(t1, view = "elevation", back = 5)

## ----log----------------------------------------------------------------------
log <- evidence_log("2026-000123", "Example County Sheriff's Office")
log <- log_item(log, "1", "Cartridge case, 9 mm Luger", location = "Point 1",
                collected_by = "Investigator A", packaging = "Paper envelope, sealed")
log <- log_item(log, "2", "Pistol, 9 mm", location = "Point 2",
                collected_by = "Investigator A", packaging = "Firearm box, zip-tied")
log <- log_custody(log, "2", "submitted to lab", from = "Investigator A", to = "State lab")
log

## ----report, eval = FALSE-----------------------------------------------------
# render_scene_report(
#   output_dir = "case-2026-000123",
#   formats = c("docx", "pdf", "html"),
#   params = list(
#     case_id = "2026-000123",
#     agency = "Example County Sheriff's Office",
#     investigator = "Investigator A",
#     narrative = "Single-family residence, living room. One bullet defect in the north wall.",
#     points = scene, walls = walls, furniture = furn,
#     shooting = list(trajectories = list(t1), heights = c(standing = 1.5, kneeling = 1.0),
#                     max_distance = 6),
#     evidence = log,
#     scene3d = TRUE          # adds the 3D view (see below)
#   )
# )

## ----render3d, eval = FALSE---------------------------------------------------
# render_scene_3d(walls, scene, t1, furniture = furn, file = "scene3d.png", view = "dollhouse")

## ----fig3d, echo = FALSE, out.width = "100%", fig.cap = "Dollhouse view: south wall removed, numbered floor grid, bullet defect at its measured height, trajectory rod with its uncertainty cone."----
knitr::include_graphics("figures/getting-started-dollhouse.png")

